2021-10-08
1609
#css
Sarah Chima Atuonwu
69819
Oct 8, 2021 ⋅ 5 min read

Native CSS nesting: What you need to know

Sarah Chima Atuonwu I am a Fullstack software developer that is passionate about building products that make lives better. I also love sharing what I know with others in simple and easy-to-understand articles.

Recent posts:

Scroll-Aware UI CSS

Implementing scroll-aware UI state with CSS

We investigate the concept of scroll-aware UI state for increased interactivity and explore how to implement it using only CSS.

David Omotayo
Dec 14, 2023 ⋅ 11 min read
Strapi Adoption Guide Overview Use Cases Alternatives

Strapi adoption guide: Overview, examples, and alternatives

Delve into Strapi’s features and more to understand when and why you should use this open source headless CMS for your next project.

Peter Ekene Eze
Dec 14, 2023 ⋅ 16 min read
Visual regression testing with Argos CI

Visual regression testing with Argos CI

Learn how to make visual regression tests easy and fast with Argos CI, an automation tool that compares screenshots during build time.

Andrew Evans
Dec 13, 2023 ⋅ 5 min read
Designing Advanced Layouts With CSS Subgrid

Designing advanced layouts with CSS Subgrid

Use CSS Subgrid to design advanced and responsive grid layouts that are consistently aligned and independent of each other.

Ibadehin Mojeed
Dec 13, 2023 ⋅ 6 min read
View all posts

5 Replies to "Native CSS nesting: What you need to know"

  1. Maybe not best to use it unless totally necessary, as SCSS still has advantages of not requiring to use that many ampersands in the code. And it can easily be forgotten or that it can catch errors before the compiling has completed. And also that we have modules that we can work from which would make it ideal. But either way would be good to have that as native.

    Kind regards,
    Michael

  2. BBEdit can reformat these before and after examples to be much easier to understand. For instance, here’s the over-nested example:

    main
    {
    & section { background-color: red;
    & ul { background-color: green;
    & .list { font-size: 16px;
    & .link { color: pink;
    &: hover { color: blue;
    }

    main section { background-color: red; }
    main section ul { background-color: green; }
    main section ul .list { font-size: 16px; }
    main section ul .list .link { color: pink; }
    main section ul .list .link:hover { color: blue; }

  3. After writing Less, Sass, SCSS, Stylus, back to SCSS… and now spending a year with no pre-processor: it’s hard to imagine using this syntax. As huge fans of nesting… we can’t believe we’re come to a point where we might just prefer not to. If we could skip the & on every line, and we also had HTTP2 or something concatenate the files natively, maybe it would be a winner. We’ll cross our fingers for something better to happen… or wait to evolve our stance.

Leave a Reply