最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I skew one side of a div and then replicate it and skew a different side? - Stack Overflow

programmeradmin1浏览0评论

Suppose I have a div:

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

And I want it to bee two mode - skew to each side -

Here is the base form - /

How could I get the above two forms?

Update :

If it required using JavaScript - do it.

Suppose I have a div:

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

And I want it to bee two mode - skew to each side -

Here is the base form - http://jsfiddle/urielz/neybabgj/

How could I get the above two forms?

Update :

If it required using JavaScript - do it.

Share Improve this question edited Aug 19, 2014 at 16:00 TylerH 21.1k79 gold badges79 silver badges114 bronze badges asked Aug 19, 2014 at 15:55 URL87URL87 11k36 gold badges111 silver badges177 bronze badges 7
  • You can't make two divs out of one without using JavaScript or some other dynamic language. You need to pick one or the other, or add another div. – TylerH Commented Aug 19, 2014 at 15:57
  • It's not clear what you are trying to do. – Paulie_D Commented Aug 19, 2014 at 15:58
  • @Paulie_D : what is not clear ? just get the div as the two attached forms ... – URL87 Commented Aug 19, 2014 at 16:00
  • 1 This is a hammer to crack a nut! However you might want to do it like so: stackoverflow./questions/22069704/skew-one-corner-of-image. But I'd stick with triangles: stackoverflow./questions/16748387/… – Hashem Qolami Commented Aug 19, 2014 at 16:03
  • @TylerH not pletely true. You can create new block elements by using :before and :after pseudo-classes – o--oOoOoO--o Commented Aug 19, 2014 at 16:03
 |  Show 2 more ments

2 Answers 2

Reset to default 4

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

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:'';
}

Fiddle: http://jsfiddle/neybabgj/7/

发布评论

评论列表(0)

  1. 暂无评论