Artwork

内容由Wes Bos and Scott Tolinski - Full Stack JavaScript Web Developers提供。所有播客内容(包括剧集、图形和播客描述)均由 Wes Bos and Scott Tolinski - Full Stack JavaScript Web Developers 或其播客平台合作伙伴直接上传和提供。如果您认为有人在未经您许可的情况下使用您的受版权保护的作品,您可以按照此处概述的流程进行操作https://zh.player.fm/legal
Player FM -播客应用
使用Player FM应用程序离线!

Hasty Treat - CSS Nesting 1

20:11
 
分享
 

Manage episode 289778807 series 1469447
内容由Wes Bos and Scott Tolinski - Full Stack JavaScript Web Developers提供。所有播客内容(包括剧集、图形和播客描述)均由 Wes Bos and Scott Tolinski - Full Stack JavaScript Web Developers 或其播客平台合作伙伴直接上传和提供。如果您认为有人在未经您许可的情况下使用您的受版权保护的作品,您可以按照此处概述的流程进行操作https://zh.player.fm/legal

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?

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 Tweet us your tasty treats!
  continue reading

763集单集

Artwork
icon分享
 
Manage episode 289778807 series 1469447
内容由Wes Bos and Scott Tolinski - Full Stack JavaScript Web Developers提供。所有播客内容(包括剧集、图形和播客描述)均由 Wes Bos and Scott Tolinski - Full Stack JavaScript Web Developers 或其播客平台合作伙伴直接上传和提供。如果您认为有人在未经您许可的情况下使用您的受版权保护的作品,您可以按照此处概述的流程进行操作https://zh.player.fm/legal

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?

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 Tweet us your tasty treats!
  continue reading

763集单集

Tutti gli episodi

×
 
Loading …

欢迎使用Player FM

Player FM正在网上搜索高质量的播客,以便您现在享受。它是最好的播客应用程序,适用于安卓、iPhone和网络。注册以跨设备同步订阅。

 

快速参考指南