Hasty Treat - CSS Nesting 1
In this Hasty Treat, Scott and Wes talk about CSS nesting — what it is, when to use it, and why.
Prismic - SponsorPrismic 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 - SponsorIf 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 Notes04: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
- Component-based — tweet, card, company, Link
and must be the first child of a compound selector
12:44 - @nest rule / media queries
- Mostly just a visual way to show nested
16:30 - How to use nesting today
- Literally any CSS preprocessor
- PostCSS to use spec
- Scott’s Instagram
- LevelUpTutorials Instagram
- Wes’ Instagram
- Wes’ Twitter
- Wes’ Facebook
- Scott’s Twitter
- Make sure to include @SyntaxFM in your tweets