Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing the child div's font colors on parent hover

Tags:

html

css

I have a question and I am not sure if it is possible, but I thought I would try asking.

Say I had three div's:

<div id="parent_div">

   <div id="child_div_1">Blue</div>

   <div id="child_div_2">Red</div>

</div>

If all text inside parent_div is set to black, how would I make the child_div_1 and child_div_2 change font-color to blue and red respectively, when the parent div is hovered over?

Sorry if this is a bit confusing, but is there a way to do this preferably with CSS only?

like image 449
Al Hennessey Avatar asked Sep 27 '12 19:09

Al Hennessey


People also ask

How do you style the parent element when hovering a child element?

The trick is to give the sibling the same size and position as the parent and to style the sibling instead of the parent. This will look like the parent is styled!

How do I change the color of my child element in CSS?

I ended up doing this: div[class*="et_pb_tab_"] td:hover span{ color: #fff ! important; } thanks!


1 Answers

#parent_div:hover #child_div_1 {
   color: blue;
}
#parent_div:hover #child_div_2 {
   color: red;
}
like image 147
Denys Séguret Avatar answered Oct 07 '22 00:10

Denys Séguret