我在網(wǎng)上瀏覽,無意中在reddit上發(fā)現(xiàn)了這個(gè)主題
看到這個(gè)可愛的橫幅后。我想試著用我選擇的五張對(duì)稱的圖片來模擬這樣的東西,這些圖片用對(duì)角線分開,就像上面的圖片一樣。也許還可以嘗試在各種圖片上添加一些文字。大概是這樣的:
我試著用貓的圖片用css在線重寫類似的東西
.image-container {
width: 90%;
height: 200px;
position: relative;
margin: 30px auto;
background: black;
overflow: hidden;
}
.image-one {
right: 20%;
}
.image-two {
right: 20%;
}
.image-three {
right: 20%;
}
.image-four {
right: 20%;
}
.image-five {
right: 20%;
}
.image-one,
.image-two,
.image-three,
.image-four,
.image-five {
position: absolute;
height: 100%;
width: 40%;
min-width: 20px;
-ms-transform: skewX(-25deg);
-webkit-transform: skewX(-25deg);
transform: skewX(-25deg);
background: white;
overflow: hidden;
top:0;
margin-right: 50px;
border: 5px solid black;
border-top: 0;
border-bottom: 0;
box-shadow: 0 0 10px 0 rgba(0,0,0,0.9);
}
.image-one:after, .image-two:after,
.image-three:after, .image-four:after,
.image-five:after{
-ms-transform: skewX(25deg);
-webkit-transform: skewX(25deg);
transform: skewX(25deg);
position: absolute;
width: 120%;
height: 100%;
display: block;
top: 0;
content: "";
}
.image-one:after{
right: -93px;
background: url("http://lorempixel.com/500/400/cats") no-repeat center center;
background-size: cover;
}
.image-two:after {
left: -93px;
background: url("http://lorempixel.com/500/401/cats") no-repeat center center;
background-size: cover;
}
.image-three:after {
left: -93px;
background: url("http://lorempixel.com/500/401/cats") no-repeat center center;
background-size: cover;
}
.image-four:after {
left: -93px;
background: url("http://lorempixel.com/500/401/cats") no-repeat center center;
background-size: cover;
}
.image-five:after {
left: -93px;
background: url("http://lorempixel.com/500/401/cats") no-repeat center center;
background-size: cover;
}
然而,不是所有的貓圖片都在盒子里,也不是均勻分布的
<div class='image-container'>
<div class='image-left'></div>
<div class='image-right'></div>
</div>
<div class='image-container'>
<div class='image-one'></div>
<div class='image-two'></div>
<div class='image-three'></div>
<div class='image-four'></div>
<div class='image-five'></div>
</div>
不需要使用定位元素,您可以像這樣簡(jiǎn)化,并使用背景-位置使元素居中:
.container {
display: flex;
height: 150px;
margin: 0 30px;
}
.box {
flex: 1;
border: 1px solid;
transform: skew(-25deg);
position: relative;
overflow: hidden;
}
.box:after {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: -50%;
right: -50%;
transform: skew(25deg);
background-image: var(--i);
background-position: center;
}
<div class="container">
<div class="box" style="--i:url(https://picsum.photos/id/16/400/300)"></div>
<div class="box" style="--i:url(https://picsum.photos/id/18/400/300)"></div>
<div class="box" style="--i:url(https://picsum.photos/id/11/400/300)"></div>
<div class="box" style="--i:url(https://picsum.photos/id/35/400/300)"></div>
<div class="box" style="--i:url(https://picsum.photos/id/42/400/300)"></div>
</div>