CSS Grid Templates - Free Printable
Educational worksheet: CSS Grid Templates. Download and print for classroom or home learning activities.
GIF
600×414
4.8 KB
Free · Personal Use
Quality Assured by Worksheets Library Team
Reviewed for educational accuracy and age-appropriateness
ID: #1788977
⭐
Show Answer Key & Explanations
Step-by-step solution for: CSS Grid Templates
▼
Show Answer Key & Explanations
Step-by-step solution for: CSS Grid Templates
It looks like you've uploaded a layout diagram of a web page structure, but there's no specific problem or question stated. Based on the image, I can infer that this is a visual representation of a typical webpage layout with the following sections:
- Header: At the top, spanning the full width.
- Nav: A vertical navigation bar on the left side.
- Ads: Below the Nav, also on the left side (likely for advertisements).
- Article: The main content area, occupying most of the right side.
- Footer: At the bottom, spanning the full width.
Since no explicit task was provided, here are a few common problems this layout might be used to solve, along with explanations:
---
#### 1. CSS Layout Using Flexbox or Grid
Problem: How to create this layout using CSS?
Solution:
You can use CSS Grid to achieve this layout efficiently.
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Layout Example</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: grid;
grid-template-rows: auto 1fr auto;
grid-template-columns: 200px 1fr;
height: 100vh;
}
header {
grid-column: 1 / -1;
background-color: #90ee00;
padding: 20px;
border-bottom: 2px solid white;
}
nav {
background-color: #90ee00;
padding: 20px;
border-right: 2px solid white;
}
.ads {
background-color: #90ee00;
padding: 20px;
border-right: 2px solid white;
}
article {
background-color: #90ee00;
padding: 20px;
}
footer {
grid-column: 1 / -1;
background-color: #90ee00;
padding: 20px;
border-top: 2px solid white;
}
</style>
</head>
<body>
<header>Header</header>
<nav>Nav</nav>
<div class="ads">Ads</div>
<article>Article</article>
<footer>Footer</footer>
</body>
</html>
```
Explanation:
- `grid-template-rows: auto 1fr auto` divides the page into three horizontal sections: header, main content, and footer.
- `grid-template-columns: 200px 1fr` creates two columns: a fixed 200px sidebar and a flexible main area.
- The `nav` and `ads` go in the first column.
- The `article` spans the second column.
- The `header` and `footer` span both columns (`1 / -1` means from first to last column).
---
#### 2. Responsive Design Challenge
Problem: Make this layout responsive on mobile devices.
Solution:
Use media queries to stack elements vertically on smaller screens.
```css
@media (max-width: 768px) {
body {
grid-template-columns: 1fr;
grid-template-rows: auto 1fr auto;
}
nav, .ads {
border-right: none;
}
article {
grid-column: 1;
}
}
```
This stacks all elements vertically when the screen is narrow.
---
#### 3. Semantic HTML Structure
Problem: Use proper semantic HTML5 elements.
Solution:
Use `<header>`, `<nav>`, `<aside>`, `<main>`, `<footer>` for better accessibility and SEO.
```html
<header>Header</header>
<nav>Nav</nav>
<aside>Ads</aside>
<main>Article</main>
<footer>Footer</footer>
```
---
If you have a specific problem or question about this layout (e.g., "How to make it responsive?", "How to style it?", "What’s wrong with this design?"), please clarify, and I’ll provide a targeted solution!
- Header: At the top, spanning the full width.
- Nav: A vertical navigation bar on the left side.
- Ads: Below the Nav, also on the left side (likely for advertisements).
- Article: The main content area, occupying most of the right side.
- Footer: At the bottom, spanning the full width.
Possible Interpretations and Solutions
Since no explicit task was provided, here are a few common problems this layout might be used to solve, along with explanations:
---
#### 1. CSS Layout Using Flexbox or Grid
Problem: How to create this layout using CSS?
Solution:
You can use CSS Grid to achieve this layout efficiently.
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Layout Example</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: grid;
grid-template-rows: auto 1fr auto;
grid-template-columns: 200px 1fr;
height: 100vh;
}
header {
grid-column: 1 / -1;
background-color: #90ee00;
padding: 20px;
border-bottom: 2px solid white;
}
nav {
background-color: #90ee00;
padding: 20px;
border-right: 2px solid white;
}
.ads {
background-color: #90ee00;
padding: 20px;
border-right: 2px solid white;
}
article {
background-color: #90ee00;
padding: 20px;
}
footer {
grid-column: 1 / -1;
background-color: #90ee00;
padding: 20px;
border-top: 2px solid white;
}
</style>
</head>
<body>
<header>Header</header>
<nav>Nav</nav>
<div class="ads">Ads</div>
<article>Article</article>
<footer>Footer</footer>
</body>
</html>
```
Explanation:
- `grid-template-rows: auto 1fr auto` divides the page into three horizontal sections: header, main content, and footer.
- `grid-template-columns: 200px 1fr` creates two columns: a fixed 200px sidebar and a flexible main area.
- The `nav` and `ads` go in the first column.
- The `article` spans the second column.
- The `header` and `footer` span both columns (`1 / -1` means from first to last column).
---
#### 2. Responsive Design Challenge
Problem: Make this layout responsive on mobile devices.
Solution:
Use media queries to stack elements vertically on smaller screens.
```css
@media (max-width: 768px) {
body {
grid-template-columns: 1fr;
grid-template-rows: auto 1fr auto;
}
nav, .ads {
border-right: none;
}
article {
grid-column: 1;
}
}
```
This stacks all elements vertically when the screen is narrow.
---
#### 3. Semantic HTML Structure
Problem: Use proper semantic HTML5 elements.
Solution:
Use `<header>`, `<nav>`, `<aside>`, `<main>`, `<footer>` for better accessibility and SEO.
```html
<header>Header</header>
<nav>Nav</nav>
<aside>Ads</aside>
<main>Article</main>
<footer>Footer</footer>
```
---
If you have a specific problem or question about this layout (e.g., "How to make it responsive?", "How to style it?", "What’s wrong with this design?"), please clarify, and I’ll provide a targeted solution!
Parent Tip: Review the logic above to help your child master the concept of template of grid.