0

I've found plenty of tutorials for creating Trapezoids using CSS3 but I am looking to create a four sided shape where none of the side are parallel (trapezium) like the one in the picture below.

enter image description here

Is this possible?

jbutler483
  • 24,074
  • 9
  • 92
  • 145
Tom
  • 12,776
  • 48
  • 145
  • 240

3 Answers3

2

Okay..Sorry for being late. Here's my answer:

Fiddle: http://jsfiddle.net/fELER/1/

CSS:

#up-triangle {
   width: 0; 
   height: 0; 
   border-bottom: 200px solid yellow; 
   border-left: 100px solid transparent; 
   border-right: 100px solid transparent; 
}

#right-triangle {
   position:absolute;
   top: 10px;
   left:175px;
   width: 50px; 
   height: 100px; 
   border-style: solid;
   border-width: 100px 0 0 300px; 
   border-color: transparent transparent transparent yellow;
   -webkit-transform: skew(29deg); 
   -moz-transform: skew(29deg); 
   -o-transform: skew(29deg);
   transform: skew(29deg);
}

HTML:

<div id="up-triangle"></div>
<div id="right-triangle"></div>

Some useful links: http://www.css3shapes.com/

http://apps.eky.hk/css-triangle-generator/

Ani
  • 4,473
  • 4
  • 26
  • 31
1

you could do this "by hand" html:

<canvas id="polygon" />

javascript

var polygon = document.getElementById('polygon').getContext('2d');
polygon.fillStyle = '#f00';
polygon.beginPath();
polygon.moveTo(0, 0);
polygon.lineTo(90,50);
polygon.lineTo(70, 70);
polygon.lineTo(0, 90);
polygon.closePath();
polygon.fill();

this doesn't make shure it's convex and it has no parallel lines. You have to put in the correct coordinates.

Fiddle: http://jsfiddle.net/8t4rZ/

ksu
  • 608
  • 4
  • 11
  • That's awesome... is there also any way of creating a border radius on the angles? – Tom Nov 19 '13 at 16:07
  • ok, this is described here: http://stackoverflow.com/questions/1255512/how-to-draw-a-rounded-rectangle-on-html-canvas – ksu Nov 19 '13 at 16:15
0
#box {
    border-bottom: 100px solid red;
    border-left: 50px solid transparent;
    border-right: 50px solid transparent;
    height: 0;
    width: 100px;
}

CSS trapezoid

Žarko Selak
  • 1,073
  • 12
  • 19