2018-09-30 23:01:58 +01:00
---
id: 5a94fe7769fb03452672e463
title: Use Media Queries to Create Responsive Layouts
challengeType: 0
videoUrl: 'https://scrimba.com/p/pByETK/cMbqeHk'
---
## Description
< section id = 'description' >
CSS Grid can be an easy way to make your site more responsive by using media queries to rearrange grid areas, change dimensions of a grid, and rearrange the placement of items.
In the preview, when the viewport width is 300px or more, the number of columns changes from 1 to 2. The advertisement area then occupies the left column completely.
< / section >
## Instructions
< section id = 'instructions' >
When the viewport width is < code > 400px< / code > or more, make the header area occupy the top row completely and the footer area occupy the bottom row completely.
< / section >
## Tests
< section id = 'tests' >
```yml
2018-10-04 14:37:37 +01:00
tests:
2019-02-22 19:30:33 +00:00
- text: When the viewport is < code > 400px</ code > or more, < code > container</ code > class should have a < code > grid-template-areas</ code > property in which the header and footer areas occupy the top and bottom rows respectively and advert and content occupy the left and right columns of the middle row.
2019-07-24 03:54:35 -07:00
testString: assert(code.match(/@media \s*?\(\s*?min-width\s*?:\s*?400px\s*?\)[\s\S]*.container\s*?{[\s\S]*grid-template-areas\s*?:\s*?"\s*?header\s*?header\s*?"\s*?"\s*?advert\s*?content\s*?"\s*?"\s*?footer\s*?footer\s*?"\s*?;[\s\S]*}/gi));
2018-09-30 23:01:58 +01:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'html-seed' >
```html
< style >
.item1 {
background: LightSkyBlue;
grid-area: header;
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
.item2 {
background: LightSalmon;
grid-area: advert;
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
.item3 {
background: PaleTurquoise;
grid-area: content;
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
.item4 {
background: lightpink;
grid-area: footer;
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
.container {
font-size: 1.5em;
min-height: 300px;
width: 100%;
background: LightGray;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 50px auto 1fr auto;
grid-gap: 10px;
grid-template-areas:
"header"
"advert"
"content"
"footer";
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
@media (min-width: 300px){
.container{
grid-template-columns: auto 1fr;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"advert header"
"advert content"
"advert footer";
}
}
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
@media (min-width: 400px){
.container{
/* change the code below this line */
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
grid-template-areas:
"advert header"
"advert content"
"advert footer";
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
/* change the code above this line */
}
}
< / style >
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
< div class = "container" >
< div class = "item1" > header< / div >
< div class = "item2" > advert< / div >
< div class = "item3" > content< / div >
< div class = "item4" > footer< / div >
< / div >
```
< / div >
< / section >
## Solution
< section id = 'solution' >
2018-10-23 16:21:53 +03:00
```html
< style >
.item1 {
background: LightSkyBlue;
grid-area: header;
}
.item2 {
background: LightSalmon;
grid-area: advert;
}
.item3 {
background: PaleTurquoise;
grid-area: content;
}
.item4 {
background: lightpink;
grid-area: footer;
}
.container {
font-size: 1.5em;
min-height: 300px;
width: 100%;
background: LightGray;
display: grid;
grid-template-columns: 1fr;
grid-template-rows: 50px auto 1fr auto;
grid-gap: 10px;
grid-template-areas:
"header"
"advert"
"content"
"footer";
}
2018-09-30 23:01:58 +01:00
2018-10-23 16:21:53 +03:00
@media (min-width: 300px){
.container{
grid-template-columns: auto 1fr;
grid-template-rows: auto 1fr auto;
grid-template-areas:
"advert header"
"advert content"
"advert footer";
}
}
@media (min-width: 400px){
.container{
/* change the code below this line */
grid-template-areas:
"header header"
"advert content"
"footer footer";
/* change the code above this line */
}
}
< / style >
< div class = "container" >
< div class = "item1" > header< / div >
< div class = "item2" > advert< / div >
< div class = "item3" > content< / div >
< div class = "item4" > footer< / div >
< / div >
2018-09-30 23:01:58 +01:00
```
< / section >