* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
175 lines
3.7 KiB
Markdown
175 lines
3.7 KiB
Markdown
---
|
|
id: 5a94fe7769fb03452672e463
|
|
title: Use Media Queries to Create Responsive Layouts
|
|
challengeType: 0
|
|
videoUrl: 'https://scrimba.com/p/pByETK/cMbqeHk'
|
|
forumTopicId: 301138
|
|
dashedName: use-media-queries-to-create-responsive-layouts
|
|
---
|
|
|
|
# --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.
|
|
|
|
# --instructions--
|
|
|
|
When the viewport width is `400px` or more, make the header area occupy the top row completely and the footer area occupy the bottom row completely.
|
|
|
|
# --hints--
|
|
|
|
When the viewport is `400px` or more, `container` class should have a `grid-template-areas` 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.
|
|
|
|
```js
|
|
assert(
|
|
__helpers
|
|
.removeCssComments(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
|
|
)
|
|
);
|
|
```
|
|
|
|
# --seed--
|
|
|
|
## --seed-contents--
|
|
|
|
```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";
|
|
}
|
|
|
|
@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{
|
|
grid-template-areas:
|
|
/* Only change code below this line */
|
|
"advert header"
|
|
"advert content"
|
|
"advert footer";
|
|
/* Only change 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>
|
|
```
|
|
|
|
# --solutions--
|
|
|
|
```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";
|
|
}
|
|
|
|
@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{
|
|
grid-template-areas:
|
|
"header header"
|
|
"advert content"
|
|
"footer footer";
|
|
}
|
|
}
|
|
</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>
|
|
```
|