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

前端 未结 14 903
猫巷女王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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 06:53

    If you have to use an image as the transparent background, you might be able to work around it using a pseudo element:

    html

    I have 100% opacity

    css

    .wrap, .wrap > * {
      position: relative;
    }
    .wrap:before {
      content: " ";
      opacity: 0.2;
      background: url("http://placehold.it/100x100/FF0000") repeat;     
      position: absolute;
      width: 100%;
      height: 100%;
    }
    

提交回复
热议问题