任何人都知道如何创建一个角落切掉的CSS矩形?

时间:2013-07-12 16:40:17

标签: css css3

有谁知道如何创建如下所示的css多边形:

enter image description here

3 个答案:

答案 0 :(得分:1)

我制作了一个可能有用的jsfiddle。我从这个改编了它:http://jsfiddle.net/76EUw/2/

无论如何,这就是我的所作所为:

.corner {
    width: calc(300px - 20px); /*300 is the width, 20 is the size of the 'cut'*/
    height: 0px;
    /*change the top/left depending on which corner you want to use*/
    border-top: 20px solid red; /*I made this red just so it was easier to see*/
    border-right: 20px solid white; /*not sure what you will do if this is not on a white background.*/
}
.main {
    width: 300px;
    height: 100px;
    background-color: black;
    color:white;
    text-align:center;
}

答案 1 :(得分:1)

以下是使用伪类:after

的解决方案

这样可以生成更清晰的DOM。

http://jsfiddle.net/9Wyuj/2/

/* Rectangle with bottom right (br) corner chopped */

.rectangle-br-chopped {
   width: 300px; 
   height: 100px; 
   background: blue;
}
.rectangle-br-chopped:after {
   height: 0;
   width: 240px;
   content:"";
   position: absolute; 
   border-top: 30px solid blue; 
   border-left: 30px solid blue;  
   border-right: 30px solid white; 
   margin: 100px 0 0 0;
}

答案 2 :(得分:1)

http://jsfiddle.net/XE4GE/

p {margin:1em auto;
    width:400px;
    overflow:hidden;
    position:relative;
    color:white;
    font-size:2em;
    padding:1em;
}
p:after {
    content:'';
    height:60px;
    width:60px;
    position:absolute;
    z-index:-1;
    bottom:0;
    right:0;
    margin:-30px;
    -webkit-transform:rotate(45deg);
        -moz-transform:rotate(45deg);
        transform:rotate(45deg);
    outline:1000px solid black;
}
body {
    background:url(http://lorempixel.com/100/100/abstract/10);
}