Fish tank with Puck the Fish Fish tank with Puck the Fish Water on the floor spelling Fish
 

Roundy

June 1st, 2009

This post is in homage to my old page, a triumph of curvaceousness. May it sleep roundly.

As any usability expert will tell you, the foundation of sound web page design is rounded corners. Their smooth curves lend an organic, almost sensual feel to a site, while other pages are un-navigable morasses of right angles.

Rounded corners are easy with tables and images! But tables make your page Web 2.0-incompatible, so most browsers cannot render it.

So when I decided to get some roundy corners for myself, I looked around, and the best I was able to find was Nifty Corners. There’s a lot to like about Nifty Corners, but look what happens if you try to make them overlap or put them on a, say, not-fixed-color background:

Notice that the corners of the boxes suffer. The problem is that the area around the corner cannot be drawn transparently – it needs to be over a fixed color. Browser specific extensions would be perfect if they weren’t browser specific.

But I like crazy backgrounds and overlapping boxes. So in a half-hearted effort for geek cred, here’s how my roundy corners worked.

This is a div:
This is a bordered div:
This is a thickly bordered div:
This is a thickly bordered div with differently colored borders:
This is a div bordered only on the left and right:
This is a div bordered more thickly on the right:
Closer:
Closer:
Contact:
This is a bunch of divs in a stack:
This is a bunch of divs in a stack with different right border widths:
This is a bunch of divs in a stack with different right border widths, set to float right:

Smaller:

Smaller:

One pixel high!

Make the left border pastel red to soften the edge. Tweak the border widths to get the desired curve. Add a solid div on top:

Four corners:

Connect the top and bottom with one div each:

Add a div in the center where stuff goes:

And the stuff doth go:

Yo mama!

Broken apart to show some of the pieces:

Yo mama!

These overlap nicely (at least in Safari, IE6, and Firefox), respect z-order, and work well with non-solid backgrounds. They do not require images, tables, or JavaScript.

Yo mama!

No, yo mama!

Touché!

Hey! Flexible widths!

Resize me!

But but but…

  • Isn’t that, like, a humongous flood of markup? Won’t the page take a long time to download?

Well, I worried about that too. But happily, all modern browsers support gzip compression – and boy does it work! Even though my last posting with comments is 382 KB in size, you only need to download 19.8 KB (Mac users can look in Safari’s Activity Viewer for the download size). So it ends up being smaller than, say, Yahoo!’s home page – and that’s just the HTML, not even counting all of its images. As a result, the page loads quite fast.

  • Well, don’t all those divs make the page unmaintainable?

Yeah, I suppose so. I use a script to generate these boxes, so the source is readable to me – even if the generated HTML isn’t.

 

The Internet!

π = 3.2851405312

Crazy but very cool.

The next logical step to me seems the question to which extent one can make these rounded corners grow with the font size by specifying the relevant lengths in em…

Very nice – there is the issue that if the page is zoomed (⌘-+ or ⌘–) in Safari 4 (and I’m assuming other new-ish browsers that do full page zoom instead of just text size), the divs “break” and the curve gets thrown off. BUT, I’d guess that less than 10% of people know about and use page zoom on a regular basis (probably even closer to <1% of interneteers).

Denis

Nice, but it looks very ugly when zooming out with Safari 4.0. Rounding error?

Same thing with Firefox 3.0.11 on Mac.

Jean-Daniel

Impressive. Personally I’m using the border-radius (-webkit or -mozilla version) CSS property, which scale well, and is far easier to use, and I don’t care if IE users don’t show the rounded corner.

Yay fishy back!

As I was reading through that table with the explanation in it, I started thinking “oh no, I can see where this is going…”
Absolutely hilarious. And it seems to work fairly well to as a cross-browser hack.

As for me… I’ll stick to sharp corners for the time being! :)