Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

skewX() CSS3 Property

Tags:

css

I have a practical use for the CSS3 skewX property. I have written a simple image accordian-like script with jQuery. Images are skewed (already, not in CSS) as part of the design and in order to make the correct areas clickable, the containing divs need to be skewed.

The problem is that in skewing the div, the image is skewed aswell. Skewing a skewed image does not look good.

One solution I've tried is resetting the skewX value to 0deg on the image, but to no avail. In the fiddle, I haven't included the accordian as this isn't necessary to the solution.

http://jsfiddle.net/yM49N/2/

<div><img src="https://www.google.com/intl/en_com/images/srpr/logo3w.png"></div>
div {
    -webkit-transform:skewX(200deg);
       -moz-transform:skewX(200deg);
         -o-transform:skewX(200deg);
        -ms-transform:skewX(200deg);
            transform:skewX(200deg);
    border:1px solid red;
}
like image 544
kyranjamie Avatar asked Jan 24 '12 09:01

kyranjamie


People also ask

What is skewX in CSS?

The skewX() CSS function defines a transformation that skews an element in the horizontal direction on the 2D plane. Its result is a <transform-function> data type.

What is skewX and skewY?

skew(x-angle,y-angle) Defines a 2D skew transformation along the X- and the Y-axis. skewX(angle) Defines a 2D skew transformation along the X-axis. skewY(angle)

How do I resize a scale object in css3?

The scale() CSS function defines a transformation that resizes an element on the 2D plane. Because the amount of scaling is defined by a vector, it can resize the horizontal and vertical dimensions at different scales. Its result is a <transform-function> data type.

What are the CSS 2D transform methods?

For the purpose of positioning, rotating, scaling, or skewing elements along the X and Y axis there are various 2D transformation methods available in CSS. The basic 2D transformation methods in CSS are translate(), rotate(), scale(), skew(), and matrix().


1 Answers

You can apply an inverted skewX on img:

img {
    -webkit-transform: skewX(-200deg);
       -moz-transform: skewX(-200deg);
         -o-transform: skewX(-200deg);
        -ms-transform: skewX(-200deg);
            transform: skewX(-200deg);
}

To make the div contain the image properly, you also need to add overflow: hidden.

http://jsfiddle.net/thirtydot/yM49N/3/

like image 92
thirtydot Avatar answered Sep 30 '22 15:09

thirtydot