I need an HTML CSS code that will have 4 elements for example 4 rectangles, when I randomly select one of these four and move the mouse to it, I want all the others except my selected rectangle to become semi-transparent.
I want to do all this with only HTML CSS hover
I tried to use the :not() class with :hover but it didn’t work, I tried almost everything but still didn’t get the result, I also tried using chatGPT but it doesn’t do everything the way I want. I don’t even know if it’s possible to do this with CSS, but I’ve spent a lot of time on it and I don’t want to just throw it away.
2
Answers
Use parent div tag and concentrate you css for that tag and it children
But all children are modified everything will become transparent, so use the child selector
>
to re-do the css for that particular div which is currently focused by mouseFor semi-transparent div tag you can
rgba
background-color, Please adjust thergba
with your own color combinationFor demo I put red color border, you can remove it
Keep the css order to make it work
Example
I have Two Answers one is
CSS
only and The other one usesJS
.CSS
Note: CSS only solution has some drawbacks like if you hover on the whitspace between the boxes it also turns the boxes semi-transparent.