Can we create an element that is only visible above specific other elements?
For instance, in the following code snippet, I want the .reflection
element to be visible only above the .reflective
elements (located at the top and bottom) and not visible on the .non-reflective
element (which is placed in the center):
.bg
{
position: relative;
width: 300px;
height: 150px;
background-color: green;
}
.reflective
{
width: 100%;
background-image: url(https://sample.wdd.co.il/wp-content/uploads/sites/6/2024/01/mahogany-4.jpg);
height: 45px;
margin: 2.5px 0;
border: 1px solid gray;
border-radius: 15px;
box-shadow: inset 0 0 10px black;
}
.non-reflective
{
width: 100%;
background-color: transparent;
height: 50px;
border: 1px solid brown;
border-radius: 15px;
}
.reflection
{
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
width: 250px;
height: 150px;
border-radius: 100%;
background: linear-gradient(to bottom right, rgba(255,255,255,0.5) 0%,rgba(255,255,255,0) 100%);
}
<div class="bg">
<div class="reflective"></div>
<div class="non-reflective"></div>
<div class="reflective"></div>
<div class="reflection"></div>
</div>