CSS三角形+正方形100%

时间:2016-05-12 19:48:51

标签: css css-shapes responsive

我想要这个正方形和三角形,在链接上显示100%页面宽度(响应)。

http://www.jsfiddle.net/webtiki/x9cxz423/199/

.btn {
position: relative;
display: inline-block;
height: 50px; width:50%;
text-align: center;
color: white;
background: gray;
line-height: 50px;
text-decoration: none;
padding-bottom:15%;
background-clip:content-box;
overflow:hidden;
}
.btn:after {
content: "";
position: absolute;
top:50px; left: 0;
background-color:inherit;
padding-bottom:50%; width:57.7%;
z-index:-1;

-webkit-transform-origin:0 0;
-ms-transform-origin:0 0;
transform-origin:0 0;

-webkit-transform: rotate(-30deg) skewX(30deg);;
-ms-transform: rotate(-30deg) skewX(30deg);
transform: rotate(-30deg) skewX(30deg);
}
/** FOR THE DEMO **/
body{background: url('http://lorempixel.com/output/people-q-c-640-480-    1.jpg');background-size:cover;}

我似乎无法让它工作,有人可以帮助我吗?

谢谢

1 个答案:

答案 0 :(得分:1)

我已修复您的代码,现在也是响应!



.btn {
    position: relative;
    display: inline-block;
    height: 50px; 
    min-width:100%;
    text-align: center;
    color: white;
    background: gray;
    line-height: 50px;
    text-decoration: none;
    padding-bottom:30%;
    background-clip:content-box;
    overflow:hidden;
}
.btn:after {
    content: "";
    position: absolute;
    top:50px; left: 0;
    background-color:inherit;
    padding-bottom:50%; width:57.7%;
    z-index:-1;
    
    -webkit-transform-origin:0 0;
    -ms-transform-origin:0 0;
    transform-origin:0 0;
    
    -webkit-transform: rotate(-30deg) skewX(30deg);;
    -ms-transform: rotate(-30deg) skewX(30deg);
    transform: rotate(-30deg) skewX(30deg);
}
/** FOR THE DEMO **/
body{background: url('http://lorempixel.com/output/people-q-c-640-480-1.jpg');background-size:cover;}

<a href="#" class="btn">Hello!</a>
&#13;
&#13;
&#13;