The Rounded Corners of Tomorrow… Today!

Hey, you know what can be a real pain in the tail? CSS rounded cor­ners. Of course there are battle-tested, work­horse solu­tions out there, like slid­ing doors, or a hand­ful of Javascript-based alter­na­tives. But rounded cor­ners are such a com­mon ele­ment of web design and seem like a nat­ural exten­sion of the designer’s exist­ing toolkit that it only makes sense that there should be a way to imple­ment them with pure CSS. The good news is that border-radius is indeed com­ing in CSS3. The bet­ter news is that you can start using it today, as long as you’re only tar­get­ing Gecko & Webkit. Before we get to that though, let’s look at the way it’s sup­posed to work accord­ing to the spec.

As you might expect, the border-radius prop­erty is used a lot like border. That is, you can spec­ify one value for each cor­ner (border-radius: 10px;), one value per cor­ner (border-radius: 1px 2px 3px 4px;), or val­ues for oppo­site cor­ners (border-radius: 5px 10px). It actu­ally gets more com­pli­cated, since in addi­tion to describ­ing cor­ners with one radius (i.e. those with semi-circular curves), you can make ellip­ti­cally rounded cor­ners by nam­ing two radii. For more detail on this, take a look at the draft spec. Lastly, you can use a prop­erty for each cor­ner, border-top-left-radius: 2em;, etc. So, assum­ing there aren’t any major changes in the spec, expect this to be what gets imple­mented as part of CSS3, and what you’ll ulti­mately using in your code.

But what about now? Here? Today? It hap­pens that two of the standards-aware, forward-thinking ren­der­ing engines have devel­oped pro­pri­etary exten­sions to CSS that should stand in for border-radius until cer­tain ambi­gu­i­ties in the spec can be resolved, and the prop­erty is implented accord­ing to the stan­dard. So if you want to use border-radius in your code today, you’ll have to use both the Mozilla– and Webkit-specific CSS prop­er­ties. For­tu­nately, both of the pro­pri­etary exten­sions work in the cur­rent major releases of their respec­tive browsers.

If you’re mak­ing a box with four cor­ners of the same radius, the syn­tax is the same in Mozilla and Webkit:

-moz-border-radius: 10px; /* 4 corners of radius = 4px*/
-webkit-border-radius: 10px; /* Same as Mozilla */

To spec­ify dif­fer­ent radii for each cor­ner, things diverge somewhat.

/* Mozilla: */
-moz-border-radius: 1px 2px 3px 4px;
/* Webkit:
    (The four declarations below amount to the
    same thing as the single rule above) */
-webkit-border-top-left-radius: 1px;
-webkit-border-top-right-radius: 2px;
-webkit-border-bottom-right-radius: 3px;
-webkit-border-bottom-left-radius: 4px;

And that’s the guts of it. So to make a tabbed nav­i­ga­tion list, you would use a dec­la­ra­tion along the lines of the fol­low­ing (and see the below code in action.):

li {
  border: 1px solid #587402;
  border-bottom: none;
  border-radius: 0 10px 0 10px;
  -moz-border-radius: 10px 10px 0 0;
  -webkit-border-top-left-radius: 10px;
  -webkit-border-top-right-radius: 10px;
  list-style-type: none;
  float: left;
  padding: .5em 1em 0 1em;
}

There you have it. But there are just a cou­ple of other things I want to point out. If the con­tainer you’re round­ing the cor­ners of has only text con­tent and a back­ground in it, the back­ground will clip to the rounded cor­ners. And indeed, accord­ing to the spec, any the con­tents of a block-level ele­ment on which a border-radius is set should clip do the same as long as you set overflow: hidden on those con­tents. How­ever, the imple­men­ta­tions just aren’t there yet. Instead, with any­thing over and above plain HTML text (for instance, an img or iframe) inside such a con­tainer, the square cor­ners will peek out­side of the rounded con­tainer. (Exam­ple)

One solu­tion would be to make the bor­der thick enough that the cor­ners of the inner ele­ment can’t poke through the outer bor­der (like so). Though inel­e­gant, this will work just fine if you don’t need every­thing to round nicely. And this method should suf­fice for what­ever kind of con­tent you’re try­ing to stuff into your nicely rounded box.

How­ever, if it’s an image you’re putting in the box and you need the inner cor­ners to be rounded as well as the outer cor­ners, then the only answer (for now) is to set the image as a back­ground. Still, if the lan­guage of the spec is any indi­ca­tion, it won’t always be this way.

For the poor soul who is try­ing to squeeze iframe con­tent into a rounded cor­ner box, you’re essen­tially out of luck at the moment. You can cer­tainly use the thick bor­der method I described above, but short of that, you’ll have to look to the bleed­ing edge. That is to say, you’ll need some­thing which isn’t yet in any production-quality browser, but that is cur­rently in the Webkit nightlies. I speak of the arcane meth­ods of -webkit-mask-image. This prop­erty can take a png or an svg as its url, and pretty much any­thing you apply it to will play nice and clip to the shape of the image. See for your­self. Still, this last bit is obvi­ously not any­thing any­body will be using in pro­duc­tion code for some time to come.

After read­ing all of this, if noth­ing else, I do hope that you’ve come away with a bet­ter idea of some of the great things that the CSS work­ing group has in store for you, the devel­oper. But even moreso, hope­fully there’s some­thing in all of this mess that you’ll be able to put to use today.

Condemned 2 — First Impressions

I loved the first Con­demned. It was loads of fun, and I can count on two fin­gers the num­ber of games that I’ve found as legit­i­mately scary. So I was look­ing very for­ward to the sec­ond install­ment. Hav­ing now played through the first level of Con­demned 2: Blood­shot, let me offer a few pre­lim­i­nary thoughts about whether or not it lives up to the promise of its predecessor.

Graph­i­cally, it looks con­sid­er­ably bet­ter than Crim­i­nal Ori­gins. This is to be expected, since the lat­ter was a launch title for the 360, and the devel­op­ers clearly didn’t know much about how to uti­lize the resources avail­able to them. As such, the fact that the char­ac­ter mod­els and ani­ma­tion have dras­ti­cally improved is as expected as it is welcome.

I wish I could say that the game­play has improved as much as the over­all look of the game. Not so, I’m afraid. At least through the first part of the game, every­thing feels much eas­ier. Let me expand on that. The first thing I noticed when going through the com­bat tuto­r­ial at the start of the game was that I didn’t really need to block to keep from get­ting clob­bered. In the first game, encoun­ters usu­ally began with you hav­ing to block a 2x4 being swung at you by a lung­ing hobo. Then you’d have to watch your oppo­nent and pre­cisely time your blocks and par­ries until you had sent the bas­tard to wino hell. Each fight was intense, sav­age, and thrilling. This time around, how­ever, if you notice a bad guy before he spots you, you could poten­tially just run up to him and punch him until he dies. Not fun. But hey, who needs intense com­bat, when you’ve got… minigames? Uh, no. Thanks to God of War and Res­i­dent Evil 4, game devs think that tack­ing a small rhythm minigame onto a fight is suf­fi­cient to take monot­o­nous but­ton mash­ing into some­thing inno­v­a­tive. It’s not.

Unfor­tu­nately, the worst con­se­quence of tak­ing the grit out of the com­bat, is that the game has lost its white-knuckle edge. Play­ing through the first one was exhaust­ing. Each shadow poten­tially hid one or more blood­thirsty cra­zies who could kill you pretty quickly if you weren’t ready for a fight, and the result­ing ten­sion was gen­uinely drain­ing. For this out­ing, if you’re not wor­ried that you’re a cou­ple of whacks away from game over, the best you can hope for is a jump scare when the weird ash-monster explodes from the ceil­ing. It’s just not the vis­ceral expe­ri­ence that I loved the first time around.

What I do like is the sto­ry­telling. I like that our hero has essen­tially become one of the lost souls he mer­ci­lessly bat­tered in the first install­ment. I really like that from his (and the player’s) per­spec­tive, there isn’t any real indi­ca­tion that he hasn’t suc­cumb to what­ever it is that has caused half of his city’s pop­u­la­tion to turn into bru­tal psy­chopaths. Most of all, though, I really like the turn towards hor­ror that this game takes right from the out­set. The city is cov­ered in ooz­ing tar, skele­tal ash-men lurk in the shad­ows, and the weird lip-ring dudes are giv­ing you atti­tude in the most omi­nous way. Good stuff all. I just wish the game­play was able to match the tone of the writing.

Over­all, I have a lot of seri­ous issues with Con­demned 2 that I really hope will resolve them­selves as I get a lit­tle fur­ther along. How­ever, given how fan­tas­tic the first game was, I feel jus­ti­fied in being at least some­what opti­mistic that they will.

And speak­ing of vio­lent video games, Stephen King has come out against the pro­posed Mass­a­chu­setts law that would lump vio­lent games in with pornog­ra­phy as being “harm­ful to minors.” Indeed, he even namechecks RE4. This fur­ther sup­ports my long-held sus­pi­cion that Stephen King is com­pletely awesome.

What I’m Reading: 3/28

  1. It’s Not a League of Their Own: Boston Dirt Dogs has an excerpt from the 2008 Red Sox Annual in which the authors size up the Sox’ com­pe­ti­tion in the Amer­i­can League. On the whole, it’s pretty inter­est­ing I guess, but the best part is that the sec­tion on the Ori­oles is just one long ref­er­ence to The Wire. And if you read a lit­tle fur­ther down there’s another Wire ref­er­ence that’s mas­querad­ing as a pithy state­ment about the eco­nom­ics behind your brand new Tampa Bay Devil Rays:

    My eco­nom­ics are rusty, but when you have an infe­rior prod­uct in a sat­u­rated, inelas­tic mar­ket, one strat­egy is to re-brand the prod­uct. There­fore, exit the Devil, and their aqua uni­forms, to be replaced by the San Diego Padres kits with blue replac­ing sand brown.

    Stringer Bell is alive and well in the sports pages, folks.

  2. WebKit gets 100% on Acid3: “Yesterday’s news” you say? Nope. The news today is about Webkit/GTK. Awe­some news for us LXers. Also, def­i­nitely take a look at this account of the main Webkit team’s road to 100/100. It’s got some fun insights for spec­ta­tors of the race between Webkit and Opera for full Acid3 com­pli­ance. And for some (prob­a­bly much-needed) per­spec­tive, here’s one Mozilla-er’s take on the Acid3 arms race.
  3. JavaScript Talk at North­east­ern: It’s a video of John Resig’s recent talk at North­east­ern on Javascript and jQuery. What are you still doing here?

What I’m Reading: 3/24

  1. Nine Tech­niques for CSS Image Replace­ment: If you spend any time at all play­ing with CSS, you know that there are a full bajil­lion tech­niques for replac­ing text with an image. It’s a lot to remem­ber, and I’ll fess up that I tend to use what­ever one I hap­pened to have read about most recently rather than tak­ing a con­sid­ered approach to which of them might be the best solu­tion for a given sit­u­a­tion. No more! The above-linked post does a great job of run­ning through the pros and cons of the 9 (9!) major tech­niques, and from now on you (mean­ing “I”) no longer have any excuse to not use the best, seman­tic, most acces­si­ble one at every opportunity.
  2. Drugs, Bugs, and IE8: A pre­dictably good read from Eric Meyer, but I link to it mainly to have an excuse to echo the fol­low­ing point: There are a lot of beta browsers out there right now (one less, now that Safari 3 has shipped). If you’re test­ing your sites in them and some­thing ren­ders in any way other than what you were expect­ing, sub­mit a bug report. Don’t change your code.
  3. Opti­miz­ing Page Load­ing in the Web Browser: For the browser builders, net­work latency is at least as big a prob­lem as con­nec­tion speed.
  4. A Japan­ese RPG Primer: The Essen­tial 20: Last week, Gama­su­tra pub­lished this list of the best of the best in Japan­ese RPGs through­out the ages. It’s a top-20, so it’s not exhaus­tive, but it’s sure as hell exhausting–i’ve been chip­ping away at this beastie since last week. Any­way, if you’re at all into JRPGs, it’s a really fun read. It’s also neat to see some old favorites put into con­text along­side some sem­i­nal games that you may never have been exposed to.

Install Mongrel & Hpricot Under Ubuntu

When­ever I do a fresh install of Ubuntu, and I’m set­ting up Ruby, Rails, I always run into the same prob­lem with a hand­ful of gems (such as Mon­grel & Hpri­cot). This is how things usu­ally go down:

matt@thinkpad:~$ sudo gem install hpricot
Building native extensions.  This could take a while...
ERROR:  Error installing hpricot:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.8 extconf.rb install hpricot
extconf.rb:1:in `require': no such file to load -- mkmf (LoadError)
from extconf.rb:1
Gem files will remain installed in
/usr/lib/ruby/gems/1.8/gems/hpricot-0.6 for inspection.
Results logged to
/usr/lib/ruby/gems/1.8/gems/hpricot-0.6/ext/hpricot_scan/gem_make.out

Now what? The main prob­lem here is that Hpri­cot and Mon­grel both con­tain some C code that needs to be com­piled. In order to fix this, you’ll need to install the Ruby & C devel­op­ment libraries for Ubuntu. To do that, just fire up Ter­mi­nal and enter:

sudo apt-get install ruby1.8-dev linux-libc-dev libc6-dev

You should now be able to install Hpri­cot, Mon­grel, or any other gem that requires you to build some C. It’s that easy!

What I’m Reading: 3/20

  1. CSS Styled Scroll­bars With Mootools and JQuery: Cur­rently, only the IEs sup­port the styling of scroll­bars with CSS alone (although scroll­bar styles are part of CSS3). This post links to a cou­ple of Javascript-library-based tech­niques to get the job done in the meantime.
  2. Mak­ing ‘IE6-friendly’ PNG8 Images: Turns out our beloved hack to get trans­par­ent PNG32s in IE6 can some­times crash the browser. To play it safe and ensure crash-free view­ing of your site, it’s prob­a­bly best to use PNG8 until IE6 is no longer a fac­tor (some­day, «ras­safrackin…»). This post gives you some tech­niques to make your PNG8 graph­ics almost as use­ful as PNG32s.

What I’m Reading: 3/19

  1. Mar­t­ian Head­sets: Spolsky’s take on IE8 & web standards.
  2. Trans­la­tion From MS-Speak to Eng­lish of Selected Por­tions of Joel Spolsky’s “Mar­t­ian Head­sets”: Mark Pilgrim’s take on the above.
  3. Site­Point Guru Lists: SitePoint’s authors have listed the best arti­cles on the Site­Point, er, site, for get­ting started in var­i­ous areas of web design & development.

A Couple of Design Tweaks

There were a few lit­tle design-y things that were bug­ging me about this site, so I went ahead a fixed them. Mostly just adding some drop-shadows and fix­ing some footer behav­ior. Any­way, now that I like the look of the site bet­ter, per­haps I’ll write something!

Front-end Development Link Roundup

Here are just a few arti­cles that have come out in the last cou­ple of weeks that might be inter­est­ing and/or use­ful to some folks.

  1. What CSS Did We Learn in 2007
    SEO site Search-This lists the CSS tech­niques they cov­ered through­out last year. It’s a lot of use­ful, basic, meat-and-potatoes stuff.
  2. 101 CSS Tech­niques Of All Time– Part 1
    Noupe begins a multi-part list of what they find to be the most use­ful CSS tech­niques. Again, a lot of great basic stuff for those who may be new to CSS, but it should also be pretty handy as a ref­er­ence for the griz­zled vets out there.
  3. Acid 3 Tack­les ECMAScript
    Resig lays out exactly what Acid 3 is test­ing. Very inter­est­ing, and some nice insight into some edge cases in Javascript
  4. Thoughts on Fire­fox 3.0
    Nice overview of some of the changes in Fire­fox 3. He men­tions some improve­ments to the DOM imple­men­ta­tion (and links to Mozilla’s more exhaus­tive list).
  5. Reset­ting Again
    Eric Meyer once again pushes the state-of-the-art in CSS resets.
  6. IE6CSS Bugs and Fixes Explained
    Another nice ref­er­ence post. Dave Woods looks at a rogues gallery of cross-browser ren­der­ing issues.

That’s it for now. Hope­fully some­one will find some­thing use­ful in here.

KDE4: meh

I gave KDE4 a brief spin over the last cou­ple of days, and I’ve got to say that I pretty much hated it. I think Ubuntu Tuto­ri­als hit it right on the nose, so I won’t go into any real detail of what sucked so bad. Suf­fice it to say that the two main things (for me) that made it so awful were the following:

  1. They basi­cally took every­thing use­ful out of the K menu, so it’s not clear at all how to even do any­thing. If it’s so con­fus­ing for some­one who’s pre­vi­ously used KDE at some length, I shud­der to think how a novice user would fare.
  2. It looks so much like Aero. So much.

So, what­ever. I kind of hated it. How­ever, I’m a semi-devout GNOME/Aqua user, and I’ve got my desk­top tweaked so I can wring every last drop of scream­ing pro­duc­tiv­ity out of it. Maybe try the new KDE for your­self. YMMV.

If you do want to get it going on your sys­tem, and you’re run­ning Ubuntu (or pro­lly any Debian-based dis­tro), you can use this tuto­r­ial.