Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS. Change color of inner element which already has color on hover outer element

Tags:

css

For example I have:

<style>
.a:hover {
  color: white;
}
.a {
  color: blue;
}
.b {
  color: red;
}
</style>
<div class="a">
  <div>First</div>
  <div class="b">Second</div>
</div>

How do I make both inner divs go color: white while i want them to be different color not on hover? Cant figure it out. It just wont change color of second one, no matter what I try.

They both at the same time should become white, not line by line.

like image 379
Dancia Avatar asked Jan 19 '26 11:01

Dancia


1 Answers

You can use this:

.a:hover .b, .a:hover div {
    color: white;
}
.a {
    color: blue;
}
.b {
    color: red;
}
<div class="a">
    <div>First</div>
    <div class="b">Second</div>
</div>

or

.a:hover div{
    color: white;
}
.a {
    color: blue;
}
.b {
    color: red;
}
<div class="a">
    <div>First</div>
    <div class="b">Second</div>
</div>
like image 81
Alex Char Avatar answered Jan 22 '26 02:01

Alex Char