CSS Layers Are Changing How Specificity Works

Sdílet
Vložit
  • čas přidán 16. 05. 2024
  • FREE CSS Selector Cheat Sheet: webdevsimplified.com/specific...
    Specificity in CSS is a pain to deal with, but that doesn’t have to be the case anymore. With custom CSS layers you can create your own specificity hierarchy which makes writing and overwriting styles so much easier.
    📚 Materials/References:
    FREE CSS Selector Cheat Sheet: webdevsimplified.com/specific...
    CSS Specificity Video: • Learn CSS Specificity ...
    CSS Specificity Blog Article: blog.webdevsimplified.com/202...
    Cascade Layers Blog Article: blog.webdevsimplified.com/202...
    🌎 Find Me Here:
    My Blog: blog.webdevsimplified.com
    My Courses: courses.webdevsimplified.com
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/WebDevSimplified
    CodePen: codepen.io/WebDevSimplified
    ⏱️ Timestamps:
    00:00 - Introduction
    00:50 - CSS Layer Basics
    03:45 - Custom CSS Layers
    07:06 - Using Layers With External CSS
    10:58 - Using Important In Layers
    12:08 - Nested Layers
    13:22 - Browser Support
    #CSS #WDS #CSSLayers

Komentáře • 94

  • @VinceAggrippino
    @VinceAggrippino Před 6 měsíci +7

    7:17 "Boots-crap code"... I agree completely with this review 😁

    • @toyflish
      @toyflish Před 3 měsíci

      he really said that :D

  • @hugoanderkivi
    @hugoanderkivi Před 2 lety +49

    Didn't think it was possible to make me hate !important even more, but you have done it.

    • @three-two-onesas
      @three-two-onesas Před rokem +1

      YESSIR

    • @illyias
      @illyias Před 5 měsíci +1

      Why in the WORLD would they implement it like that? My god

  • @MajorRushMore
    @MajorRushMore Před 2 lety +14

    Nice job not getting tongue tied saying "specificity" over and over! 🙌

  • @gohancomfejao
    @gohancomfejao Před 2 lety +18

    It’s nice to see a great feature already implemented on tailwind being natively supported on major browsers!

  • @alvarojflores
    @alvarojflores Před 2 lety

    Thank you for the simplicity!

  • @_the_one_1
    @_the_one_1 Před 2 lety +6

    Kyle your teaching style is amazing! I wish you could teach a little us some Sveltekit content! I know that you are more into React and personally I am more into Vue but man, Sveltekit is amazing! Please add some content related to it.

  • @_the_one_1
    @_the_one_1 Před 2 lety +1

    Awesome explanation! Thank you!

  • @ericnjanga3245
    @ericnjanga3245 Před rokem +1

    Amazing, thank you!

  • @trimbrains911
    @trimbrains911 Před 2 lety +2

    Interesting feature and nicely explained. I found that adopting the ITCSS approach solved my specificity issues. The possibility to "layer" a third party framework is interesting though, especially if they've written overly specific selectors.

  • @Dream-Web
    @Dream-Web Před 2 lety +1

    Thanks a lot for teaching such an important thing

  • @cristhiandelgado6189
    @cristhiandelgado6189 Před 2 lety +1

    Your explanation are the best

  • @AttilaButurla
    @AttilaButurla Před 2 lety +1

    Excellent content, as always.

  • @titan6392
    @titan6392 Před rokem

    You're so good thanks a lot man 🙂 i learnt something new.

  • @JuanIGN95
    @JuanIGN95 Před 2 lety +6

    Today on my work, I got some messy css old code that I need to improve and I had some problems with libraries… I will test this tomorrow and if it works I will be sooooo happy 😂 thanks for share and it’s crazy that you uploaded it the same day I encounter this problem 🤣

    • @JuanIGN95
      @JuanIGN95 Před 2 lety +4

      bad news... experimental thing not ready for production 😂 will wait till supported to all browsers.

  • @Aalii6
    @Aalii6 Před 2 lety +1

    very interesting, thank you!

  • @sumandutta4074
    @sumandutta4074 Před rokem +1

    Congratulations to advance 1 million subscribers 🥳🥳🥳🥳

  • @fadfooood
    @fadfooood Před 2 lety +1

    First time knowing about layers!

  • @QwDragon
    @QwDragon Před 2 lety

    What are use cases for nested layers? And where we need to order them?

  • @goffyfoot82
    @goffyfoot82 Před 9 měsíci +1

    Timestamp at 3.35 is spot on ...... try to say specificity is hard enough to say let alone understand.

  • @fadhilh3931
    @fadhilh3931 Před 2 lety +1

    Do you have any tips to improve CSS skill? I already have basic CSS, but sometimes I still struggled to implement some CSS property. Any tips is appreciated.

  • @alvaroprietovideos
    @alvaroprietovideos Před 2 lety +1

    Wow! That is very interesting! Do you know if there is something to prevent css contamination? Something like isolated scopes, or some kind of easy and clean css reseter? Thank you!

  • @rajapoudel5037
    @rajapoudel5037 Před 2 lety +1

    can you make the another tutorial on react testing using jest. I have seen on tutorial already

  • @codehan
    @codehan Před 2 lety

    Does it also work if you want to overwrite css rules from an external library within React css/scss modules?

  • @dave6012
    @dave6012 Před 2 lety +1

    Great CSS insights! Nobody tell Kevin 😬😅

  • @danielm1
    @danielm1 Před 2 lety +7

    Very cool. What sources do you use and/or recommend to keep yourself up-to-date with state of art web dev (besides your amazing youtube channel :)?

    • @sicfxmusic
      @sicfxmusic Před 2 lety +2

      A designer/developer should never reveal their sources 😛

    • @danielm1
      @danielm1 Před 2 lety +1

      @@sicfxmusic So you're saying it's like asking a drug dealer where he gets his drugs :)

    • @seekknowledge1928
      @seekknowledge1928 Před 2 lety +1

      @@danielm1 :)

  • @dancastady8571
    @dancastady8571 Před měsícem

    GAME CHANGER, HOW AM I JUST LEARNING THIS!?!?!?!

  • @geforcesong
    @geforcesong Před rokem +1

    @kyle This is nice, but how can i put css in multiple files in the same layer? define the layer with same name everywhere?

  • @clevermissfox
    @clevermissfox Před 4 měsíci +1

    I’m confused at the end. Does “@layer utilities.anotherLayer “ reference the same layer above it ? ie “@layer utilities {@layer anotherLayer{…} }”? Or utilites.anotherLayer completely separate and just one long name that isn’t related to the former ?
    Eg.
    ” @layers utilities, utilities.anotherLayer, frameworks, etc”
    @layer anotherLayer, frameworks, etc

  • @cursorcodecamp
    @cursorcodecamp Před 2 lety +1

    hello.. off topic but wanted you to do a javascript async await video. i've gone through your playlists but there's none..

  • @biLLie_wiLLie
    @biLLie_wiLLie Před 2 lety +2

    @layers has 59% support on caniuse

  • @Raaaww
    @Raaaww Před 2 lety +1

    This is probably a dumb question, but is there any way to access a component(next js) in _apps.js from other pages? I want to move the change theme button to a menu, but can't figure out how to do it :/

  • @paxdriver
    @paxdriver Před 2 lety +1

    Why not replace !important with a layer called "important"? Any downsides to that?

  • @TheGarageboyz
    @TheGarageboyz Před 2 lety +1

    First viewer! Enjoying your videos man!

  • @Videoguy789
    @Videoguy789 Před 10 měsíci +1

    7:17 bootsCrap - nice freudian slip there

  • @cricket_talk6197
    @cricket_talk6197 Před 2 lety +1

    U r the best

  • @kareemsakr41
    @kareemsakr41 Před 2 lety +1

    You are amazing

  • @romanext921
    @romanext921 Před 2 lety +1

    This is cool. But what about the backwards compatibility? Ios especially is a pain in the ass when it comes to styles incapatability

  • @mannumannu9200
    @mannumannu9200 Před 2 lety +1

    Then how to overridie !important of bootstrap

  • @borstenpinsel
    @borstenpinsel Před 2 lety +1

    WTH. I always thought the later (higher line number) the style comed in the sheet, it will override earlier styles. First time I learn about specifity. This explains so much... why I had to resort to using !important even though I know I shouldn't need it, if I "order" by css right...

    • @ShadowVipers
      @ShadowVipers Před 2 lety +2

      If the selectors are of the same specificity, then it goes by whichever selector comes last (order based), although, if specificity is higher then the order in which it's defined doesn't matter.

  • @WetaNewZealand
    @WetaNewZealand Před 2 lety +1

    Nice

  • @whatthefunction9140
    @whatthefunction9140 Před 2 lety +2

    @layer important 🤔

  • @awekeningbro1207
    @awekeningbro1207 Před 2 lety +2

    why haven't i heard of this before?

  • @andyschulze4973
    @andyschulze4973 Před 11 měsíci +1

    Oh, and here is a question: you said that the important! rule inside bootstrap messes the whole thing up, since these rules are applied the other way around. But if so, I can never include an external CSS-library, because I can never gurantee, that they won't use important! in their code, right!? :/

    • @nielsdegroot9138
      @nielsdegroot9138 Před 4 měsíci +1

      You can define a layer before the layer in which you import bootstrap. In that first layer you can create !important rules which will overwrite the bootstrap !important ones.
      But the best thing is for frameworks to not use !important in their css. But that might take their developers some time to take out. (If it was easy they probably wouldn't have put them in in the first place)

  • @spicynoodle7419
    @spicynoodle7419 Před 2 lety +1

    Basically like !default in sass

  • @Holy_Frijole
    @Holy_Frijole Před 2 lety +1

    [11:10] ok we need @veryimportant j/k. Hmmm not sure if this reverse of importance is a good call or a mistake by those in charge.

  • @andyschulze4973
    @andyschulze4973 Před 11 měsíci

    Thank you. Very well explained! However, I am aware that long tutorials don't sell, but could you please slow down a little next time!? :D It was a bit hard to follow along. Anyway: nice work! :)

  • @sicfxmusic
    @sicfxmusic Před 2 lety +1

    How is the browser support? I hate when clients use outdated browsers and complain about things not working properly!! 😠

  • @yadusolparterre
    @yadusolparterre Před 2 lety +1

    Please tell me if I am wrong... If you put Bootstrap inside the lowest layer, it is impossible to override any of its rules that have the "!important" keyword in the higher layers... But since Bootstrap uses "!important" in virtually every single rule, I guess that it's useless to import it in a layer... Am I right?

    • @ogreeni
      @ogreeni Před rokem +2

      I believe you could put Bootstrap inside its own layer and then define the rest of your styles at the top level. Then your own styles would be considered more specific.

    • @yadusolparterre
      @yadusolparterre Před rokem +1

      @@ogreeni no because !important will override from the bottom layer to the top and not the other way around

    • @ogreeni
      @ogreeni Před rokem +1

      @@yadusolparterre yes, but would it override everything including code that is not within a layer, or only up to the upmost layer?

    • @yadusolparterre
      @yadusolparterre Před rokem +1

      @@ogreeni good question, I don't know

  • @MrCC-hx8xr
    @MrCC-hx8xr Před 2 lety +1

    Fresh & modern & intuitive & fast curve of learning = KYLE aka WDS + luxury hair ;-)))))

  • @david.petrey
    @david.petrey Před rokem +1

    Now having watched the last part about nested layers and !important in layers I'm going to buy stock in Tylenol and any other company selling headache medicine. 🤣

  • @devarshihazarika4871
    @devarshihazarika4871 Před 2 lety +1

    Important had to be different

  • @pfcokelly
    @pfcokelly Před 2 lety +2

    With layers I don't need Kevin Powell no more! Jk

  • @NitNet
    @NitNet Před 2 lety

    CSS can be used in making advance animation, but SCSS/SASS is better over normal CSS.

  • @chaozou6283
    @chaozou6283 Před 2 lety +1

    Looks like scss wrapper

  • @TariqSajid
    @TariqSajid Před 2 lety

    Can you please make tutorial on redux toolkit that do crud in array without making any api calls

  • @MdFahimMuntasir
    @MdFahimMuntasir Před 2 lety

    First viewer since your video starts

  • @sandeeptottadi
    @sandeeptottadi Před 2 lety

    Hello

  • @lucasa8710
    @lucasa8710 Před 2 lety +1

    does it works on SCSS?

  • @ryan-heath
    @ryan-heath Před 2 lety +1

    Did you just scoff at bootstrap? 😆

  • @david.petrey
    @david.petrey Před rokem +1

    So now instead of having !important scattered all over the place devs will start adding non-layered styles whenever they are in a bind and have to override something. Only now there is no way at-all to override non-layered styles except with other non-layered styles plus specificity? And so !important will still get used. Isn't that what's going to happen when this isn't managed properly? lol

  • @Sanguinezor
    @Sanguinezor Před 2 lety +2

    Boots"Crap" code (^_^)

  • @DanThemes
    @DanThemes Před 2 lety +1

    So basically you cannot overwrite both !important and non-!important styles. Since 3rd-party CSS might have both, that makes CSS Layers pretty much useless.

  • @reyzKhight
    @reyzKhight Před 2 lety

    4th

  • @johnryder8464
    @johnryder8464 Před 7 dny

    The layer ordering doesn't make sense, logically the most specific layer would appear first not the other way around.

  • @7heMech
    @7heMech Před 2 lety

    888K subs

  • @nitsanbh
    @nitsanbh Před 2 lety +1

    Very cool, but could you use a different color other than red?
    3 giant red rectangles on a white background during the whole video really hurt my eyes, and make it harder to watch

  • @amosmachoradevlogs
    @amosmachoradevlogs Před 2 lety +1

    So like just Sass ryt

  • @Niko753A
    @Niko753A Před 2 lety +1

    is it me who is very slow or is the video really really fast? :-)

  • @MrCC-hx8xr
    @MrCC-hx8xr Před 2 lety

    does anyone know anything closer about this guy? His profession? Sometimes I feel like he can do everything

  • @swapnilkuwar7040
    @swapnilkuwar7040 Před 2 lety

    Second

  • @rajanpoudel7980
    @rajanpoudel7980 Před 2 lety

    First

  • @timm.7740
    @timm.7740 Před 2 lety +1

    I love your vids, am a subscriber, but my God you talk and teach so fast! I'm slowly learning, so it's probably my fault. I wished you would talk/teach slower. Love your teaching though, Kyle!

  • @sohastar1985
    @sohastar1985 Před 2 lety

    Oh man , is anyone catching you !? Toooo much fast talking 😳🙄🥺🤐

  • @babakfp
    @babakfp Před 2 lety

    people that develop CSS, never disappointed me by releasing broken bs features.

  • @finsflexin
    @finsflexin Před 2 lety

    This could’ve been taught in 2 minutes

  • @kinleygyeltshenwangdue1764

    First