如何使用 CSS 倾斜图像?
How to skew image with CSS?
我想像这样扭曲图像
申请的时候有效div
现在我想将此代码用于 img
标记,但它不起作用。
这是我的实时代码:
https://jsfiddle.net/dbkvdq3u/5/
.steps-widget .step-img-box {
position: relative;
text-align: center;
padding: 12px;
margin-bottom: 6px;
height: 60px;
}
.steps-widget .step-img-box:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 51%;
z-index: -1;
-webkit-transform: skew(0deg, 6deg);
-moz-transform: skew(0deg, 6deg);
-ms-transform: skew(0deg, 6deg);
-o-transform: skew(0deg, 6deg);
transform: skew(0deg, 6deg);
}
.steps-widget .step-img-box:after {
z-index: -1;
content: '';
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 50%;
-webkit-transform: skew(0deg, -6deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, -6deg);
}
<div class="step-img-box">
<img class="img-responsive" src="http://i.imgur.com/E7atspO.jpg" alt="Image">
</div>
<!-- end step-img-box -->
您可以使用伪元素,使用背景位置 属性 对齐图像的两个 'halfs':
div {
height: 300px;
width: 300px;
position: relative;
margin: 100px auto;
}
div:before,
div:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 50%;
background-size: 300px 300px;
}
div:before {
transform: skewY(10deg);
}
div:after {
left: 50%;
background-position: -100% 0;
transform: skewY(-10deg);
}
.sk:before, .sk:after{ background-image: url(http://lorempixel.com/300/300);}
.sk2:before, .sk2:after{ background-image: url(http://lorempixel.com/400/400);}
<div class="sk"></div>
<div class="sk2"></div>
我想像这样扭曲图像
申请的时候有效div
现在我想将此代码用于 img
标记,但它不起作用。
这是我的实时代码:
https://jsfiddle.net/dbkvdq3u/5/
.steps-widget .step-img-box {
position: relative;
text-align: center;
padding: 12px;
margin-bottom: 6px;
height: 60px;
}
.steps-widget .step-img-box:before {
content: '';
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 51%;
z-index: -1;
-webkit-transform: skew(0deg, 6deg);
-moz-transform: skew(0deg, 6deg);
-ms-transform: skew(0deg, 6deg);
-o-transform: skew(0deg, 6deg);
transform: skew(0deg, 6deg);
}
.steps-widget .step-img-box:after {
z-index: -1;
content: '';
position: absolute;
top: 0;
right: 0;
height: 100%;
width: 50%;
-webkit-transform: skew(0deg, -6deg);
-moz-transform: skew(0deg, -6deg);
-ms-transform: skew(0deg, -6deg);
-o-transform: skew(0deg, -6deg);
transform: skew(0deg, -6deg);
}
<div class="step-img-box">
<img class="img-responsive" src="http://i.imgur.com/E7atspO.jpg" alt="Image">
</div>
<!-- end step-img-box -->
您可以使用伪元素,使用背景位置 属性 对齐图像的两个 'halfs':
div {
height: 300px;
width: 300px;
position: relative;
margin: 100px auto;
}
div:before,
div:after {
content: "";
position: absolute;
top: 0;
left: 0;
height: 100%;
width: 50%;
background-size: 300px 300px;
}
div:before {
transform: skewY(10deg);
}
div:after {
left: 50%;
background-position: -100% 0;
transform: skewY(-10deg);
}
.sk:before, .sk:after{ background-image: url(http://lorempixel.com/300/300);}
.sk2:before, .sk2:after{ background-image: url(http://lorempixel.com/400/400);}
<div class="sk"></div>
<div class="sk2"></div>