用对角线分割的两个div - CSS

时间:2015-07-09 08:58:39

标签: css slider css-shapes diagonal

我试图让两个div适合页面的整个宽度,但是用对角线分成两半。

example of what i want it to look like

如何通过CSS实现两个div?这是一个滑块,完成后需要添加到每个部分的内容

1 个答案:

答案 0 :(得分:11)

可能是这样的

示例1

div {
    min-height: 100px;
    background: #D25A1E;
    position: relative;
    width: calc(50% - 30px);
}
.div1 {
    float: left;
}
.div2 {
    float: right;
}
.div1:after, .div2:before {
    content:'';
    position: absolute;
    top: 0;
    width: 0;
    height: 0;
}
.div1:after {
    left: 100%;
    border-top: 100px solid #D25A1E;
    border-right: 50px solid transparent;
}
.div2:before {
    right: 100%;
    border-bottom: 100px solid #D25A1E;
    border-left: 50px solid transparent;
}
<div class="div1"></div>
<div class="div2"></div>

fiddle

示例2

div {  
    background: #D25A1E;
    min-height: 100px;
    width: calc(50% - 25px);
    position: relative;     
}
.div1 {
    float: left;
}
.div2 {
    float: right;
}
div:after {
    position: absolute; top: 0px;
    content:'';    
    z-index: -1;
    height: 100%;
    width: 50%;
    background: #D25A1E;
}
.div1:after {    
    right: 0;
    transform-origin: bottom right;
    transform: skewX(-20deg);
}
.div2:after {    
    left: 0;
    transform-origin: top left;
    transform: skewX(-20deg);
}
<div class="div1"></div>
<div class="div2"></div>

fiddle