I have a question concerning CSS selectors. How to choose a correct one? For example I have this piece of HTML:
<header>
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<p style="font-size:1.2em" class="navbar-text">Project name</p>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="navbar-nav nav navbar-right">
<li><a style="font-size:1.2em" href="#AboutMe">Text1</a></li>
<li><a style="font-size:1.2em" href="#Social">Text2</a></li>
<li><a style="font-size:1.2em" href="#Projects">Text3</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</nav>
</header>
To make my list elements li in unordered list ul to change appearance I saw next CSS selector:
.navbar-inverse .navbar-nav > li > a:hover {
background-color: white;
color: black;
}
And how I understand this selector says: chose all a elements children of li element who in his turn a child of an element with .navbar-nav class (?) and all of this inside and element with .navbar-inverse class (?).
And this work well. But. If change this selector to another one:
li > a:hover {
background-color: white;
color: black;
}
This does not work. But what it's say: chose all a elements that's a direct children of li element.
Or maybe I do not understand very well concept of CSS selectors.
Thanks.
Edit:
That's all my internal CSS who could potentially influence nav element.
Thanks.
/*
Solution from "http://stackoverflow.com/questions/11124777/twitter-bootstrap-navbar-fixed-top-overlapping-site"
*/
body { padding-top: 40px; }
@media screen and (max-width: 768px) {
body { padding-top: 0px; }
}
.anchor {
padding-top:40px;
}
.navbar-inverse .navbar-nav > li > a:hover {
background-color: white;
color: black;
}
.navbar {
background-color: #444;
border: 0px;
letter-spacing: 2px;
padding-right: 50px;
padding-left: 50px;
}