Please consider this HTML+CSS:
#testArea {
box-sizing: border-box;
width: 300px;
height: 300px;
background-color: blue;
padding: 20px;
color: white;
font-weight: bold;
font-size: 18px;
}
#testArea:hover {
-webkit-filter: brightness(50%);
}
#absElement {
position: absolute;
left: 100px;
top: 100px;
width: 100px;
height: 100px;
background-color: green;
}
<div id="absElement"></div>
<div id="testArea">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</div>
If you mouse over the blue area, the :hover
CSS style kicks in and 50% brightness filter is applied. And somehow, the absolutely positioned green absElement
disappears. I was expecting that the rendering of the testArea
element itself would be altered, but it appears that a kind of overlay element is dynamically rendered just over the host element instead.
If I add z-index: 1
to the #absElement
style definition, the behavior is then according to what I was expecting. Another way to "fix" it, is by moving the absElement
div after the testArea
div. But it's strange that I should do so, because the absolutely positioned elements always should be rendered over the flow-layout elements.
What's going on here? I know I can add that z-index
property and just move on, but I'd like to understand how the filter effect is applied/rendered.