I dont have much experiences in CSS, but recently i found out that there is a difference between having a whitespace before a class selector and without having one. So far, I only know that they are interpreted as two different things...Can somebody experienced in CSS explains to me what the particular difference is? Does this also apply to id selector?
Thanks. appreciate your answers.
#someid ul li.someclass a
means
Anchors that are descendants of
list items that have the classsomeclass
and are themselves descendants of
unordered lists that are descendants of
the element with IDsomeid
.
#someid ul li .someclass a
means
Anchors that are descendants of
any elements that have the classsomeclass
and are themselves descendants of
list items that are descendants of
unordered lists that are descendants of
the element with IDsomeid
.
So, the <a>
element in the following markup is matched by the first rule, but not by the second:
<div id="someid">
<ul>
<li class="someclass">
<a href="foo.html" />
</li>
</ul>
</div>
And the <a>
element in the following markup is matched by the second rule, but not by the first:
<div id="someid">
<ul>
<li>
<span class="someclass">
<a href="foo.html" />
</span>
</li>
</ul>
</div>
Two examples:
#someid ul li.someclass a
will hit the anchor tag in this example
<div id="someid">
<ul>
<li class="someclass">
<a href="http://www.example.com">link</a>
</li>
</ul>
</div>
#someid ul li .someclass a
will hit the anchor tag in this example
<div id="someid">
<ul>
<li>
<div class="someclass">
<a href="http://www.example.com">link</a>
</div>
</li>
</ul>
</div>
Also notice that this will hit both of them:
<div id="someid">
<ul>
<li class="someclass">
<div class="someclass">
<a href="http://www.example.com">link</a>
</div>
</li>
</ul>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With