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

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

    As others have mentioned in this and other similar threads, the best way to avoid this problem is to use RGBA/HSLA or else use a transparent PNG.

    But, if you want a ridiculous solution, similar to the one linked in another answer in this thread (which is also my website), here's a brand new script I wrote that fixes this problem automatically, called thatsNotYoChild.js:

    http://www.impressivewebs.com/fixing-parent-child-opacity/

    Basically it uses JavaScript to remove all children from the parent div, then reposition the child elements back to where they should be without actually being children of that element anymore.

    To me, this should be a last resort, but I thought it would be fun to write something that did this, if anyone wants to do this.

提交回复
热议问题