So I wanted to build an infinite gallery with the following layout: Expected result (the first picture also gets a border)
As you can see, only the currently active picture is visible and the inactive pictures are only indicated by their borders and the container is translucent.
Now what makes this a bit tricky, is that the borders aren't a regular rectangle but shifted to a parallelogram. To achive this I've tried the following two approaches:
Skew
My first approach was to just use CSSs transform: skewX(deg);
Sadly skew doesn't only shift but also distortes the picture..
Clip Path
with the layout as following
<div class="wrapper">
<img></img>
</div>
Style:
.wrapper {
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
background: black;
}
img {
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
transform: scale(0.95);
}
I was able to spaghetti my way into a shifted border. Problem here is that when the picture isn't active anymore and should therefore be invisible, my fake border is exposed as the whole container will be black.
So I was wondering what would be the best way to shift the containers border and place the image inside so that it can be faded out and the background is translucent.
Heres a Code Snippet:
div[class*="wrapper"] {
height: 100px;
width: 200px;
margin: 1em;
}
img {
width: 100%;
height: 100%;
}
.wrapper-clippath {
background: black;
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
}
.wrapper-clippath img {
clip-path: polygon(25% 0%, 100% 0%, 75% 100%, 0% 100%);
transform: scale(0.985);
animation: opacity 1s infinite alternate;
}
.wrapper-skew {
transform: skewX(-25deg);
border: 1px solid black;
}
@keyframes opacity {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
<h1>With Skew</h1>
<p>Image gets distorted</p>
<div class="wrapper-skew">
<img src="https://www2.tuhh.de/zll/wp-content/uploads/placeholder.png">
</div>
<h1>With clippath</h1>
<p>Background is black and not translucent when image is faded out</p>
<div class="wrapper-clippath">
<img src="https://www2.tuhh.de/zll/wp-content/uploads/placeholder.png">
</div>