A website is typically divided into sections such as headers, menus, content, and a footer.
Numerous layout designs are available to select from. Nonetheless, the structure outlined above is among the most prevalent, and we will delve deeper into it in this tutorial.
.header { background-color: #F1F1F1; text-align: center; padding: 20px; } |
Result:
A navigation bar comprises a list of links intended to assist visitors in navigating through your website.
Example
/* The navbar container */ .topnav { overflow: hidden; background-color: #333; } /* Navbar links */ .topnav a { float: left; display: block; color: #f2f2f2; text-align: center; padding: 14px 16px; text-decoration: none; } /* Links – change color on hover */ .topnav a:hover { background-color: #ddd; color: black; } |
Result
The layout in this section typically varies based on the target audience. Among the most common layouts are:
We’ll develop a 3-column layout and adapt it to a single-column layout on smaller screens.
Example
/* Create three equal columns that float next to each other */ |
Tip: To create a 2-column layout, set the width to 50%. For a 4-column layout, use 25%, and so on. Tip: Curious about how the Tip: A more modern approach to creating column layouts is to use CSS Flexbox. However, Flexbox is not supported in Internet Explorer 10 and earlier versions. If you need to support IE6-10, use floats as demonstrated above. To learn more about the Flexible Box Layout Module, check out our CSS Flexbox chapter. |
The main content constitutes the largest and most significant section of your website.
Unequal column widths are frequently employed, prioritizing the main content with a larger portion of space. Side content, if present, is typically utilized for alternative navigation or to provide supplementary information related to the main content. Adjust the widths as desired, ensuring they collectively sum up to 100%.
Example
.column { |
Result
Positioned at the bottom of your webpage, the footer typically includes details such as copyright information and contact details.
Example
.footer { background-color: #F1F1F1; text-align: center; padding: 10px; } |
Result
By implementing portions of the CSS code provided earlier, we’ve developed a responsive website layout that dynamically adjusts between two-column and full-width column configurations based on screen width.