Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am working on a website where I need to use different trapezoid shape of images. Here I am giving you that image in rapidshare link:

http://rapidshare.com/files/3321655398/trapezoid.JPG

I have been trying different type of CSS3 code like

border-bottom: 100px solid #05ed08;
border-left: 15px solid #05ed08;
border-right: 45px solid transparent;

Also I have worked with using rotate, skew CSS but the images are always getting out of the shape. So I want the parent DIV with above image shape and when I will be put above image (like the left image) in that shape, it will not get out of the shape. And if the screen size increase the image is also increase but shape look like same as current.

Also I have posted a main structure of the site where those different shaped images will be one after another. Here as you can see, there are 3 different trapezoid shape of images. So I want to know how I can put those image one after another using CSS3.

share|improve this question
Don't share the file with that service. Upload it to imgur via Stack Overflow's interface. – alex 6 hours ago
@alex thats a minimum 10 rep service – Richard Tingle 6 hours ago
1  
@RichardTingle I suspected as much. Still, RapidShare is a horrible service to share images with. Users can always manually upload to imgur and link to it (I think that's allowed). – alex 6 hours ago
Yes. Rapidshare is a) one of the slowest, and b) it deletes its files after 2 months, so this link will become useless. Other than that, it's not that horrible though. Lots of ads on the site, but most of the ads are for itself. – Mr Lister 5 hours ago

1 Answer

HTML STRUCTURE FOR REFERENCE:

<div id="container">
    <span id="left">
        <img src=""/>
    </span>
    <span id="middle">
        <img src=""/>
    </span>
    <span id="right"></span>
</div>

I made this example for you with pure css.

Now let explain how I made it.

I take a container, set the dimension of that and the relative position.

#container{
width:600px;
background-color:orange;
height:300px;
overflow:hidden;
position:relative;
}

If you set the overflow:hidden all the element inside the container will be truncated and they can't expand outside of the parent.

After that I putted 3 span in the container, they are inline element so I can't set the width or height of it. For do that I set it to display:inline-block. Now I can give to the span a dimension.

The span are in a absolute position because I want that there can be a span over another. For that after the absolute position use z-index.

The 3 span ids.

#left{
position:absolute;
left:-100px;
display:inline-block;
width:300px;
background-color:red;
height:300px;
transform:skew(-20deg,0deg);
-ms-transform:skew(-20deg,0deg); /* IE 9 */
-webkit-transform:skew(-20deg,0deg); /* Safari and Chrome */
z-index:1;
overflow:hidden;
}
#left img{
-webkit-transform:skew(20deg,0deg);
}
#middle{
position:absolute;
left:200px;
display:inline-block;
width:200px;
background-color:green;
height:300px;
transform:skew(-20deg,0deg);
-ms-transform:skew(-20deg,0deg); /* IE 9 */
-webkit-transform:skew(-20deg,0deg); /* Safari and Chrome */
z-index:3;
border-right:10px solid white;
border-left:10px solid white;
overflow:hidden;
}
#middle img{
-webkit-transform:skew(20deg,0deg);
margin-left:-50px;    
}
#right{
position:absolute;
right:-100px;
display:inline-block;
width:400px;
background-color:gray;
height:300px;
transform:skew(-20deg,0deg);
-ms-transform:skew(-20deg,0deg); /* IE 9 */
-webkit-transform:skew(-20deg,0deg); /* Safari and Chrome */
z-index:2;
overflow:hidden;
}

As you can see there are the skew transformation for the shape, and also the overflow:hidden because I don't want the img inside the span go outside the parent area.

When I put an img inside the skewed span, it take also the skew of the shape. So apply the #nameofskewedcontainer img{ -webkit-transform:skew(20deg,0deg); } where the skew property are exactly the opposite that is applied to the span. With that I keep the img with the standard shape without skew. ( try to remove that in jsfiddle demo and see)

So I hope I was clear. For everything leave a comment!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.