I have many elements with the same class on a web page. I would like to highlight all these elements when I hover one of them. How can I do that in CSS?
Right now, I have this CSS:
p.un:hover { background-color:yellow;}
And my HTML:
<div class="book">
<div class="page left">
<p class="un">Karen…</p>
</div>
<div class="page right">
<p class="un">Karen ne se retourne pas. Mme Tilford reste là, apparemment confuse et abattue.</p>
</div>
The best you can do using pure CSS is this:
But this only highlights all siblings with a class
classnameafter the hovered element.You have to use JavaScript to highlight all elements;
If you have multiple classes and want to generalize this, use something like this: