How when I hover on the <li>
I can select my <a>
element ?
a ul:hover {
color: red;
}
<a href="#">Link</a>
<ul>
<li>Element 1</li>
<li>Element 2</li>
</ul>
How when I hover on the <li>
I can select my <a>
element ?
a ul:hover {
color: red;
}
<a href="#">Link</a>
<ul>
<li>Element 1</li>
<li>Element 2</li>
</ul>
2
Answers
For those browsers which support :has you can use:
However, check on caniuse.com that there is enough support for your use case – Edge/Chrome/Safari support it but Firefox requires a flag to be set.
You can do this using
:has
like this: