0

I'm trying to darken on hover a parent div element which has a paragraph tag inside(this is child element). The

element is affected by darkening of the parent when hovered and the color of the font goes darker as well which is not what I want to achieve (color of the

element should be bright as default).

.parent {
  background-color: lightgrey
}

.parent:hover {
  filter: brightness(50%); //this affects also child element
}
<div class="parent">
  <p class="children">Paragraph</p>
</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Murakami
  • 3,474
  • 7
  • 35
  • 89

1 Answers1

1

To affect only the child you can do something like this:

.parent, .children {
  background:white;
} 
.parent:hover {
  background: black; //this affects the parent and the child
}
.parent:hover .children {
  background: white; //this affects only child
}

So what you are doing is overriding the children hover, so it is like you are excluding the child. So what happens is that both are white, you hover over parent, they both become black, but immediately get overridden by .parent:hover .children so children stay white.

Constantin Chirila
  • 1,979
  • 2
  • 19
  • 33