I do not want to inherit the child opacity from the parent in CSS

前端 未结 14 921
猫巷女王i
猫巷女王i 2020-11-21 06:31

I do not want to inherit the child opacity from the parent in CSS.

I have one div which is the parent, and I have another div inside the first div which is the child

14条回答
  •  忘了有多久
    2020-11-21 06:44

    The question didn't defined if the background is a color or an image but since @Blowski have already answered for coloured backgrounds, there's a hack for images below:

    background: linear-gradient(rgba(0,0,0,.6), rgba(0,0,0,.6)), url('image.jpg');
    

    This way you can manipulate the color of your opacity and even add nice gradient effects.

    .wrapper {
      width: 630px;
      height: 420px;
      display: table;
      background: linear-gradient(
        rgba(0,0,0,.8), 
        rgba(0,0,0,.8)), 
        url('http://cdn.moviestillsdb.com/sm/35bc3c6a2b791425de6caf8b9391026e/rambo-iii.jpg');
     }
    
    h1 {
      display: table-cell;
      vertical-align: middle;
      text-align: center;
      color: #fff;
      }

    Question 5770341

提交回复
热议问题