Create non-transparent div on top of transparent parent element

前端 未结 7 1815
渐次进展
渐次进展 2020-12-29 04:35

EDIT: Changed title to actually be correct

I\'m trying to simulate a modal popup in all HTML and CSS and am having a bit of bad luck w

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 05:23

    Setting the color of the parent div with opacity with a rgba-color would make more sense here, because in this case the child element wouldnt inherit the opacity and wont be transparent!

    so instead of using background-color: gray or #something, use something like this:

    .modalBackground {
      background-color: rgba(222, 222, 222, 0.7);
    }
    

    Like this the parent-element has an opacity of 0.7 but is does not inherit it to any div or image or whatever inside of this div!

    There are many rgba-generators out there on the net, try them.

    http://www.css3-generator.de/rgba.html

提交回复
热议问题