Reputation: 881
I know that opacity
creates a new stacking context as demonstrated in this post by Philip Walton.
In following code, setting opacity: .8
of 2nd child div is lower than the opacity: .9
of 1st child wrapper
still 2nd child appears above 1st child div. Why?
HTML
<div id="wrapper">
<div class="block top">
Lorem ipsum dolor immet. Lorem ipsum dolor immet. Lorem ipsum dolor immet. Lorem ipsum dolor immet. Lorem ipsum dolor immet. Lorem ipsum dolor immet.
</div>
<p class="block bottom">In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. In-flow para. </p>
</div><!-- END HTML -->
</body>
CSS
.block{
width: 200px; padding: 10px;
border: 2px solid;
background-color: yellow }
.top {
margin-bottom: -70px;
opacity: .9 }
.bottom {
opacity: .8;
background-color: red;
margin: 0 }
https://jsfiddle.net/fy9sznjp/1/
Can someone tell me as to why lower opacity
child stack over higher opacity
div.
Upvotes: 0
Views: 48
Reputation: 40862
Both elements have an opacity
property that is different to 1
, so bottom
is displayed over top
, the value of opacity
, does not determine in which order they are drawn. It just matters if opacity
is different to 1
.
Upvotes: 2