Hello, I’m learning CSS and have a suspicion I didn’t solve a skill test in the intended way.
In trying to match the white background, my working CSS looks like this:
/* Specificity: 0113 */
/* Goal: override the blue background-color with initial */
#outer div ul .nav a {
background-color: blue;
padding: 5px;
display: inline-block;
margin-bottom: 10px;
}
/* Specificity: 0004 */
div div li a {
color: yellow;
}
/* Specificity: 0113 */ /* Successful, but jank? */
#outer div ul .nav a {
background-color: initial;
}
============
<div id="outer" class="container">
<div id="inner" class="container">
<ul>
<li class="nav"><a href="#">One</a></li>
<li class="nav"><a href="#">Two</a></li>
</ul>
</div>
</div>
That third rule works because I’ve verbatim copied the first rule’s selector, and overridden it with my own further down in the CSS. This works, but I also tried to complete the exercise with more specific selectors, and those didn’t work.
Can someone explain why the following rules don’t target my text properly?
/* Intended specificity: 0213,
notice the extra #inner ID selector */
#outer #inner div ul .nav a {
background-color: initial;
}
/* Intended specificity: 0114,
notice the extra li element selector */
#outer div ul li .nav a {
background-color: initial;
}
You can plug these rules into the CSS section of the exercise to see that they don’t work. Why don’t these rules work?