if child elemnt is hovered do changes to the container css

Solutions on MaxInterview for if child elemnt is hovered do changes to the container css by the best coders in the world

showing results for - "if child elemnt is hovered do changes to the container css"
Camilla
04 Jun 2017
1CSS can not select a parent div only when a specific child or descendent element is hovered.  You'll need some JavaScript to achieve what you seem to want.
2
3JavaScript can be added to add something like a "hovered" class to your parent element when various mouse or touch events happen on the child div.  You could edit the CSS properties directly in JavaScript but I would use a CSS class just to keep more of the CSS concerns separate.
4
5
6
7The :hover is closely related to your question but it doesn't solve your requirements.  :hover lets you select elements that are hovered over.  If the child is hovered, the parent is also hovered.  There is a problem though.
8Here is an example of the problem with :hover:
9HTML:
10<div class="my-parent">
11   <button id="ok">OK</button>
12   <button id="cancel">Cancel</button>
13</div>
14
15CSS:
16.my-parent:hover {
17   background-color: green;
18}
19Say you want the background of my-parent to go red when hovering over "OK".  The above example will do that.  The problem is it'll go green when hovering over the Cancel button too.