Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS Transform to skew the shape to a trapezium

Tags:

I want to be able to skew an element in the way the image displays below.

rhombus

I have been playing around with it, but dont seem to be able to get close to replicating that shape.

My css code is

transform:skew(30deg,30deg); 

Is transform even the right way to do this? Please let me know the best, most browser compatible, solution.

like image 358
user2909486 Avatar asked Apr 20 '14 02:04

user2909486


People also ask

How do I make a trapezium in CSS?

CSS Code: In this section, we will first design the div element using some basic CSS properties and then use the border-bottom, border-left and border-right properties to create the trapezium shape.

How do you change skew in CSS?

CSS | skew() FunctionThe skew() function is an inbuilt function which is used to transform an element in the 2D plane. Skew an element means to pick a point and push or pull it in different directions. Parameters: ax: This parameter holds the angle representing the horizontal axis to distort an element.

How do you make a Div skew?

Give your <img> the opposite skew of your div by adding transform : skewY(2deg); . This will only skew the bottom of your image. @Chris The padding is needed in order to hide part of the skew. If you want your image to closer to the top, you can remove the margin, or even give it a negative value like here.

What is skew property in CSS?

CSS Demo: skew() This transformation is a shear mapping (transvection) that distorts each point within an element by a certain angle in the horizontal and vertical directions. The effect is as if you grabbed each corner of the element and pulled them along a certain angle.


1 Answers

You can apply some rotate transform around the X axis and apply an appropriate pespective before:

div {       width:300px;   height:200px;   background:url(http://placekitten.com/300/200);   border:2px solid red;       border-top-width:4px;   border-bottom-width:1px;   -webkit-transform: perspective(200px) rotateX(40deg);       margin:100px; } 

Demo

like image 139
King King Avatar answered Nov 05 '22 03:11

King King