227 points · by grinnick · 13y ago · 104 comments
This hack on the other hand will work in every browser all the way back to Netscape Navigator or earlier.
<svg height=10 width=20>
<polygon fill=red stroke-width=0
points="0,10 20,10 10,0" />
</svg>
If you want to include it in your CSS, you can include it via a data URI, though you need to embed it as an actual XML document (within an HTML document, you can skip the namespace and use HTML syntax which doesn't require quotes around attributes) and can't include line breaks so the syntax is a little bit more cumbersome: .triangle {
background: url("data:image/svg+xml;charset=utf-8,<svg height='10' width='20' xmlns='http://www.w3.org/2000/svg'><polygon fill='red' stroke-width='0' points='0,10 20,10 10,0' /></svg>") no-repeat left center;
width: 20px;
height: 10px;
}
Examples of both in action: http://jsfiddle.net/jtR4G/If you want to make a triangle, without an additional (unnecessary) HTTP request, you should use the appropriate web tech which is SVG.
Just like all other resources you can easily embed an SVG in your HTML if you're being stingy on the requests (which is a good thing).
sadly, we will see some dozen iterations of 'flash' until that day finally comes. and html5 js shenanigans are only the third...
The web isn't just one visual presentation layer, its a multitude of presentation layers for all kind of people and that demands some compromise.
SVG would be awesome if it could be freely intermixed with HTML. I think I'd ditch HTML for everything other than text boxes and forms.
The beauty for me is not in the hack itself though, it is in the way it is presented - I adore the simplicity of this approach. Kudos!
#box { position: relative } #box:after {position: absolute; top: -10px; left: 45%; ... }
The fact that this exists and is lauded as clever rather than being ridiculed for its opaqueness really gets my goat.
<svg width='20' height='10'>
<path fill='#D94948' d='M0,20h20L10,0'/>
</svg>
Should be supported pretty much everywhere canvas is, but without the need of scripting to actually get a triangle.Some more - http://www.fileformat.info/info/unicode/block/geometric_shap...
Better site for this, IMO.
In fact, I think it's awesome that a triangle can be created from a "very broken rectangle", along with many other hacks that make this simple language quite powerful.
Eg. a triangle pointing down:
.triangle-down {
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-top: 7px solid #444;
} .triangle-down {
border: 1em solid transparent;
border-top-color: #444;
}Anyway, here's a link to the video: http://yow.eventer.com/yow-2012-1012/the-story-of-the-teapot...
As for the compatibility thing, you're coming at it the wrong way. Don't tell Google et al. to support yet another standard for CSS shapes. Let them spend their time implementing SVG and Canvas according to the existing spec. Inventing a new spec not only doesn't solve the problem, it actually re-introduces it.
I think we said the same stuff - came at it from slightly different angles. I´m not advocating yet another standard. Im saying - lets make it easy enough to use the appropriate (and already existing) standards to draw - rather than be at the mercy of a seemingly prehistoric styling system. My point with google et al was - get together and agree to a way to do simple things like images - the same way across browsers.
Does that help clarify?
I always knew how it worked but it was nice to see the animation play out.
OK, that's it everybody. Trying to do something? Is it done yet? Nope? Pack it in. All the things have been done.
HN reader who's not a designer: "don't like, bleh CSS, should SVG, used to do that in VIM, TIMTOWTDI" and other similar useless rants missing the point.
Part of web work is knowing immediately what you're dealing with. dimensionless rectangles that show up as triangles is a layer of complexity (hack) that disrupts flow.
Get it?