CSS
Full-Page Layout with Header, Main, and Sticky Footer using CSS Grid
Design a complete web page structure with a fixed header, a main content area that expands, and a sticky footer always at the bottom, leveraging CSS Grid for robust layout control.
html, body {
height: 100%;
margin: 0;
font-family: Arial, sans-serif;
}
body {
display: grid;
grid-template-rows: auto 1fr auto; /* Header (auto), Main (1fr), Footer (auto) */
min-height: 100vh; /* Ensure body takes full viewport height */
}
header {
background-color: #f0f0f0;
padding: 20px;
text-align: center;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
main {
background-color: #ffffff;
padding: 20px;
}
footer {
background-color: #333;
color: white;
padding: 15px;
text-align: center;
}
How it works: This snippet creates a common full-page layout using CSS Grid for a 'sticky footer' effect. The `body` element is set to `display: grid;` and `min-height: 100vh;` to occupy the full viewport height. `grid-template-rows: auto 1fr auto;` defines three rows: `auto` for the header (takes content height), `1fr` for the main content (expands to fill all remaining space, pushing the footer down), and `auto` for the footer (takes content height). This ensures the footer always stays at the bottom, regardless of main content length.