My goal is to create a vertically tiled background by clipping the top 50px of a background image and using only that portion. However, the code I have below isn't working as expected. Even though I've given a higher z-index to the
<div class="content">
, it's also being clipped. Additionally, the clipped part of the image isn't repeating.
I did manage to get the desired result by removing comments in the code (like here: https://jsfiddle.net/jamacoe/1ej3k80o/3/), but that involved duplicating the
<div class="clipped">
container. Is there a way to achieve this with just a single <div class="clipped">
container with a height of 100%? Any insights or alternative approaches are much appreciated. Thank you!
.outer {
border: 1px solid red;
height: 150px;
overflow: hidden;
position: strict;
}
.clipped {
background-image: url("https://source.unsplash.com/featured/?nature");
clip-path: inset(1 0 calc(100% - 51px) 0);
background-repeat: repeat-y;
height: 50px;
z-index: -1;
}
.content {
position: absolute;
top: 0;
z-index: 1;
}
p {
color: white;
background-color: rgba(255, 255, 255, 0.25);
}
<div class=outer>
<div class=clipped></div>
<!-- div class=clipped></div>
<div class=clipped></div -->
<div class=content>
<p>content 1</p>
<p>content 2</p>
<p>content 3</p>
<p>content 4</p>
</div>
</div>