No more specificity issues?! (or all new ones 🤔) - A look at CSS Cascade Layers

Поділитися
Вставка
  • Опубліковано 18 жов 2024

КОМЕНТАРІ • 122

  • @LivingRegiment
    @LivingRegiment 2 роки тому +43

    "Uh oh, looks like we've run into a specificity issue..." so mischieveous 😂 I cannot wait for the official release. CSS Layers are going to be a game changer!

    • @peternicholson26
      @peternicholson26 2 роки тому +1

      Nerdiest. T-Shirt. Ever

    • @LivingRegiment
      @LivingRegiment 2 роки тому +3

      @@peternicholson26 If Kevin turned this into a shirt, I would totally buy it lol!

    • @peternicholson26
      @peternicholson26 2 роки тому +3

      I would buy it just out of respect for the amount of times he said specificity without mispronunciation. Ridiculous

    • @Allformyequine
      @Allformyequine Рік тому

      HAHA I laughed at that too lol!

  • @dgcp354
    @dgcp354 2 роки тому +6

    I remember you struggling to say specificity, I think there is actually a dedicated video about it, glad you're saying it with ease is.

  • @SebastianZartner
    @SebastianZartner 2 роки тому +12

    I am really looking forward to cascade layers, as they make my CSS life so much easier! Thank you, Kevin, for explaining this new feature in detail!
    Also a big thank you to the implementers and the specification writers for pushing this feature forward in such a short time! Special thanks go to Miriam Suzanne here!

  • @Morrile1
    @Morrile1 2 роки тому +12

    This is the “Great stuff” that Kevin is a godsend in sharing and explaining in a way we can follow.

  • @nomadshiba
    @nomadshiba Рік тому

    this video was one year ago and i didnt even know this was existed
    this will be a life changer

  • @faisal_foyez
    @faisal_foyez 2 роки тому +9

    Letting the developers defining the layers is going to save their life in large projects. Feeling relieved.

  • @NicholasAlexander1
    @NicholasAlexander1 2 роки тому +1

    This is brilliant! Makes CSS specificity far less mysterious - when you find yourself searching through modules. Now nodules are essentially layered namespaces. Thank you for the clarity.

  • @rockmonty
    @rockmonty 2 роки тому +1

    Great video again. not an easy subject to explain, but Kevin battles through and gives everyone a good understanding . thank you. its nice that the video isn't too long either

  • @voidmind
    @voidmind 2 роки тому +3

    Something that's missing from this video is that you can set a layer to imported CSS files like "@import 'utilities.css' layer(utilities);". So you could import the CSS from a component library this way and have an easier time overriding some styles it defines.

    • @RondellKB
      @RondellKB Рік тому

      Hey bro, I have a problem with this. I am using gulp to concatenate component css files into a main styles.css. In each css file, I have the css within layers, but when the files get concatenated, there are multiple components inside the @component layer for example. this causes the layer specificity to not work. Any idea how to get this to work with my use case?

  • @andreibicu5592
    @andreibicu5592 11 місяців тому

    Lovely explanations! I understood better than when read from Tailwind, for instance.

  • @iwanttobealihgt
    @iwanttobealihgt Рік тому

    thanks for the explanation and examples. Extremely handy!

  • @mrastrogastro
    @mrastrogastro 2 роки тому

    This will save me Kevin, I'm working on an old project with such bad css practice. I will create my layer and voila! :D

  • @nested9301
    @nested9301 3 місяці тому

    the browser support is good for this feature so we can use it now :) great video!

  • @ritwik5774
    @ritwik5774 2 роки тому

    Great video! Very exciting times ahead for CSS with layers and Houdini.

  • @vishwa
    @vishwa 2 роки тому

    Thanks for the video. This thing is awesome. Real problem solver for large projects.

  • @apuravela
    @apuravela 2 роки тому

    Very clear, as ussual. Thanks Kevin

  • @Take-the-Ticket
    @Take-the-Ticket 2 роки тому

    Congrats on your specificity victory!

  • @manytrickpony695
    @manytrickpony695 2 роки тому

    Great way to start the day.

  • @GnomePuntTrainerYT
    @GnomePuntTrainerYT 2 роки тому +7

    You prefaced by saying it's around the corner, and listed the experimental dev browsers that supports it, but it's really important to drive home the point of how CSS Cascade Layers has a whooping 0.04% support right now in the web space. I think we'll be waiting a long time before this CSS feature becomes relevant, but it's still a lot of fun to experiment with and learn!

    • @KevinPowell
      @KevinPowell  2 роки тому +5

      By being in the experimental browsers right now without a flag, it won't be long for it to make the jump to the production ones, and at that point support will hit 70% within a few weeks (of it being in all 3 of course). It'll take awhile before they're safe to use though, since you won't really be building in fallbacks.

  • @raphaelsanchez1235
    @raphaelsanchez1235 2 роки тому

    Oh Kevin ! Thanks so much !!!! Can’t wait official release !
    But i so this in tailwind yet. Can you think they used post css preset-env ?

  • @Ceko
    @Ceko 2 роки тому +1

    Great video. I was thinking about this technique to override bootstraplike frameworks with importants though. If you have such framework, isn’t it always loaded first? I.e. you can define the layers order but at that point the framework is already loaded?

  • @sergejstojanovic2518
    @sergejstojanovic2518 2 роки тому +1

    Love the tumbnail

  • @RevivingCulture
    @RevivingCulture 2 роки тому

    Thanks Kevin it a gr8 video. I have a question this will works for all browsers? Chrome,safari,firefox and IE ?plz help on this

    • @KevinPowell
      @KevinPowell  2 роки тому

      Right now, no, but all of them are actively working on it, so in the not too distant future it will work in all of them, yes

    • @Killyspudful
      @Killyspudful 2 роки тому

      @@KevinPowell Er, well, it ain't never going to work in IE...

  • @jybedesign
    @jybedesign 9 місяців тому

    Excellent video. Thx a lot!

  • @germantoenglish898
    @germantoenglish898 2 роки тому

    Your placeholder text is much more interesting and entertaining than Lorem Ipsum...did you use a gibberish random text generator, if so, where can I find it? Sorry for the off-topic question and thanks for the great tutorial.

  • @StefanH
    @StefanH 2 роки тому

    This is HUGE!

  • @eddiemcconkie4111
    @eddiemcconkie4111 2 роки тому

    Specificity: 31
    Specificicity: 0
    You've set a new record Kevin!

  • @eivindmn
    @eivindmn 2 роки тому +2

    If I understand this correctly, that means that for instance plugin creators for wordpress or similar can declare layers to their css, which then makes my job of overwriting their styling to integrate it better into my theme a lot easier? Because that has been an annoying battle for several occasions.

  • @JulienReszka
    @JulienReszka Рік тому

    Very important video thx

  • @grezvany1372
    @grezvany1372 2 роки тому

    I'm happy about the reversed !important order, because it will allow people to overwrite styles at User (or even browser) level when needed.
    We, the designers/developers, always want to make stuff visually look good and be user friendly for "all" visitors. However some things may be bad for specific end users due to visual issues, and not being able to overwrite styling without breaking 90% of the time in a uniform way is an actual issue. So this new standard will actually be a welcome one.
    Accessibility will always be extremely important, but this will help as well.

  • @chrisallen1745
    @chrisallen1745 2 роки тому

    I need this t shirt! Where the hell did you get it!? Also, great stuff as usual!

  • @andyx4506
    @andyx4506 2 роки тому +1

    This is amazing! By the way, do you have any ideas on making content have a border, but also have rounded corners?

    • @DTunezOfficial
      @DTunezOfficial 2 роки тому

      I assume you cant just make a border radius with a border?

    • @andyx4506
      @andyx4506 2 роки тому

      @@DTunezOfficial Yep. I used border and then border-image gradient, not sure if that disables the border-radius.

    • @hugoanderkivi
      @hugoanderkivi 2 роки тому

      I think box-shadow could enable that.

    • @andyx4506
      @andyx4506 2 роки тому

      @@hugoanderkivi thanks, though i alreay figured it out some time ago

  • @SamCrowetheCreativeCrowe
    @SamCrowetheCreativeCrowe 2 роки тому +1

    Thanks!

  • @dan110024
    @dan110024 2 роки тому

    Nice to see you’ve overcome your specificity issue. I mean the one getting tongue tied 😁
    I totally made this comment before you even mentioned it loll

  • @yassinih5189
    @yassinih5189 2 роки тому

    you can easily give a value of inherent to the a, to avoid that specificity issue

  • @Acaykath
    @Acaykath 2 роки тому +2

    !important is for when the user wants to overwrite something and can't figure out why it gets overridden by the creator. I use it all the time in reStyle when I want a page to have a dark theme that doesn't burn my eyes. But, it really should never be used in production code. If your website code has !important in it, you're doing something wrong.
    This layers thing sounds real useful. Hopefully, this and nesting become mainstream soon.

    • @Xamy-
      @Xamy- 2 роки тому +4

      Or you’re caught by corporate bloat and it’s the only way to override shitty corporate “frameworks”

  • @EmSixTeen
    @EmSixTeen 2 роки тому

    This is confusing, but.. still interesting!

  • @PowBro
    @PowBro 3 місяці тому

    Thank's Maestro

  • @tithos
    @tithos 5 місяців тому +1

    What lorem are you using?

  • @finalsecretofchrono1339
    @finalsecretofchrono1339 2 роки тому

    Kevin, what do you think of Metaverse buzz? Is HTML/CSS going to be history in 10 years?

  • @jemandanders3173
    @jemandanders3173 2 роки тому +2

    Tolkien ipsum, very cool.
    Edit: It appears to be called LOTRem ipsum, if anyone else is interested ;)

  • @antisk8
    @antisk8 2 роки тому

    Great video. Better shirt

  • @brefasdra
    @brefasdra 2 місяці тому

    it would be nice if we could put a class-layer="isolatedLayer" on an element, and then that element and its children would ignore any author styles css rules not in a specified layer (and maybe even an inverse of that to ignore certain layers), so if you had bootstrap on the page and its screwing with something, instead of trying to counter it, you could have a div that completely ignores those bootstrap styles (i always have issues where a site designer has used tag name style definitions, and it screws up my apps styles, to be able to easily switch off some styles for an area would be a lifesaver.
    or maybe instead of/as well as on the element itself, having the css definition be able to do something like that.

  • @adamlongaway
    @adamlongaway 17 днів тому

    The fact that un-layered classes always have greater priority makes this feature nearly unless with any legacy code of much size. Shame, wonderful feature if they reversed that so layered items always were first in priority over non-layered. Only solution for a legacy site is to come up with new class names and semi-by-pass the legacy code which it a ton of work, would have been lovely if layers sat on top of the priority stack :( -- oh what could have been so easy

  • @lizt_official
    @lizt_official 2 роки тому

    Gamechanger 😍

  • @danielk.3017
    @danielk.3017 2 роки тому

    I find that it's a great addition for people who are new to CSS, since it makes things more organized, and it makes it easy to deal with problems quickly. Though having said that, I still think that not using it is better if you have the time to write organized and structured CSS, since less lines of code would be needed, and layering could be done through splitting up your stylesheet into multiple ones.
    Thank you for the video, I found it very informative! ✌🏼

  • @ssygon2
    @ssygon2 2 роки тому

    Nothing worse when trying to add/update a new framework/module and seeing breaking changes in layouts/font styles/etc.
    I've always used an id at the top level in my templates to override:
    my button
    #main {
    .section {
    .button {
    }
    }
    }
    Nice once all browsers adopt this cascade layer specificity can set the styling order.

  • @simpleman1218
    @simpleman1218 2 роки тому

    After third SPECIFICITY word i was like Who are you and where is real Kevin😮 And then you told about the word🤣

  • @fredhair
    @fredhair 2 роки тому +1

    Seems to me like there'd be a lot of issues here especially for library / framework developers. What would be more useful imo is proper namespacing & scoping.. yeah usable scoping (:scope).. and not just for CSS variables. At least we're getting nesting soon but I really am looking forward to the time when I can use is(), has(), where() without worrying about wrapping everything in @supports and pollyfilling. Parent selector is my dream CSS feature and potentially kinda possible with has() but we shall see.

    • @KevinPowell
      @KevinPowell  2 роки тому +2

      has() will be a gamechanger for sure!
      And scoping is on the way as well, though that's going to be a bit longer still.
      I also think this will make libraries and frameworks easier to work with, rather than harder. Could be useful within site builders with custom CSS with WP themes as well.
      We'll only really know once it's out in the wild though!

    • @fredhair
      @fredhair 2 роки тому

      @@KevinPowell Yeah I think if the scoping was there it would help, I just think there's going to be issues with ordering and redeclaration on the user side. Seeing as you mentioned WP, the naming could be solved with just prefixing everything with something very unique (like most do in WP themes / plugins).
      I suppose the more I think about it, the more it makes sense it just doesn't seem like an ideal solution to me but for sure it will be helpful for some specificity issues.
      Anyway, thanks for the video Kevin, I was unaware of layers and you covered them well 👍

    • @MiriamCodes
      @MiriamCodes 2 роки тому +1

      @@fredhair Lucky for you, `@scope` is the primary feature planned for the next update to the Cascade. :) Here's the current draft: www.w3.org/TR/css-cascade-6/

    • @fredhair
      @fredhair 2 роки тому +2

      @@MiriamCodes Yeah it's progress but it will be a long while before it's usable in production. That's still at first draft stage and was only published just over a month ago but at least it's moving in the right direction!

  • @carolmckay5152
    @carolmckay5152 2 роки тому +1

    Is there, or will there be a way to import an external css like this: ?

    • @erics2133
      @erics2133 2 роки тому +1

      That went through my mind as well. Maybe create a wrapper that consists of nothing but a layer with an @import inside it? I can see where that could or couldn't work, so I'll have to test it. Using @import is/was discouraged, I'll have to test how this would affect the reasoning as well.

  • @dolevgo8535
    @dolevgo8535 2 роки тому

    is there a way to check if said framework is using layers? and if not, a way to wrap it?

  • @katetretyakova4901
    @katetretyakova4901 2 роки тому

    so lit t-shirt, man!)))

  • @DeltaNrOne
    @DeltaNrOne 2 роки тому

    This sounds like a pain and a blessing at the same time.

  • @sidthetech7623
    @sidthetech7623 2 роки тому

    Kevin, I will be looking for a front-end designer very soon for our animation festival that will feature our selection online.
    Perhaps someone in your comments is proficient enough and reasonably priced.?!

  • @albuslrc
    @albuslrc 2 роки тому

    Great!

  • @Fachuro
    @Fachuro 2 роки тому +2

    I just wish there was a way to undo !important in CSS - for those times where you work on legacy code and old projects where a client has been puking !important tags all over everywhere they couldn't figure out how specificity actually works - or you know, just because... Because you dont really just wanna go in and remove them all as you could end up breaking something else, because its not like they wrote any tests or snapshots to tell you when something gets broken either - and some clients have systems that go back 2-3 decades and just simply have too much code to realistically be able to know all the places that would rely on that style rule...

  • @dasten123
    @dasten123 2 роки тому

    interesting feature

  • @gwemula
    @gwemula 2 роки тому

    Is this similar to SASS nesting where we use a parent-element class selector (e.g. .navbar) and then style all children elements in it?

  • @lewis4929
    @lewis4929 9 місяців тому

    With this make it easier to manage dark and light themes?

  • @MakoSDV
    @MakoSDV 2 роки тому +2

    Is there ever a valid reason to use !important? It always seems to be used as a hack because the dev didn't want to do it the right way.

  • @FredUA
    @FredUA 2 роки тому

    Could you make an example of this issue using BEM methodology? Maybe this is not a problem with specificity but bad naming and using tag/class/id mash?

    • @FredUA
      @FredUA 2 роки тому

      Awful example.Why do you use class .button for link? Why do you use tag selector? Do anybody write CSS like this? Do you realy need custom properties if you are using nesting selectors and mix it with id/class/attr selectors 🤨

  • @2Fast4Mellow
    @2Fast4Mellow 2 роки тому

    For a second I was afraid that Mozille would introduce (document) layers again... It's the stuff nightmares are made off!

  • @sergejstojanovic2518
    @sergejstojanovic2518 2 роки тому

    Can we name layers however we want or are there already existing names for them: reset, base, components, etc?

    • @KevinPowell
      @KevinPowell  2 роки тому +2

      We can name them however we want, and create as many as we want :)

  • @theomegamale5335
    @theomegamale5335 2 роки тому

    So, because people can't grasp the cascade, they decided to add another layer to the onion? I find specificity as is to be elegant if done right, never really thought it to be difficult. I guess maybe it will help people....I just don't understand the need. Is it just a QOL kind of thing?

    • @Killyspudful
      @Killyspudful 2 роки тому

      As was mentioned in the video - if you've ever had to 'work' with Bootstrap and had designs that differed from its defaults, you'll soon find that you need to write more and more overriding selectors because of how opinionated it is. This will allow you to isolate imported third-party styles without resorting to .class.class.class and other ugly specificity boosting.

  • @FrancisPerronLongpre
    @FrancisPerronLongpre 2 роки тому

    16:29 There's 292 !important in the latest Bootstrap version :(

  • @Strasbourgeois
    @Strasbourgeois Рік тому

    The reason unlayered rules have higher specificity is because they get put inside an anonymous layer that is below all other layers

  • @oliver139
    @oliver139 2 роки тому

    I think this technique will either make thing simplier, or mess up the CSS LOL
    and btw !important is still evil..damn boostrap

  • @ChanyArpin
    @ChanyArpin 2 роки тому

    In Chrome, the User Agent throws an !important on a input’s writing-mode.

  • @welling1
    @welling1 2 роки тому +1

    Doesn't this have the potential to become a complete bloated mess if not carefully handled, especially if working on a large team? This seems like it would be very easy to abuse this power if in a hurry under a tight deadline (or just being lazy).

  • @sharkinahat
    @sharkinahat 2 роки тому +1

    I try to go for the everything-is-a-class thing and get super annoyed when the fix for my problems is to copy-paste to a different place. Argh!

  • @DanielRios549
    @DanielRios549 11 місяців тому

    I didn't like that selectors outside a layer have higher specificity, it should be the opposite

  • @Скофиэлд
    @Скофиэлд 2 роки тому

    is there a way to set a level of importance? such !important Lvl 9

  • @tanaygupta6905
    @tanaygupta6905 2 роки тому

    Me after watching this 👀😳🤩😍❤️

  • @i007c
    @i007c 2 роки тому

    cool

  • @deatho0ne587
    @deatho0ne587 2 роки тому

    Old code with tons of important (that aren't important at all). Think this is just going to make it harder to maintain.

    • @KevinPowell
      @KevinPowell  2 роки тому +1

      If there are a lot of !importants floating around in an old code base, I'd probably wouldn't look at updating it with layers cause yeah, it would be a bit of a nightmare.

    • @deatho0ne587
      @deatho0ne587 2 роки тому

      I kind of wish the important would vanish from modern browsers, but this would most likely break most corporate code looks.

  • @R4GEFORME
    @R4GEFORME 2 роки тому

    What about .nav-list a:not(.button)?

  • @ErickXavier
    @ErickXavier 2 роки тому

    Is it possible to '@import' css within a layer?

    • @KevinPowell
      @KevinPowell  2 роки тому +1

      I tried and it didn't work in Chrome Canary, but I think it's supposed to, so I'm not sure where it'll end up.

  • @levyroth
    @levyroth 2 роки тому

    html * {
    font-size: 16px;
    line-height: 1.6;
    }

  • @whynot9963
    @whynot9963 2 роки тому

    I mean, all of this is great, but using SCSS with nesting (or anything else that offers similar features, like scoped classes, etc) is much better than using plain CSS. My question is, why would anyone bother with vanilla CSS in this day and age?

    • @ritwik5774
      @ritwik5774 2 роки тому

      It's simple. Those tools can use layers under the hood. If they can use native features like layers instead of having to do complex processing, build steps get faster.
      Also, not everyone uses CSS tools. The ideal should always be focusing on getting vanilla CSS as usable as possible, so that we can one day use it directly instead of wrappers.
      CSS can also do things that stuff like sass cannot, like custom variables for instance. And now with Houdini, it's going to get a whole lot more powerful.

    • @KevinPowell
      @KevinPowell  2 роки тому +1

      Well, nesting can cause problems, as I looked at in this video when my .button wouldn't work in the nav, because it had a descendant selector. So, in this case at least, nesting doesn't solve that. I do think this will play SUPER well with Sass, tbh.

    • @whynot9963
      @whynot9963 2 роки тому

      @Kevin Powell but it's much easier to keep stuff organized so that this doesn't happen, you just make a button component, and off you go, no need for complex selectors. But I guess more features and options never hurt anybody :)

    • @whynot9963
      @whynot9963 2 роки тому

      @Ritwik but with SCSS you can avoid this complex selector completely as you just make a button component instead of specifically selecting button in certain spots. But as I mentioned in previous comments, the more features the merrier :)

    • @ritwik5774
      @ritwik5774 2 роки тому +1

      ​@@whynot9963 like I said, not everyone uses scss, and scss has to transpile to css under the hood.
      Kevin already mentioned a very real world use case for layers with the framework overrides.
      Pretty sure the number of people using scss is a miniscule minority compared to the people on frameworks like bootstrap.

  • @user-ms8ei9le7x
    @user-ms8ei9le7x 2 роки тому

    @layer === position : z - index :)))))))
    Kevin thanks 🎓

  • @तुम्हारीमम्मी

    If the js can access @layer then it will be totally gane changer i think 🙄

  • @mma93067
    @mma93067 Рік тому

    Wait. Does this mean i can finally throw away all those god awful CSS-in-JS libs?!

  • @Jan.Feldmann
    @Jan.Feldmann 2 роки тому +1

    Say "specificity" 10 times fast!

  • @owolabioluwapelumi5070
    @owolabioluwapelumi5070 2 роки тому

    First yo get here

  • @pushqrdx
    @pushqrdx 2 роки тому

    To me it looks like a and !important block lol

  • @xanpk2074
    @xanpk2074 2 роки тому

    No more !important; ? :/

  • @MatveyAndreyev
    @MatveyAndreyev 2 роки тому

    CSS specificity is one of the easiest things on Earth.