我开始使用CSS3做一个简单的形状或方形,但我卡住了,你知道我怎么能在下面产生效果?
图:
我的CSS:
.square{
width: 150px;
height: 100px;
-webkit-transform: skew(20deg);
-moz-transform: skew(20deg);
-o-transform: skew(20deg);
background: red;
}
答案 0 :(得分:2)
是。您应该可以使用perspective
,perspective-origin
和transform: rotateY()
例如:
/* Need a wrapper to use perspective */
#div1 {
position: relative;
height: 150px;
width: 150px;
margin: 50px;
padding: 10px;
border: 1px solid black;
-webkit-perspective: 150px; /* Chrome, Safari, Opera */
-webkit-perspective-origin: 50% 50%; /* Chrome, Safari, Opera */
perspective: 150px;
perspective-origin: 50% 50%;
}
/* Apply rotateY() to child */
#div2 {
padding: 50px;
position: absolute;
background-color: red;
-webkit-transform: rotateY(25deg); /* Chrome, Safari, Opera */
transform: rotateY(25deg);
}
/* CSS triangle trick */
#div2::after {
content: "";
position: absolute;
bottom: -19px;
left: 50%;
margin-left: -20px;
width: 0;
height: 0;
border-left: 20px solid transparent;
border-right: 20px solid transparent;
border-top: 20px solid red;
}
<div id="div1">
<div id="div2">HELLO</div>
</div>
答案 1 :(得分:1)
您可以使用三角形边框创建它。
#box {
width: 300px;
height: 150px;
border-left: 400px solid #e3dd2d;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
position: relative;
}
#box:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-left: 25px solid transparent;
border-right: 25px solid transparent;
border-top: 70px solid #e3dd2d;
position: absolute;
left: -220px;
bottom:-80px;
}
<强> Example 强>
<强>更新强>
#box {
width: 300px;
height: 150px;
border-left: 400px solid #e3dd2d;
border-top: 30px solid transparent;
border-bottom: 30px solid transparent;
position: relative;
}
#box:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-left: 25px solid transparent;
border-right: 25px solid transparent;
border-top: 70px solid #e3dd2d;
position: absolute;
left: -220px;
bottom:-80px;
}
#box div {
display: table;
margin-left: -400px;
text-align: center;
}
#box div span{
display: table-cell;
width: 400px;
height: 150px;
vertical-align: middle;
}
<div id="box">
<div>
<span>
Some text inside
</span>
</div>
</div>
<强> UPDATED EXAMPLE 强>