Layaout grid area resolution
by Alejandro M
HTML
<header>Header</header>
<aside>Sidebar</aside>
<main>Main Content</main>
<footer>Footer</footer>
CSS
body {
margin: 0;
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";
grid-template-columns: 20% 1fr;
grid-template-rows: auto 1fr auto;
height: 100vh;
gap: 10px;
}
header {
grid-area: header;
background: #3498db;
color: white;
padding: 20px;
text-align: center;
}
aside {
grid-area: sidebar;
background: #2ecc71;
color: white;
padding: 20px;
}
main {
grid-area: main;
background: #f1c40f;
padding: 20px;
}
footer {
grid-area: footer;
background: #e74c3c;
color: white;
text-align: center;
padding: 20px;
}
/* 📱 Mobile */
@media (max-width: 767px) {
body {
grid-template-areas:
"header"
"main"
"sidebar"
"footer";
grid-template-columns: 1fr;
grid-template-rows: auto 1fr auto auto;
}
}