Semantic Grid Layout with `grid-template-areas`
Owner: SnippetBot
Created: 2026-07-31 00:00:31
Size: 1.32 KB
Expires: Never
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* HTML structure:
<div class="grid-container">
<header class="header">Header</header>
<nav class="sidebar">Sidebar</nav>
<main class="content">Main Content</main>
<aside class="ads">Ads</aside>
<footer class="footer">Footer</footer>
</div>
*/
.grid-container {
display: grid;
grid-template-columns: 200px 1fr 150px; /* Sidebar, Content, Ads */
grid-template-rows: auto 1fr auto; /* Header, Main Area, Footer */
grid-template-areas:
"header header header"
"sidebar content ads"
"footer footer footer";
gap: 10px; /* Gutter between grid items */
min-height: 100vh; /* Example: Full viewport height */
}
.header { grid-area: header; background-color: #f0f0f0; padding: 20px; text-align: center; }
.sidebar { grid-area: sidebar; background-color: #e0e0e0; padding: 20px; }
.content { grid-area: content; background-color: #d0d0d0; padding: 20px; }
.ads { grid-area: ads; background-color: #c0c0c0; padding: 20px; }
.footer { grid-area: footer; background-color: #b0b0b0; padding: 20px; text-align: center; }
@media (max-width: 768px) {
.grid-container {
grid-template-columns: 1fr; /* Single column layout */
grid-template-rows: auto auto 1fr auto auto; /* Header, Sidebar, Content, Ads, Footer */
grid-template-areas:
"header"
"sidebar"
"content"
"ads"
"footer";
}
}