i got a div that looks like this:
+---------+
| |
+---------+
and I want to transform it like this:
+---------+
/ \
+-------------+
How can i do that ?
i got a div that looks like this:
+---------+
| |
+---------+
and I want to transform it like this:
+---------+
/ \
+-------------+
How can i do that ?
If you wish to use CSS transforms, see here
HTML
<div class='trapezoid'></div>
CSS
.trapezoid {
display: inline-block;
overflow: hidden;
margin: 0 3em;
/**outline: solid 1px;/**/
width: 10em;
height: 10em;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
}
.trapezoid:before {
display: block;
background: red;
content: '';
}
.trapezoid:before {
width: 20em; height: 3em;
transform: rotate(-45deg) translate(-4.142em, -2.6em);
-webkit-transform: rotate(-45deg) translate(-4.142em, -2.6em);
}
For a simpler implementation, see this fiddle
HTML
<div></div>
CSS
div {
border-bottom: 100px solid red;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
height: 0;
margin-top:30px;
width: 100px;
}
Divs are square elements, so you can't transform the actual bounding box of the div to be trapezoidal. However, you can play with borders and box shadows to achieve visual effects like that. See CSS3 matrix3d rectangle to trapezoid transformation for some potential help.
If by "how to transform" you mean how to rotate on the x axis applying a perspective to achieve deepness, then you can do it by using CSS3 transform
's perspective
and rotate3d
:
HTML
<div class="box">
Hover me
</div>
CSS
.box{
width: 300px;
height: 100px;
background: silver;
font-size: 4em;
margin: 100px;
}
.box:hover{
transform : perspective(400px) rotate3d(1, 0, 0, 50deg);
}
You may wanna read this other answer too.