It is easy to highlight a div
when mouse hovers on it.
However, when div
s are inside each other, the parent shades over the rest of the div
s. How should I tell CSS to hover only on the directly hovered div
?
When I hover over parrot
, I don't want bird
or animal
to be highlighted.
div.creature{
margin:5px;
padding:5px;
border: 1px solid;
}
div.creature:hover{
background: #ffeeaa;
}
<div class="creature">
animal
<div class="creature">
mammal
<div class="creature">
cat
</div>
</div>
<div class="creature">
bird
<div class="creature">
parrot
</div>
<div class="creature">
duck
</div>
</div>
</div>
UPDATE
The HTML code is created dynamically. Hence, an independent CSS is preferred.
When I hover on bird
but not on parrot
or duck
, I expect the entire bird
highlights.