There's some interesting information online in regards to creating triangles and other polygonal shapes purely using css. Tantek Çelik's article A Study of Regular Polygons and Scott Jehl's Image-free CSS Tooltip Pointers — A Use for Polygonal CSS? served as the main inspiration for this tutorial.
I was curious to play with these concepts and see how they function cross-browser.
<div class="triangle basic"></div>
.triangle {
width: 0;
height: 0;
border-bottom: 0;
}
.triangle.basic {
border-top: 40px solid red;
border-left: 25px solid transparent;
border-right: 25px solid transparent;
/* IE6 specific hacks. See notes below. */
_border-left-color: black;
_border-right-color: black;
_filter: chroma(color=black);
}
Internet Explorer 6 does not comprehend setting a border colour to
transparent. It seems to instead treat
transparent
as being equal to
inherit,
with the result being your left and right borders being the
colour set in the
body
declaration of your css file.
Tervel Peykov has an article,
Emulating border-color: transparent in Internet Explorer 6,
which explains how IE6 can be "hacked" to display transparent borders using the propriatary
filter
attribute in css.
As noted in the article, the thing to be careful of when applying the filter is to make sure to choose a colour that is not applied or nested anywhere inside the parent you're applying it to.
For example, if your default font colour is black then set the filter in the css to something like pink or orange, or else your black text may vanish!
Based on tests I conducted, these are just some quick notes on how the popular browsers handle rendering polygon shapes.
| WinXP + OS X | OS X | WinXP | |||||
|---|---|---|---|---|---|---|---|
| Firefox 3 | Safari 3 | Opera 9 | Firefox 2 | Chrome 2 | IE 8 | IE 7 | IE 6 |
|
Pass
|
Partially
|
Partially
|
Partially
|
Pass
|
Partially
|
Partially
|
Partially
|
<div class="triangle basic outer"> <div class="triangle basic inner"></div> </div>
.triangle.outer {
position: relative;
}
.triangle.inner {
position: absolute;
}
.triangle.inner.basic {
border-left: 24px solid transparent;
border-right: 24px solid transparent;
top: 39px solid yellow;
bottom: 1px;
left: -24px;
}
Flat out, overlaying two polygons on top of each will just not work in Internet Explorer 6.
Applying the
filter
attribute to the inner triangle has the weird result of making the triangle below basically invisible.
There really isn't a good workaround to fix this, so the best suggestion would be not to use this technique and instead use the tried and tested method of using a background image.
| WinXP + OS X | OS X | WinXP | |||||
|---|---|---|---|---|---|---|---|
| Firefox 3 | Safari 3 | Opera 9 | Firefox 2 | Chrome 2 | IE 8 | IE 7 | IE 6 |
|
Pass
|
Partially
|
Partially
|
Partially
|
Pass
|
Partially
|
Partially
|
Fails
|
Here's just a simple example of how you can combine triangles with other elements to produce some simple models with a call-out.
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.
Depending on what the situation requires, using triangles and polygons rendered in css could easily reduce load times or provide a more versatile option to implementing a desired effect.
Nesting triangles may not be the best idea in the overall, as IE6 tends to break badly, but if you need to make simple shapes to accent an area of a design, this may be the perfect solution.