CSS Selector Specificity

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Hi! could you look at this code and help me understand, because from what I gathered it goes against the rules you said on your video:

<html>
<style>
#first div {color: blue;} /*R1*/
p + p + div :first-child {color: red;} /*R2*/
</style>
<div class="post" id="first">
<div class="header">
<h1>Title</h1>
</div>
<p>First paragraph</p>
<p>Second paragraph</p>
<div class="footer">
<p>This is a footer</p>
</div>
</div>
</html>

R1 has a specify of 101; and R2 of 13. This creates a conflict with the color in line 13. Since R1 has the biggest specify for the same thing i figured the color would be blue, but when I tested on a browser it was red. How did that happen? Is it because R1 is inherited and R2 is not?

onlyonetwin
Автор

Thanks sir for your awesome presentation

tayebhimel
Автор

Thanks for bringing out the confusion related selector priority

userinterface