Doubts about CSS applying effect on one div without changing the other

Asked

Viewed 35 times

1

I have the following code.
The div Second is inside the div first
How to make the opacity property not affect the div Second

.first {
  width: 200px;
  height: 200px;
  background: red;
  opacity: 0.6;
}
.second{

  width: 50px;
  height: 50px;
  background: blue;
}
<div class="first">
  <div class="second">
  </div>
</div>

  • 1

    Hello! There is an answer available in another topic: https://answall.com/questions/3860/como-n%C3%A3o-apply-opacity-in-a-child element

1 answer

1

According to the comment of our friend @Getulio Rafael Ferreira who provided the link of a similar question. You can make use of background-color: rgba(250,0,0,0.6); that will bring the effect you want.

Link to similar response: How not to apply opacity to a child element?

.first {
  width: 200px;
  height: 200px;
  background: red;
  background-color: rgba(250,0,0,0.6);
}
.second{

  width: 50px;
  height: 50px;
  background: blue;
}
<div class="first">
  <div class="second">
  </div>
</div>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.