Search code examples
javascripthtmlcssweb-frontend

What is the difference betweeen specifying "a" and taking whole class/container?


Okay so I've been making website for my mom's business and stumbled onto an interesting thing I can't really find difference on, right now, since website is still in early development.(tried googling but no help)

So basically my question is:

What is the difference in css(and html) between;

container a:hover;

and

container:hover;

I mean it shouldn't be any different. In both cases, as long as there is only <a></a> type used like here, it will apply to everything:

<a href="index.html">#name of the button</a>

The thing is here:

.nav-link-wrapper:hover {
    border-bottom: 1px solid black;
}
.nav-link-wrapper a:hover {
    color:black;
} 

Why do I have to specify a that is within the class, to apply color, when I don't have to for manipulating borders.

Sry if it was asked. This is more of a beginner's question and I can't find anybody who already asked this.


Solution

  • If you set color in .nav-link-wrapper:hover, it will not affect since a tag has its own style. So in order to add style for that a tag, you will need to specify a.