2018-09-30 23:01:58 +01:00
---
id: 587d7dbd367417b2b2512bb5
title: Nest CSS with Sass
challengeType: 0
2019-08-05 09:17:33 -07:00
forumTopicId: 301457
2021-01-13 03:31:00 +01:00
dashedName: nest-css-with-sass
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2019-10-27 15:45:37 -01:00
Sass allows nesting of CSS rules, which is a useful way of organizing a style sheet.
2020-11-27 19:02:05 +01:00
2018-09-30 23:01:58 +01:00
Normally, each element is targeted on a different line to style it, like so:
2019-05-14 05:01:32 -07:00
```scss
nav {
background-color: red;
}
nav ul {
list-style: none;
}
nav ul li {
display: inline-block;
}
```
2019-10-27 15:45:37 -01: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:
2019-05-14 05:01:32 -07:00
```scss
nav {
background-color: red;
ul {
list-style: none;
li {
display: inline-block;
}
}
}
```
2020-11-27 19:02:05 +01:00
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01: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-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Your code should re-organize the CSS rules so the `h1` and `p` are nested in the `.blog-post` parent element.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01: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-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
```html
2020-05-09 16:31:18 +02:00
< style type = 'text/scss' >
2018-09-30 23:01:58 +01:00
.blog-post {
2018-10-08 01:01:53 +01:00
2018-09-30 23:01:58 +01:00
}
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-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
2019-05-01 01:55:22 +02:00
```html
2020-05-09 16:31:18 +02:00
< style type = 'text/scss' >
2019-05-01 01:55:22 +02:00
.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 >
2018-09-30 23:01:58 +01:00
```