Getting started with CSS nesting

Getting started with CSS nesting

Kevin Powell

11 месяцев назад

67,593 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Krystian
Krystian - 26.10.2023 10:17

doesnt work

Ответить
Joshua Timothy
Joshua Timothy - 22.10.2023 19:21

This is a long-waited feature in CSS for me and its finally here! I am really grateful that a good person like you is there to provide us with contents like this, you really are a blessing to the community.

Ответить
Daniel H
Daniel H - 25.09.2023 12:33

Will container queries work in nesting

Ответить
Luka janjgava
Luka janjgava - 30.08.2023 11:22

great

Ответить
kno_raziel
kno_raziel - 17.08.2023 10:15

This will work great with Svelte 😮

Ответить
delanyo agbenyo
delanyo agbenyo - 13.08.2023 23:04

Now we need mixins and masonry layouts 😅😅😅

Ответить
VideoNOLA
VideoNOLA - 08.08.2023 00:51

Don't think I heard the term "placeholder" used often enough in this explanation, but that's all & is IMHO.

Ответить
Rémi Dion
Rémi Dion - 02.08.2023 20:13

Thanks for this! This will be awesome when browser support gets there.
A little question, do you know if LESS and SASS will support classic css vs nested css for css outputs?

Ответить
Steve Lam
Steve Lam - 02.08.2023 16:12

Why doesn't the browser use the :where selector when it converts combined selectors?

Ответить
Travis Watson
Travis Watson - 02.08.2023 05:05

I really wish they didn't cave to pressure and make & optional. It's just unintuitive that it's a descendant selector without the ampersand, but you add it to get to same selector... you literally have to ADD the ampersand operator to REMOVE the descendant behavior... this is not normal.

Ответить
Cahn
Cahn - 01.08.2023 19:24

The thing I find annoying in nesting is because you raise specificity, so when I need to make a media query I have to recreate the entire nesting even though I just want to change an li or something.

Ответить
Rick Kukiela
Rick Kukiela - 31.07.2023 20:23

I'm assuming that it didn't really matter, but FTR, the primary-navigation__list element you created was an ID not a class attribute...

Ответить
Chris Mo
Chris Mo - 30.07.2023 00:29

I’ve been using SCSS for a long time…this seems reeeeeeally similar.

Ответить
VP Martin
VP Martin - 29.07.2023 18:41

Awesome video. Thanks!

Ответить
Lakshay Chauhan
Lakshay Chauhan - 26.07.2023 02:36

Hii kevin! So I use Styled components and alot of I do have to get to 3layers of nesting, but that is mostly because I am using many many changing css for my projects.

Ответить
paul porter
paul porter - 25.07.2023 12:13

Thank you Kevin. You are the reason I enjoy CSS.

Ответить
nednosleep
nednosleep - 25.07.2023 02:32

thank god this will change everything for me

Ответить
Sebastian Zartner
Sebastian Zartner - 24.07.2023 23:55

As always, very well explained, Kevin! Especially the gotchas regarding native vs. pre-processor nesting are important to know. Though there are two things that I am missing in this video. One is how you can support browsers that don't support nesting and the other is how the DOM model for nested rules works. (I know, this channel is mainly about CSS but I believe the DOM APIs are part of that and especially for nesting quite important.)

Ответить
Sebastian Zartner
Sebastian Zartner - 24.07.2023 23:26

Note that the restrictions regarding the ampersand selector got relaxed in the latest version of the specification. That means, you do not need an ampersand in front of an element selector anymore. Firefox 117 already ships with this relaxation in the syntax, Chrome and WebKit still need to change that.

Ответить
Favourite Jome
Favourite Jome - 24.07.2023 02:11

That's for the update sir

Ответить
Niner
Niner - 24.07.2023 01:29

This was so overdue ;-) Since about 10 years I was waiting for css nesting to become native :-)

Ответить
Laura
Laura - 23.07.2023 19:18

I may have commented this before, but I'm extremely grateful for your videos. CSS makes so much sense when you explain it. I stumbled into frontend work by accident, so I never took the time to formally learn CSS and have just been brute-forcing my way through stylesheets. But since I've been watching your videos, I'm starting to actually understand why some things work and others don't. It's a great feeling.

Ответить
monkaS is Life
monkaS is Life - 23.07.2023 18:02

i dont think you should use this for at least 1 year until seriously everyone supports it.

until then, using scss and compiling it to css is the safer route

Ответить
Trendy
Trendy - 23.07.2023 02:08

I really think Chrome dev tools should resolve the ampersand symbol to the value and just indicate it's a placeholder by coloring it differently.

Ответить
Wave Icle
Wave Icle - 22.07.2023 19:16

@Kevin think you may need to add a correction, style wasn't applying to ul also because you put that bem style string in the id attribute value not class. makes a lot of sense to stick w sass nesting for me since im using that anyway and browser support is not an issue, but appreciate this info!

Ответить
Michiel Helvensteijn
Michiel Helvensteijn - 22.07.2023 14:03

Why require that nested selectors start with a symbol though? It feels inconsistent and arbitrary.

Ответить
Avaze
Avaze - 22.07.2023 12:08

I wont switch for now, I dont like the gotchas and id lose mixins. I also feel like seeing the & in the dev tools is just confusing, because you have to hover it first to figure out where it's from.

Ответить
Chester XP
Chester XP - 21.07.2023 19:32

GoodJob!

Ответить
Richard Stiehm
Richard Stiehm - 21.07.2023 17:15

This is awesome, can't wait to try it

Ответить
Zakir Nuriiev
Zakir Nuriiev - 21.07.2023 12:22

Thanks a lot for a so nice lesson!

Ответить
Spicy Baguette
Spicy Baguette - 20.07.2023 21:10

I believe PostCSS can translate nested CSS for browsers that don't support it

Ответить
Foxtrot Foxtrot Papa Golf Foxtrot Foxtrot Papa Golf
Foxtrot Foxtrot Papa Golf Foxtrot Foxtrot Papa Golf - 20.07.2023 18:55

I personaly only use Scss and BEM when i know that a project get really big, to organise my code and to speed up the process off writing the code.

I think i will use not all of the fetures when they are out.
But some off them like the media query or for &:hover

Ответить
Miloš Kolčák
Miloš Kolčák - 20.07.2023 17:14

Nice to hear about nesting in CSS, I think that '&' symbol is necessary because of minification/oneline css thing. like 'a {color:red;&small{color: green}}' in this case css know that &small is new element and not css property. (Its just my guessing :D) Nice video.

Ответить
James Rosemary
James Rosemary - 20.07.2023 13:28

At last!. Thirty years later, we finally have the most obvious feature for this language.
I've been waiting for this moment all this time to have CSS nesting!

Ответить
rawveganconnor
rawveganconnor - 20.07.2023 13:02

I owe you a huge thank you. I’ve been struggling to learn the absolute basics of html of almost a year now. I know pathetic. You are my favorite means of learning html. Unbelievable how much replay value your videos have. It’s your tone, voice, pace, kindness, attitude, it’s everything. I hope that everyone can achieve the level of teaching you have in whatever they desire, by applying what you did, time and effort

Ответить
Brain
Brain - 20.07.2023 03:24

Seems like it has a very specific use case. I don't really use BEM personally due to modules, but sometimes for semantics sake I implement some kebab case in my modules and SASS is great because of it.

Ответить
Gbtx6
Gbtx6 - 19.07.2023 23:23

pretty sad firefox has to play a bit of catch up, but i love we're finally getting far more robust features for CSS. I hope some day we can use loops like we do in js in some way, shape or form.
I do have to say, you did, as usual, a phenomenal job covering the good the bad and the ugly kevin! One of my fav tech content creators of all time <3. Bell icon has never felt this good!

Ответить
Ostap1974
Ostap1974 - 19.07.2023 22:05

There have been lately some new standards I have trouble understanding the reasoning behind... Could someone explain the idea why the a { .smth } is OK, but a { li } is not?

Ответить
אהרוני יוסי
אהרוני יוסי - 19.07.2023 22:01

Hi Kevin,
What is the program that you use to record your videos?

Ответить
Itzik CA
Itzik CA - 19.07.2023 21:59

Ha hoisting in css 😂

Ответить
Ayub Elmi
Ayub Elmi - 19.07.2023 21:24

Hi Kevin, Im currently studying web developent and sometimes get discouraged by the advancement in AI and the possibility of replacing devs and I was wondering what your thoughts are. Is it likely that devs will be replaced or they will adapt to the new changes AI brings?

Ответить
Venelin Manchev
Venelin Manchev - 19.07.2023 18:55

In your code "primary-navigation__list" is an id, its not a class!

Ответить
Baka Vaca
Baka Vaca - 19.07.2023 16:50

Literally just yesterday I was pondering how feasible it would be to add sass to a pretty old legacy site but definitely was a little hung up on introducing all the extra complexity to build it.

So excited that css nesting will be a truly viable option in the future as nesting was one of the primary reasons I wanted sass.

Ответить
Lee Smith
Lee Smith - 19.07.2023 16:47

Nesting is basically 99% of what I use less for.
Is there a css->css converter so that we can use this now?
I think I'll take the approach of always using `&`. Sometimes omitting it is just going to lead to bugs...

Ответить
BLK emerone
BLK emerone - 19.07.2023 15:45

I can see the creators of sass stressing a lot

Ответить
Jeffrey Tackett
Jeffrey Tackett - 19.07.2023 15:07

This shows that CSS is getting more like a programming language, and along with that, you need to follow good styling patterns: limit the nesting, property naming, etc… I see linters with these styling rules becoming popular very soon and naming conventions like BEM going away. This also will increase the learning curve at a faster rate.

Ответить
Richard Hindle
Richard Hindle - 19.07.2023 11:03

Have a beer. I get all my css news from you. Super useful video. Always found scss a bit dangerous and extra faff. I like to put things that could cause confusion next to each other on the stylesheet. Putting some of a block's rules in the css file and some in scss file is just asking for human error. Looking forward to using nesting.

Ответить