Home > Article > Web Front-end > How to Achieve a 100% Minimum Height for CSS Layouts with Fixed Header and Footer?
Achieving 100% Minimum Height in CSS Layouts
When designing a website layout with a fixed-height header and footer, it becomes essential to ensure that the middle content section fills the remaining space while adhering to the desired minimum height requirement. This presents a challenge in achieving cross-browser compatibility.
Min-Height Attribute
One effective solution involves utilizing the min-height attribute. By assigning a min-height of 100% to the container element, you force it to expand vertically to accommodate the necessary content.
Relative Positioning
To ensure the footer remains fixed at the bottom of the page, the container element should be set to relative positioning. This allows the footer, which is absolutely positioned, to maintain its location even when the container's height increases.
Padding on Content Element
To provide space for the footer while preventing it from overlapping the content, add a padding-bottom to the content element. This padding remains within the scrolled height, preventing the footer from obscuring the content.
Combining Elements
<br>html,body {</p> <pre class="brush:php;toolbar:false">height:100%;
}
div#container {
position:relative; min-height:100%;
}
div#header {
...
}
div#content {
padding-bottom: ...;
}
div#footer {
... bottom:0;
}
This comprehensive approach allows you to create a layout where the header and footer have fixed heights, while the middle content section dynamically fills the remaining space. It provides flexibility in both browser support and responsive design.
The above is the detailed content of How to Achieve a 100% Minimum Height for CSS Layouts with Fixed Header and Footer?. For more information, please follow other related articles on the PHP Chinese website!