meta_pixel
Tapesearch Logo
Log in
Syntax - Tasty Web Development Treats

Hasty Treat - CSS Nesting 1

Syntax - Tasty Web Development Treats

Wes Bos

Tech News, News, Technology

4.9 • 1.2K Ratings

🗓️ 12 April 2021

⏱️ 20 minutes

🧾️ Download transcript

Summary

In this Hasty Treat, Scott and Wes talk about CSS nesting — what it is, when to use it, and why. Prismic - Sponsor Prismic is a Headless CMS that makes it easy to build website pages as a set of components. Break pages into sections of components using React, Vue, or whatever you like. Make corresponding Slices in Prismic. Start building pages dynamically in minutes. Get started at prismic.io/syntax. Sentry - Sponsor If you want to know what’s happening with your code, track errors and monitor performance with Sentry. Sentry’s Application Monitoring platform helps developers see performance issues, fix errors faster, and optimize their code health. Cut your time on error resolution from hours to minutes. It works with any language and integrates with dozens of other services. Syntax listeners new to Sentry can get two months for free by visiting Sentry.io and using the coupon code TASTYTREAT during sign up. Show Notes 04:22 - What is it? https://drafts.csswg.org/css-nesting-1/#nest-prefixed https://twitter.com/argyleink/status/1371874777548267520 06:02 - Why nest? Easier to read Easier to write Prevents refactoring errors, allows for dry-er code. No more typing a parent div 100 times, with a possibility of screwing it up. 08:13 - When to use nesting Nesting is often overused Only nest what you would have written un-nested with a short hand (e.g. don’t nest just for the sake of it) .container .item {} .container .item a {} Use it for scoping 10:06 - Nesting prefixes In order to nest CSS, you must first start it with a nesting selector .tweet { & > p { } &.media-included { color: green; } & + .tweet { } // sibling & p { } // descentang } Component-based — tweet, card, company, Link article{ color: blue; & { color: red; } } and must be the first child of a compound selector 12:44 - @nest rule / media queries Mostly just a visual way to show nested .foo { display: grid; @media(orientation: landscape) { & { grid-auto-flow: column; } } } .foo { display: grid; @media (orientation: landscape) { & { grid-auto-flow: column; } @media (min-inline-size > 1024px) { & { max-inline-size: 1024px; } } } } /* equivalent to .foo { display: grid; } @media (orientation: landscape) { .foo { grid-auto-flow: column; } } @media (orientation: landscape) and (min-inline-size > 1024px) { .foo { max-inline-size: 1024px; } } */ 16:30 - How to use nesting today Literally any CSS preprocessor PostCSS to use spec Links Syntax 274: How does stuff get added to CSS? Adam Argyle answers! Sass PostCSS CSS Variables Tweet us your tasty treats! Scott’s Instagram LevelUpTutorials Instagram Wes’ Instagram Wes’ Twitter Wes’ Facebook Scott’s Twitter Make sure to include @SyntaxFM in your tweets

Transcript

Click on a timestamp to play from that location

0:00.0

Monday Monday Monday open wide dev fans get ready to stuff your face with Javascript CSS node module barbecue tips get work flows break dancing soft skills web development the hastiest the

0:13.5

Carrazius the tastiest web development treats coming in hot here is West

0:19.2

Barakuda boss and Scott L. Toro Lungo to Linsky

0:25.2

Welcome to syntax in this Monday hasty treat. We're going to be talking about a new feature to CSS that

0:35.3

While it's still in a draft. It's kind of the first look that we're getting to see at this feature

0:40.6

And this is one of those things that anybody who's using CSS preprocessors for a long time are going to rejoice at

0:46.5

I'm talking about CSS nesting so as always my name is Scott Linsky

0:52.0

I'm a developer from Denver Colorado and with me is always is the West boss. Hey everybody. What's up?

0:58.4

West. Oh, we just had a plumber come to our house and fix a whole bunch of disgusting septic issues

1:06.4

We had so so thankful that that's all solved. No, thank you. No, thank you. No, thank you. No, thank you. Yeah, they were like

1:13.0

sewage pumping out in the street. It was so weird in our neighborhood the other like last week

1:20.0

And it was our neighbor like across the street neighbors and it was like maybe nine o'clock ten o'clock one

1:27.1

Like the you know, have you seen ET? I think so. Yeah. Yeah, it's one of the few there was like the scene in ET

1:33.2

We're all like those like crazy government people show up with spotlights and our fume it like they have the house all locked down

1:39.0

It's like very scary. That's like what our street look like there

1:42.2

It's like 800 trucks showed up out of the middle of nowhere at like 9 p.m. And just started

1:48.0

Excavating like maybe like 20 feet down. It was like crazy. What a crappy job. That must be oh

1:55.4

Yeah, you saw it. Yes crappy job indeed. You saw like with big tubes go down there and pull it out. It's like covered in

2:01.6

Gross stuff. Yucky. Yucky. No, thank you. So I'm sorry about your septic issues. That sounds like a crappy time

2:09.4

You already said crappy. I don't know. Yeah. Okay. So before we get into CSS

2:14.1

Nesting here. Let's talk about some of our sponsors

2:16.1

We have prismic and century as our sponsors today

...

Please login to see the full transcript.

Disclaimer: The podcast and artwork embedded on this page are from Wes Bos, and are the property of its owner and not affiliated with or endorsed by Tapesearch.

Generated transcripts are the property of Wes Bos and are distributed freely under the Fair Use doctrine. Transcripts generated by Tapesearch are not guaranteed to be accurate.

Copyright © Tapesearch 2026.