CSS3 toggle-button without JavaScript
lab.simurai.com
lab.simurai.com
This is pretty cool and fun to inspect & maybe draw inspiration from, but please don’t ever use code like this in production. Cool code ≠ reliably cross-browser, accessible, or maintainable code.
Dear downvoters, I’m not criticizing the experiment or the visual appearance of this trick. I love following simurai.
The best method of obtaining maintainable code is to avoid buggy browsers that need tons of workarounds and hacks.
/* AFAIK, not supported in moz/o[pera] yet */
and :target has incomplete browser support still. Nested <a> tags are a bit unusual, too, even if they are legal (is this valid? I don’t even know, because come on!)But I’d like to make a slightly broader point that, on the web, if you want something to work on as many clients (and that means on hundreds of different mobile browsers as well, these days) then sticking to the mainstream is your best bet, if perhaps boring :)
As it happens I've been fiddling with the HTML 4.01 DTDs in a project the past couple of weeks, and I can answer this for at least HTML 4.01: No. An A element may contain any inline element except for another A tag, which is explicitly denied.
(It isn't entirely clear to me whether the standard permits something like <a><b><a> or if the exclusions apply to all children, but the latter interpretation makes more sense.)
Edit: You’re right as far as browser support if you only want to target Webkit and bleeding-edge browsers, but that’s not really my point. (And I’m not sure why you would want to actively exclude other browsers by choosing a complicated technique instead of a more traditional, lightweight, and understandable one — which is my point.)
A better approach in my opinion is to use a checkbox (hidden) with a label pointing to it, then the styling can be applied with the CSS '+' selector, though this won't work with IE6, at least it's using sensible markup.
Google Chrome 8.0.552.237