I’m trying to use CSS to make the text "Permits Required" and the ::before pseudo-class turn red – the ::before contains an icon.
.knHeader__menu-list-item:hover::before {
color: #aa0003 !important;
}
.knHeader__menu-list-item:hover {
color: #aa0003 !important;
}
<li class="knHeader__menu-list-item">
::before
<a href="#permits-required" class="knHeader__menu-link knHeader__menu-link--text">
<!---->
Permits Required
<!---->
</a>
</li>
This makes only the icon turn red not the "Permits Required". I need both to turn red, at the same time when either of them are hovered over.
3
Answers
You just need to use
color: inherit;
sample code
Try the above.
When you hover over
.knHeader__menu-list-item
you are changing the ::before and the item itself. However its childa
is still given the browsers default link styling. We can tell thea
to inherit the colour from its parent:Here’s your demo snippet updated to do just that: