我正在尝试倾斜具有边框的一侧的背景图像。
我基本上想创建的布局如下:
这是我用当前设置制作的快速JSFiddle:
https://jsfiddle.net/silvawebdesigns/b2ae0k69/11/
#about-gallery {
margin: 60px 0;
display: -ms-flex;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
margin-bottom: 500px;
width: 100%;
}
.about-img-wrapper {
position: relative;
width: 100%;
display: -ms-flex;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
margin: 5px;
}
#about-gallery .about-bg {
border: solid 10px black;
float: left;
width: 100%;
height: 300px;
background-size: cover;
background-position: center;
}
#about-gallery .image-1 {
width: -moz-calc(55% - 10px);
width: -webkit-calc(55% - 10px);
width: calc(55% - 10px);
}
#about-gallery .image-2 {
width: -moz-calc(45% - 10px);
width: -webkit-calc(45% - 10px);
width: calc(45% - 10px);
}
#about-gallery .image-4,
#about-gallery .image-5 {
width: -moz-calc(50% - 10px);
width: -webkit-calc(50% - 10px);
width: calc(50% - 10px);
}
<div id="about-gallery">
<div class="about-img-wrapper img-about image-1">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
<div class="about-img-wrapper img-about image-2">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
<div class="about-img-wrapper img-about image-3">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
<div class="about-img-wrapper img-about image-4">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
<div class="about-img-wrapper img-about image-5">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
</div>
我已经尝试使用正负偏斜的组合来实现这一目标,
-webkit-transform: skew(20deg);
-moz-transform: skew(20deg);
-o-transform: skew(20deg);
但是似乎无法获得所需的布局,有可能吗?
诀窍是正确设置transform-orgin,border,然后应该容易地应用两个偏斜变换。您可能还需要一些负边距来纠正一些空格
#about-gallery {
margin: 60px 0;
margin-bottom: 500px;
display: flex;
flex-wrap: wrap;
}
.about-img-wrapper {
position: relative;
margin: 5px;
width: 100%;
overflow: hidden;
flex-grow:1;
}
.about-bg {
height: 300px;
background-size: 0 0;
background-position: center;
overflow: hidden; /* Don't forget this !!*/
}
/* The pseudo element will get the image and the inverse of skewing */
.about-bg::before {
content:"";
display:block;
width:100%;
height:100%;
background:inherit;
background-size:cover;
}
/**/
.image-1 {
border-left: solid 10px black;
flex-basis:50%;
margin-right:-10px;
}
.image-1>* {
transform: skewX(-8deg);
transform-origin: top;
border: solid 10px black;
border-left: none;
}
.image-1>*:before {
transform: skewX(8deg);
transform-origin: top;
}
/**/
.image-2 {
border-right: solid 10px black;
flex-basis:40%;
margin-left:-10px;
}
.image-2>* {
transform: skewX(-8deg);
transform-origin: bottom;
border: solid 10px black;
border-right: none;
}
.image-2>*:before {
transform: skewX(8deg);
transform-origin: bottom;
}
/**/
.image-3 {
border-top: solid 10px black;
}
.image-3>* {
transform: skewY(-8deg);
transform-origin: left;
border: solid 10px black;
border-top: none;
}
.image-3>*:before {
transform: skewY(8deg);
transform-origin: left;
}
/**/
.image-4 {
border-bottom: solid 10px black;
flex-basis:40%;
margin-top:-5vw;
}
.image-4>* {
transform: skewY(-8deg);
transform-origin: right;
border: solid 10px black;
border-bottom: none;
}
.image-4>*:before {
transform: skewY(8deg);
transform-origin: right;
}
/**/
.image-5 {
border-bottom: solid 10px black;
flex-basis:40%;
margin-top:-12vw;
}
.image-5>* {
transform: skewY(-8deg);
transform-origin: right;
border: solid 10px black;
border-bottom: none;
height:calc(100% + 12vw);
}
.image-5>*:before {
transform: skewY(8deg);
transform-origin: right;
}
* {
box-sizing: border-box;
}
<div id="about-gallery">
<div class="about-img-wrapper img-about image-1">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
<div class="about-img-wrapper img-about image-2">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
<div class="about-img-wrapper img-about image-3">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
<div class="about-img-wrapper img-about image-4">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
<div class="about-img-wrapper img-about image-5">
<div class="about-bg" style="background-image: url(https://via.placeholder.com/1140x400.png?text=SKEW+THIS+IMAGE+ON+ONE+SIDE);"></div>
</div>
</div>