【问题标题】:How can I skew one side of a div and then replicate it and skew a different side?如何倾斜 div 的一侧,然后复制它并倾斜另一侧?
【发布时间】:2014-08-19 15:55:50
【问题描述】:

假设我有一个 div:

div {
    height: 100px; 
    width: 500px; 
    background: blue; 
    margin: 0 auto; 
} 

而且我希望它变成两种模式 - skew 到每一边 -

这是基本形式 - http://jsfiddle.net/urielz/neybabgj/

我怎样才能得到以上两种形式?

更新:

如果需要使用 JavaScript - 请执行此操作。

【问题讨论】:

标签: javascript html css skew


【解决方案1】:

JSiddle Demo

CSS

div {
    height : 100px;
    width : 500px;
    background : blue;
    margin : 10px auto;
    position: relative;
}
div:first-child:before {
    position: absolute;
    top:0;
    right:100%;
    width:0;
    height:0;
    content:'';
    border:50px solid blue;
    border-top-color:transparent;
    border-left-color:transparent;
}

div:nth-child(2):after {
    position: absolute;
    top:0;
    left:100%;
    width:0;
    height:0;
    content:'';
    border:50px solid blue;
    border-bottom-color:transparent;
    border-right-color:transparent;
}

【讨论】:

    【解决方案2】:

    HTML

    <div class="crop">
        <div class="skew"></div>
    </div>
    

    CSS

    .crop {
        width: 492px;
        height: 240px;
        overflow: hidden;
    }
    .skew {
        display: block;
        height : 100px;
        width : 500px;
        background : blue;
        margin : 0 auto 0 32px;
        position:relative;
        -webkit-transform: skew(-30deg);
        -moz-transform: skew(-30deg);
        -ms-transform: skew(-30deg);
        transform: skew(-30deg);
    }
    .skew:after {
        height : 100px;
        width : 500px;
        background : blue;
        margin : 0 auto;
        position:absolute;
        bottom: -120px;
        content:'';
    }
    

    小提琴:http://jsfiddle.net/neybabgj/7/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-02
      • 1970-01-01
      • 2017-04-09
      • 2014-11-22
      • 2016-12-23
      • 2016-12-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多