There is a container in which there is a flex container.
HTML
<div class="container">
<div class="content">
<div class="over">Over</div>
<div>Test</div>
<div>Test</div>
<div>Test</div>
</div>
</div>
CSS
.container {
background-color: yellow;
width: 500px;
}
.content {
display: flex;
}
.over {
background-color: rgba(255, 0, 0, 0.8);
}
Now it looks like this:
Can the over div somehow be placed over all other divs, and the width of the content should be?
You can use the CSS position property in combination with the z-index property to overlay an individual div over another div element. The z-index property determines the stacking order for positioned elements (i.e. elements whose position value is one of absolute , fixed , or relative ).
Use the CSS z-index property. Elements with a greater z-index value are positioned in front of elements with smaller z-index values. Note that for this to work, you also need to set a position style ( position:absolute , position:relative , or position:fixed ) on both/all of the elements you want to order.
Flex items within a flex container can be laid out either horizontally or vertically, but not both. If you want to lay out items in both dimensions, you'll need to nest a flex container inside another one. In this example we apply display: flex to both the outer container and to the red flex item.
You can make the element position:absolute
and stretch it to take the full width of .content
. You may also use inline-flex
so that the width of .content
is equal to the width of its content:
.container {
background-color: yellow;
width: 500px;
}
.content {
display: inline-flex;
position:relative;
}
.over {
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background-color: rgba(255, 0, 0, 0.8);
}
<div class="container">
<div class="content">
<div class="over">Over</div>
<div>Test</div>
<div>Test</div>
<div>Test</div>
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With