How to group footer content in form of table using HTML?


If you have a lot of footer content on your website, it can be helpful to group it together in the form of a table. This can make the content easier to read and navigate, and can also provide a more structured and organized look to your website. In this article, we'll look at how to group footer content in the form of a table using HTML, CSS, and JavaScript.

Grouping Footer Content Using HTML

To group footer content in the form of a table using HTML, you can use the <table> element along with the appropriate table-related elements such as <thead>, <body>, and <tfoot>. Here's an example −

<footer>
   <table>
      <thead>
         <tr>
            <th>Column 1</th>
            <th>Column 2</th>
            <th>Column 3</th>
         </tr>
      </thead>
      <tbody>
         <tr>
            <td>Row 1, Column 1</td>
            <td>Row 1, Column 2</td>
            <td>Row 1, Column 3</td>
         </tr>
         <tr>
            <td>Row 2, Column 1</td>
            <td>Row 2, Column 2</td>
            <td>Row 2, Column 3</td>
         </tr>
         <!-- more rows here -->
      </tbody>
      <tfoot>
         <tr>
            <td>Footer 1</td>
            <td>Footer 2</td>
            <td>Footer 3</td>
         </tr>
      </tfoot>
   </table>
</footer>

In this example, we use the <table> element to create a table. The <thead> element is used to define the table header, and contains a single row with three table headers (<th>). The <tbody> element is used to define the table body, and contains several rows with three table data elements (<td>) in each row. Finally, the <tfoot> element is used to define the table footer, and contains a single row with three table data elements.

You can customize the appearance of the table using CSS. For example, you can apply borders, background colors, and font styles to different parts of the table using CSS.

Grouping Footer Content Using CSS

Another way to group footer content is to use CSS to apply styling that visually groups the content together. Here's an example −

<footer>
   <div class="footer-section">
      <h3>Section 1</h3>
      <p>Content for section 1 goes here.</p>
   </div>
   <div class="footer-section">
      <h3>Section 2</h3>
      <p>Content for section 2 goes here.</p>
   </div>
   <div class="footer-section">
      <h3>Section 3</h3>
      <p>Content for section 3 goes here.</p>
   </div>
</footer>

<style>
   .footer-section {
      display: inline-block;
      vertical-align: top;
      margin-right: 20px;
      width: calc((100% / 3) - 20px);
   }
   .footer-section:last-child {
      margin-right: 0;
   }
   .footer-section h3 {
      font-size: 1.2em;
      margin-bottom: 10px;
   }
</style>

In this example, we have a footer element containing three div elements with the class footer-section. Each div represents a section of footer content with a heading and some text.

To group these sections together visually, we use CSS to apply some styling to the footer-section class. We set the display property to inline-block so that each section appears next to each other. We use vertical-align: top to align them at the top. We also set the margin-right property to create some space between each section.

To ensure that each section takes up an equal amount of space, we use the width property with a value of calc((100% / 3) - 20px). This calculates the width of each section as one-third of the available space, minus the 20px margin on the right side of each section.

Finally, we use the :last-child pseudo-class to remove the margin-right from the last div element, so that it aligns with the edge of the footer element.

We also apply some basic styling to the h3 element within each section, using the font-size property to increase the size of the heading, and the margin-bottom property to create some space between the heading and the text.

Overall, this approach allows us to group footer content visually, while maintaining a flexible layout that adjusts to the available screen space.

Styling the Grouped Footer Content Using CSS

Once you have grouped your footer content, you can use CSS to style it in a way that makes it visually appealing and easy to read. Here are some tips for styling your grouped footer content −

  • Use a consistent font size and style for the section headings and content text. This makes it easy for users to quickly scan and find the information they need.

  • Use spacing and padding to create a clear visual separation between each section. This makes it clear where one section ends and the next one begins.

  • Use a color scheme that complements your website's overall design. This helps to create a cohesive look and feel across your entire site.

  • Use hover effects and other interactive elements to make the footer more engaging for users. For example, you could add a hover effect to the section headings to highlight them when the user hovers over them.

Here's an example of how you might style the footer content using CSS −

.footer-section {
   display: inline-block;
   vertical-align: top;
   margin-right: 20px;
   width: calc((100% / 3) - 20px);
   padding: 20px;
   background-color: #f2f2f2;
   border-radius: 5px;
}
.footer-section:last-child {
   margin-right: 0;
}
.footer-section h3 {
   font-size: 1.2em;
   margin-bottom: 10px;
   color: #333;
}
.footer-section p {
   font-size: 1em;
   line-height: 1.4;
   color: #666;
}
.footer-section:hover {
   background-color: #e6e6e6;
}

In this example, we use the .footer-section class to style each section of the footer. We use display: inline-block and vertical-align: top to align the sections horizontally, and we use margin-right and width to create equal spacing between the sections. We also use padding, background-color, and border-radius to create a visual separation between the sections.

We use the :last-child pseudo-class to remove the right margin from the last section, ensuring that it aligns correctly with the edge of the footer container.

We use the h3 and p selectors to style the section headings and content text, respectively. We set the font size and color to create a consistent look and feel across all sections.

Finally, we use the :hover pseudo-class to add a hover effect to each section, changing the background color to a lighter shade of gray.

Adding Pagination to Grouped Footer Content

If you have a large amount of grouped footer content, it may be helpful to add pagination so that users can easily navigate through the content. You can use a variety of libraries and plugins, such as Bootstrap, to implement pagination. Here's an example of how to add pagination to grouped footer content using Bootstrap:

<footer>
   <div class="container">
      <div class="row">
         <div class="col-sm-4">
            <h3>Section 1</h3>
            <p>Content for section 1 goes here.</p>
         </div>
         <div class="col-sm-4">
            <h3>Section 2</h3>
            <p>Content for section 2 goes here.</p>
         </div>
         <div class="col-sm-4">
            <h3>Section 3</h3>
            <p>Content for section 3 goes here.</p>
         </div>
      </div>
      <nav aria-label="Page navigation">
         <ul class="pagination">
            <li>
            <a href="#" aria-label="Previous">
               <span aria-hidden="true">«</span>
            </a>
            </li>
            <li><a href="#">1</a></li>
            <li><a href="#">2</a></li>
            <li><a href="#">3</a></li>
            <li>
            <a href="#" aria-label="Next">
               <span aria-hidden="true">»</span>
            </a>
            </li>
         </ul>
      </nav>
   </div>
</footer>

In this example, we use the grid system provided by Bootstrap to layout the footer content in three columns. We then add a pagination component at the bottom of the footer using the pagination class provided by Bootstrap. Users can now easily navigate through the footer content using the pagination buttons.

Creating Dynamic Grouped Footer Content

Instead of manually creating and updating grouped footer content, you can use JavaScript and jQuery to create dynamic content based on user input or data from an external source. This can make your footer content more engaging and interactive for users. Here's an example of how to create dynamic grouped footer content using jQuery:

<footer>
   <div id="footer-sections"></div>
</footer>
<script>
   var sections = [
      {
         title: 'Section 1',
         content: 'Content for section 1 goes here.'
      },
      {
         title: 'Section 2',
         content: 'Content for section 2 goes here.'
      },
      {
         title: 'Section 3',
         content: 'Content for section 3 goes here.'
      }
   ];
   
   var $footerSections = $('#footer-sections');
   
   for (var i = 0; i < sections.length; i++) {
      var $section = $('<div>').addClass('footer-section');
      var $title = $('<h3>').text(sections[i].title);
      var $content = $('<p>').text(sections[i].content);
      
      $section.append($title);
      $section.append($content);
      $footerSections.append($section);
   }
</script>

In this example, we define an array of objects that contain the title and content for each section. We then use jQuery to dynamically create the footer sections by iterating over the array and appending new elements to the DOM. This approach allows you to easily update the footer content by modifying the source data, rather than having to manually update the HTML.

Conclusion

Grouping footer content can make it more organized, easier to navigate, and visually appealing for users. There are several ways to achieve this, including using HTML, CSS, and JavaScript/jQuery. The appropriate method depends on the specific needs and goals of the website or application.

With the techniques covered in this blog post, you can effectively group and display footer content to provide a better user experience.

Updated on: 07-Aug-2023

85 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements