I am new on HTML and CSS. So there is something I do not understand properly.
For example, take this code-
<li><a href="">Home</a></li>
<li><a href="">Articles</a></li>
<li><a href="">Images</a></li>
<li><a href="">About</a></li>
Now in the style attribute, suppose I am writing-
nav a{
color: black;
text-decoration: none;
}
and,
nav>a{
color: black;
text-decoration: none;
}
what is the difference between them? And how do I realize when to use whom? For example, I wanted to hover the anchor tags. So I had to do it like this-
nav a:hover{
color: blue;
}
why didn't we write it like 'nav>a' here?
Pardon me for this post has become so big and advance thank you.
Edit- I am trying to fix it through editing but the first code is not showing that I used a nav tag. Please pardon me for that.
Top comments (2)
The
>
selector means something is a direct child of something else. So in the case ofnav>a
, it means thea
element has to a direct child ofnav
, whilenav a
meansa
is insidenav
but doesn't have to directly, it can be nested inside other elements, like a child of a child or so on.In the case of the code sample you have,
nav>a
doesn't work becausea
is insideil
, so it's not a direct child ofnav
.I hope this helps.
Thank you ma'am.