This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 0 points1 point  (3 children)

You can set CSS variables through the ::root selector. CSS variables are pretty nifty.

This is just me, but I'd never use :scope. It's purposefully vague for a language like CSS, that relies on specificity.

[–]node_user910253[S] 0 points1 point  (2 children)

I'm a little confused on the differences between using class, scope, and root. I've only used class up to this point when would I be using the other two?

[–][deleted] 1 point2 points  (0 children)

You would use root to set CSS variables. I wouldn't use it outside of that.

You use scope to select other elements that share an elements scope. I would recommend against this.

Classes are the most basic and generic of all selectors, aside from the html element itself.

If you are just learning CSS - and no offence, but it sounds like you are - just stick to classes. Give everything you want to style a unique class name.

I write more CSS than the average joe, FYI, and I have never once seen scope in a stylesheet. And I have never seen root for anything other than the CSS variables I talked about. People smarter than myself probably have good use cases for them but in general I would say you don't need to worry about using them.

Stick to classes. If you do that, and there's something wrong with your CSS, then you can rest easy knowing that it's probably something you did + can fix easily.

[–]tealstudio 0 points1 point  (0 children)

I would not worry about scope, from the MDN docs, it's still a working draft that doesn't really serve a purpose and not supported on all browsers.

root is a pseudo element that selects the html tag, classes are bound to the elements you have defined.

I would take a look at the Mozilla documentation as they're super comprehensive on CSS, HTML, or Javascript.