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

前端 未结 14 934
猫巷女王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:53

    There is no one size fits-all approach, but one thing that I found particularly helpful is setting opacity for a div's direct children, except for the one that you want to keep fully visible. In code:

    and css:

    div.parent > div:not(.child1){
        opacity: 0.5;
    }
    

    In case you have background colors/images on the parent you fix color opacity with rgba and background-image by applying alpha filters

提交回复
热议问题