相邻的div有边角?

时间:2012-05-12 23:57:21

标签: html css html5 css-shapes

我想创建两个相互浮动的div,但是有一个倾斜的角度边界将它们分开。我附上了一张照片来证明我的意思。

有没有人知道CSS是否可以使用这样的东西(用溢出来切断内容:我想是隐藏的)

adjacent div with slanted side

这些div需要包含被边框切断的图像,这是一个例子:

divs with images and slanted adjacent sides

3 个答案:

答案 0 :(得分:28)

试试这个



.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;
}

<div class="left"> </div>
<div class="right"> </div>
&#13;
&#13;
&#13;


带图片的

更新

&#13;
&#13;
.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;
}
&#13;
<div class="left"> </div>
<div class="right"> </div>
&#13;
&#13;
&#13;

答案 1 :(得分:14)

到目前为止,所有解决方案都依赖于一个非常厚的角度边框来分割照片。

为避免这种情况,你要制作一个容器并使其倾斜。然后计数器以相反的方向扭曲图像。

这是CodePen http://cdpn.io/azvsA,但其要点如下:

.container {
  border-right: 10px solid white;
  overflow: hidden;
  transform (skewX(-20deg));
}

.image {
  transform (skewX(20deg));
}

答案 2 :(得分:4)

您可以这样写:

.left, .right {
    background: #000 url('http://lorempixel.com/300/100');
    position: relative;
    height: 100px;
    width: 250px;
    float: left;
}
.left{
    z-index:1;
}
.parent{
    overflow:hidden;
}

.right {
    background: #000 url('http://lorempixel.com/200/100');
    width: 150px;
}
.left:after{
    content:'';
    position:absolute;
    border-right:20px solid #fff;
    top:-25px;
    bottom:-10px;
    left:0;
    right:-10px;
    -moz-transform:rotate(10deg);
    -webkit-transform:rotate(10deg);
}

选中此http://jsfiddle.net/EJxFg/4/