This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
Just like with :is()
and :not()
, the specificity of :has()
is replaced by the specificity of the most specific selector in its selector list argument. Unlike :nth-child()
or :link
, :has()
itself doesn't add to the specificity.
<div class="parent">
<p class="child">yo!</p>
</div>
/* A tag and a class */
div:has(.child) {
background: red;
}
/* A tag: specificty too low */
div {
background: blue;
}
/* A class: specificty too low */
.parent {
background: green;
}
/* A tag and a class: same specificty as div:has(.child) */
div.parent {
background: orange;
}
yo!
This content originally appeared on Manuel Matuzović - Web development blog and was authored by Manuel Matuzović
Manuel Matuzović | Sciencx (2022-10-17T09:38:54+00:00) Day 16: the specificity of :has(). Retrieved from https://www.scien.cx/2022/10/17/day-16-the-specificity-of-has/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.