Comments on: The latest ways to deal with the cascade, inheritance and specificity https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/ Tips, Tricks, and Techniques on using Cascading Style Sheets. Sun, 13 Feb 2022 15:07:06 +0000 hourly 1 https://wordpress.org/?v=6.1.1 By: Sheila Tanner https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/#comment-1614740 Thu, 18 Jan 2018 07:24:43 +0000 http://css-tricks.com/?p=264665#comment-1614740 Most of this seems quite useful to me, aside from the Shadow DOM, which for my coding just makes things more verbose. Aside from that, I will continue to make heavy use of id when writing CSS for SVGs. I tend to use the id as a sort of comment (in that an id of, say, ‘leaf’ will refer to the only leaf in the SVG) that doubles as a class of sorts. The real bonus in using an id in those cases is that the id, unlike an actual comment, is not removed during minification and uses fewer bytes, since id is two letters long and class is five letters long.

On the other hand, my HTML tends to be a bit more complex, so I avoid the use of id except in rare cases where it’s absolutely needed.

I don’t mind being a hybrid of the old and the new so long as I know I understand all the new if I ever need to make a sudden switch.

]]>
By: jamie https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/#comment-1614716 Wed, 17 Jan 2018 17:36:39 +0000 http://css-tricks.com/?p=264665#comment-1614716 :revert appears to only be supported by Safari at present.

]]>
By: Dan https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/#comment-1614655 Tue, 16 Jan 2018 21:45:08 +0000 http://css-tricks.com/?p=264665#comment-1614655 In reply to Brad.

Specificity matters a lot when you work in a team or when you come on to work done by another team. Its crucial you understand specificity and I’m not one for picking up and using whatever new fandangled naming convention is out right now however if you study up on ITCSS BEM (aka BEMIT) & CSS namespacing It will radically change the way you write CSS for the better. I was very much against BEM when I came across it, now I’m fully converted to it having seen how much issues specificity was causing us in work on large projects with a range of skill levels all pitching in over time. No system is perfect ITCSS and BEM certainly are not but their much better than traditional ways of working with CSS.

It will be a joy to use CSS on large projects. Follow people like Harry Roberts (CSSWIZARDRY). Oh and you’ll come across OOCSS, its a nonsense that doesn’t work in the real world, forget about it. OOCSS teaches us to be bone DRY which will cause all manner of issues down the line. Being just DRY enough is good enough….apply common sense.

]]>
By: oliverwilliams345 https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/#comment-1614460 Fri, 12 Jan 2018 13:16:23 +0000 http://css-tricks.com/?p=264665#comment-1614460 In reply to Brad.

Hi Brad. My main advice: don’t bother worrying about naming conventions like BEM or things that sound fancy like OOCSS etc, however popular they may seem. Also don’t worry about Sass. Just make sure you understand how specificity works. Discussions about ‘CSS architecture’ are mostly bikeshedding (and there is no clear best way), but if you really want to read something:

https://adamwathan.me/css-utility-classes-and-separation-of-concerns
https://www.smashingmagazine.com/2016/11/css-inheritance-cascade-global-scope-new-old-worst-best-friends/
http://nicolasgallagher.com/about-html-semantics-front-end-architecture/
https://csswizardry.com/2012/05/keep-your-css-selectors-short/

Main advice: keep specificity as low as possible, use classes a bunch, don’t use IDs for CSS.
So that example could be
.sidebar li {} (which is easier to overwrite later on if need be without the need for !important)

]]>
By: Brad https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/#comment-1614406 Thu, 11 Jan 2018 17:09:38 +0000 http://css-tricks.com/?p=264665#comment-1614406 As someone who still does things like: #sidebar ul li {} is there a recommended resource (or set of resources) all about modern CSS inheritance and best practices? I tend to work on small projects where I’m the only developer so I do what works for me but I’ve long wanted to level up with writing “good” CSS. Thanks.

]]>
By: Comandeer https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/#comment-1614399 Thu, 11 Jan 2018 11:29:17 +0000 http://css-tricks.com/?p=264665#comment-1614399 In reply to Pete.

Actually this flaw (JS dependency) could be solved in future, as there is discussion about creating new tag, shadowroothttps://github.com/whatwg/dom/issues/510

]]>
By: oliverwilliams345 https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/#comment-1614353 Wed, 10 Jan 2018 19:40:29 +0000 http://css-tricks.com/?p=264665#comment-1614353 In reply to Pete.

That’s absolutely true, and a very important consideration. Perhaps you have some components that rely on JavaScript for their functionality – their very raison d’etre relies on javascript. For these things shadow DOM is great. You certainly wouldn’t style every element on a page with shadow DOM – which perhaps I should have made more clear!

]]>
By: Pete https://css-tricks.com/latest-ways-deal-cascade-inheritance-specificity/#comment-1614338 Wed, 10 Jan 2018 14:50:45 +0000 http://css-tricks.com/?p=264665#comment-1614338 My understand of shadow dom is the only way to create a shadow root is via client side javascript? So if your JS doesn’t load you have an unstyled page? Seems like a pretty major flaw if so.

]]>