Skip to content
Advertisement

Selective hover background change on nested divs

I’m working on the following files:

JavaScript
JavaScript

The result I want to achieve is that when I hover a certain div, its background changes to a #ccc grey color.

However what adds some difficulty is that I want only the area that belongs only to the innermost hovered div to change background color, not the child or parent.

Here is a picture to show the behavior I want for example when hovering the second div:

enter image description here

EDIT: I ALSO WANT THE BACKGROUND COLOR TO BE RESET TO WHITE WHEN THE MOUSE IS OUTSIDE AN AREA

EDIT 2: IS THIS DOABLE WITH ONLY CSS OR IS JAVASCRIPT MANDATORY?

Advertisement

Answer

Some magic using pseudo element and box-shadow:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement