You cannot create a non-rectangular DOM element.
There are several ways to hack it.
Firstly, there is a method of using CSS borders with different widths on each side of an element to make it look triangular. It will still be a rectangle, but it will look like a triangle.
There is a tutorial on this subject: http://www.russellheimlich.com/blog/pure-css-shapes-triangles-delicious-logo-and-hearts/
The downside of this approach is that it is limited to creating right triangles. You can join several of them together to get around this, but then you do not have a single container for your image.
An alternative hacker way to do this is to place rotating elements on top of the main element so that they cover the corresponding parts of the image and make it triangular. This works in all browsers, although IE does have a very nasty syntax for rotation, and it is pretty heavy in the browser, given that you will only use it to create shapes.
Another option would be to use CSS transforms. However, this is only supported by a small number of modern browsers, so it will not work for most users.
A better approach might be to use the right graphics library for this, instead of trying to fit it to the <div> element.
I would recommend using Raphael . This is a Javascript library that can be drawn directly in the browser using SVG (or VML for IE). It is trivial to create triangles using it and fill them with graphics. See the examples on Raphael's homepage for you to get started.
source share