wolfwings: (Default)
wolfwings ([personal profile] wolfwings) wrote2007-01-27 03:58 am

Finally updating here again...

...because I found an incredibly nifty feature of CSS that all this time I hadn't known about, that I'm working to integrate into that web-comic-interface program I was building before: Selectors. It's useful enough I'll deal with posting it here just so everyone on my friends list sees it.

Most folks know about the a:hover CSS-tag that lets you set the 'hover' style for a link, or the div.warning to let you style <div class="warning"> (which is actually a shorthand for something I'm about to show here) but I bet you didn't know about td[direction~="up"] did you? That lets you define new attributes for your elements, for example in this case making this valid: <td direction="up left"> and applying the "up" and "left" styles if you have both defined.

The fairly well-known td.card form (using the class="blah" attribute) is actually nothing more than a shorthand for td[class~="card"] actually. The ~= means that the attribute is treated as a series of space-seperated values, and matches against each one individually. If you replace it with =, as in td[direction="apples and oranges"] then the CSS-style will only apply to that explicit attribute tag, for example if you need to perform some special trickery on some combinations of your custom attributes.

A minimal example of the effect.

[identity profile] premchai21.livejournal.com 2007-01-27 12:16 pm (UTC)(link)

XML Path Language (http://www.w3.org/TR/xpath)

[identity profile] elfs.livejournal.com 2007-01-27 05:11 pm (UTC)(link)
Doesn't work in IE6. In fact, IE6 is notorious about ignoring the [] syntax in CSS declarations.

[identity profile] animecat.livejournal.com 2007-01-31 09:06 pm (UTC)(link)
Hey Wolfwings? I've been trying to find you since RCFM... You commissioned a badge from me at RCFM and I never did get any contact info. I've just now found your LJ, and was wondering... what's the next con you'll be at? I'd really like to give you your badge!