Mar*_*ark 16 html css html5 css-shapes
我想创建两个相互浮动的div,但是有一个倾斜的角度边界将它们分开.我附上了一张照片来证明我的意思.
有没有人知道CSS是否可以这样做(切断内容溢出:隐藏我猜)
这些div需要包含被边框切断的图像,这是一个例子:
Zol*_*oth 30
试试这个
.left, .right {
position: relative;
height: 100px;
width: 200px;
background: #000;
float: left;
}
.left:after {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-top: 100px solid #000;
border-bottom: 50px solid transparent;
border-left: 0px solid transparent;
border-right: 50px solid transparent;
position: absolute;
top: 0;
right: -50px;
}
.right {
margin-left: 60px;
width: 100px;
}
.right:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 100px solid #000;
border-left: 50px solid transparent;
border-right: 0px solid #000;
position: absolute;
top: -50px;
left: -50px;
}
Run Code Online (Sandbox Code Playgroud)
<div class="left"> </div>
<div class="right"> </div>
Run Code Online (Sandbox Code Playgroud)
更新图像
.left, .right {
background: #000 url('http://lorempixel.com/300/100');
position: relative;
height: 100px;
width: 250px;
float: left;
}
.left:after {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 100px solid #fff;
border-left: 30px solid transparent;
border-right: 0 solid #fff;
position: absolute;
top: -50px;
right: 0;
}
.right {
background: #000 url('http://lorempixel.com/200/100');
width: 150px;
}
.right:before {
content: '';
line-height: 0;
font-size: 0;
width: 0;
height: 0;
border-top: 100px solid #fff;
border-bottom: 50px solid transparent;
border-left: 0px solid transparent;
border-right: 30px solid transparent;
position: absolute;
top: 0;
left: 0;
}
Run Code Online (Sandbox Code Playgroud)
<div class="left"> </div>
<div class="right"> </div>
Run Code Online (Sandbox Code Playgroud)
小智 15
到目前为止,所有的解决方案都依赖于一个非常厚的角度边框来分割照片.
为了避免这种情况,你需要制作一个容器并使其倾斜.然后反向偏移图像的方向相反.
这是一个CodePen http://cdpn.io/azvsA,但它的要点如下:
.container {
border-right: 10px solid white;
overflow: hidden;
transform (skewX(-20deg));
}
.image {
transform (skewX(20deg));
}
Run Code Online (Sandbox Code Playgroud)