I been stuck on this for a while but I cant figure out how to do this correctly.
My wanted result is to have two images side by side and a gap between them.
My problem is that when the browser resize it wont keep the gap and the images "merge" or extending the browser the gap gets bigger.
code:
.hs-media {
--hs-media-overlap: 7.5rem;
--hs-media-col-size: calc(var(--hs-media-overlap) / 2);
list-style: none;
display: grid;
gap: 1rem;
grid-template-columns: [one] auto [two-begins] minmax(0, var(--hs-media-col-size)) minmax(0, var(--hs-media-col-size)) [one-ends] auto [two];
}
[class*="hs-media__col-"] {
grid-row: 1;
position: relative;
display: flex;
min-block-size: 100%;
}
.hs-media__col-1 {
grid-column: one/one-ends;
clip-path: polygon(0% 0%, 100% 0%, 85% 100%, 0% 100%);
}
.hs-media__col-1::before {
content: '';
position: absolute;
inset-block-start: 0;
inset-inline-start: 0;
block-size: 100%;
inline-size: 100%;
background: rgba(51, 153, 68, 0.79);
mix-blend-mode: multiply;
}
.hs-media__line {
grid-column: one/line;
grid-row: 1;
block-size: 100%;
background-color: white;
clip-path: polygon(0% 0%, 100% 0%, 85% 100%, 0% 100%);
}
.hs-media__col-2 {
grid-column: two-begins/two;
clip-path: polygon(15% 0, 100% 0%, 100% 100%, 0% 100%);
}
.hs-media__image {
inline-size: 100%;
object-fit: cover;
}
<ul class="hs-media">
<li class="hs-media__col-1">
<img src="https://source.unsplash.com/Ul-Cp7f_CGQ/1440x546" class="hs-media__image" />
</li>
<li class="hs-media__col-2">
<img src="https://source.unsplash.com/t8QeaJkxp4M/1800x546" class="hs-media__image" />
</li>
</ul>
2
Answers
To me it looks like you are complicating it too much, is this ok for you ?
diagonal slash will always take 1% of total width
I have a detailed article about such layouts where you can also have hover effect: https://css-tricks.com/css-grid-and-custom-shapes-part-2/