2018-10-10 22:03:03 +00:00
---
id: 587d7dbd367417b2b2512bb5
2021-02-06 04:42:36 +00:00
title: Nest CSS with Sass
2018-10-10 22:03:03 +00:00
challengeType: 0
2020-09-07 08:11:08 +00:00
forumTopicId: 301457
2021-01-13 02:31:00 +00:00
dashedName: nest-css-with-sass
2018-10-10 22:03:03 +00:00
---
2020-12-16 07:37:30 +00:00
# --description--
2021-02-06 04:42:36 +00:00
Sass allows nesting of CSS rules, which is a useful way of organizing a style sheet.
2020-12-16 07:37:30 +00:00
2021-02-06 04:42:36 +00:00
Normally, each element is targeted on a different line to style it, like so:
2020-09-07 08:11:08 +00:00
```scss
nav {
background-color: red;
}
nav ul {
list-style: none;
}
nav ul li {
display: inline-block;
}
```
2021-02-06 04:42:36 +00:00
For a large project, the CSS file will have many lines and rules. This is where nesting can help organize your code by placing child style rules within the respective parent elements:
2020-09-07 08:11:08 +00:00
```scss
nav {
background-color: red;
ul {
list-style: none;
li {
display: inline-block;
}
}
}
```
2020-12-16 07:37:30 +00:00
# --instructions--
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
Use the nesting technique shown above to re-organize the CSS rules for both children of `.blog-post` element. For testing purposes, the `h1` should come before the `p` element.
2018-10-10 22:03:03 +00:00
2020-12-16 07:37:30 +00:00
# --hints--
2018-10-10 22:03:03 +00:00
2021-02-06 04:42:36 +00:00
Your code should re-organize the CSS rules so the `h1` and `p` are nested in the `.blog-post` parent element.
2018-10-10 22:03:03 +00:00
2020-12-16 07:37:30 +00:00
```js
assert(
code.match(
/\.blog-post\s*?{\s*?h1\s*?{\s*?text-align:\s*?center;\s*?color:\s*?blue;\s*?}\s*?p\s*?{\s*?font-size:\s*?20px;\s*?}\s*?}/gi
)
);
2018-10-10 22:03:03 +00:00
```
2021-01-13 02:31:00 +00:00
# --seed--
## --seed-contents--
```html
< style type = 'text/scss' >
.blog-post {
}
h1 {
text-align: center;
color: blue;
}
p {
font-size: 20px;
}
< / style >
< div class = "blog-post" >
< h1 > Blog Title< / h1 >
< p > This is a paragraph< / p >
< / div >
```
2020-12-16 07:37:30 +00:00
# --solutions--
2020-08-13 15:24:35 +00:00
2021-01-13 02:31:00 +00:00
```html
< style type = 'text/scss' >
.blog-post {
h1 {
text-align: center;
color: blue;
}
p {
font-size: 20px;
}
}
< / style >
< div class = "blog-post" >
< h1 > Blog Title< / h1 >
< p > This is a paragraph< / p >
< / div >
```