Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Sass Nesting | Preprocessors
course content

Зміст курсу

Advanced CSS Techniques

Sass NestingSass Nesting

The next powerful feature is nesting. It allows us to nest one selector within another to create more organized and readable code. We can group styles and reduce the code we need to write.

Let's imagine that we need to create the website navigation.

navigation example

The html for this navigation will look the following:

Considering that besides the navigation, we use the same html tags (ul, li, a) multiple times throughout the project. To add some styles exactly to these elements, we need to use nesting rules in css. So, css can look as follows:

Now, let's see how sass can makes our lives easier. We will group all these styles in one block. The code is rewritten into:

It's like we're nesting the child's style block in its parent block. Pay attention that the & symbol in the &:hover selector is used to reference the parent selector, in this case, a. This is a shorthand way of writing a:hover and makes it easier to write nested selectors without repeating the parent selector multiple times.

What is the benefit of using sass nesting?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 7. Розділ 5
course content

Зміст курсу

Advanced CSS Techniques

Sass NestingSass Nesting

The next powerful feature is nesting. It allows us to nest one selector within another to create more organized and readable code. We can group styles and reduce the code we need to write.

Let's imagine that we need to create the website navigation.

navigation example

The html for this navigation will look the following:

Considering that besides the navigation, we use the same html tags (ul, li, a) multiple times throughout the project. To add some styles exactly to these elements, we need to use nesting rules in css. So, css can look as follows:

Now, let's see how sass can makes our lives easier. We will group all these styles in one block. The code is rewritten into:

It's like we're nesting the child's style block in its parent block. Pay attention that the & symbol in the &:hover selector is used to reference the parent selector, in this case, a. This is a shorthand way of writing a:hover and makes it easier to write nested selectors without repeating the parent selector multiple times.

What is the benefit of using sass nesting?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 7. Розділ 5
some-alt