Yes, most definitely. Selector rules can be overridden by rules that appear later in the style sheet’s written order. This is a fundamental concept in CSS and well worth taking the time to explore further, imho.
Take for example the anchor element, which has pseudo-class selectors in its repertoire.
a {}
a:link {}
a:visited {}
a:hover {}
a:focus {}
a:active {}
The order in which we write these selectors will have a definite bearing on whether they have any influence, let alone the affect we expect. We’re going to use all of them, so best get the order that we can expect the best result from, which is the above. Mind, we can switch :hover
and :focus
around since they are independent.
If these pseudo-classes are foreign, then do read up on them. It’s a brief learning opportunity that won’t take much of your time and will still in your lexicon for all time.
Briefly, I’ve defined the generic selector first so it has least specificity. However, I give it all the properties relating to style so it becomes the basic template for that element. :link
let’s me define things like color and text-decoration; :visited
let’s me override the color and/or text-decoration (for instance why underline a link we’ve already visited, a visual clue without even changing color, though color is a better one); :hover
and :focus
are reason again to change color and/or outline (default for focus) and/or background, border, etc. We should not change font-size or font-weight since that causes jumping motion that is disturbing to some users. Ditto with alignment. Color change and text-decoration are the best signals to give the user.
:active
is for when the user has depressed the mouse button or a keyboard user has pressed ‘Enter’. We can leave the link in view with a different color to give a signal of, ‘this is where we are.’
In order for any of this to work we need the written order as suggested above.
Now back to the OP, it is strongly advisable to dig into CSS just as a read, without clacking any keys. Just read, reason, reread, and store it away. Once turning to practical usage a lot more will make sense in a viable way. Read, read, read.
Learn why we write selector rules with the least specificity possible. I almost challenge one to do that just for the exercise. CSS is so beautiful, and so pliable. There is good reason it has been a spec for decades past, and is certain to be in good stead for decades to come. Learn the whys and wherefores of this bold statement. Then you begin to understand CSS and take command of it. It is, after all a declarative language, not an imperative one.
Actually, post Level II all elements have one pseudo-class, :hover
. We can hover on any element, not just a link.