3 Examples from the Future of CSS
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

3 Examples from the Future of CSS

More html news from Gaks[1]...

Following on from the W3C announcement of a 'Tags' attribute, I'll show you how this tags information can be utilized using CSS 2.0, today, and CSS 3.1, in the future.

First, a simple example, using just plain old CSS 2.0 attribute selectors, available today in firefox.

Consider the following chunk of style information:

<STYLE type="text/css">
p[tags] { background : lightgreen }
</STYLE>

It basically says "All p elements that have a Tags attribute should be shown in green." (You can use this today in firefox.)

[continues with code examples]

Hence the following html:

<p tags='example text css2 tutorial'>an example paragraph</a>

will render like this:

an example paragraph

Another example

This is also available in CSS2, and can be used today in firefox. [I've uninstalled IE7 and can't test it here]. The following style information:

<STYLE type="text/css">
a[tags~='warning'] { background : red }
</STYLE>

Basically says "all a elements with a 'tags' attribute containing the value 'warning' should have red background."

The little squiggle before the equals sign (i.e. "~=") is because tags could hold a lot of different space-delimited values: and we only need one of them to match. We don't need the entire attribute value to match.

If we apply the above style to the following snippet of html:

<a href='linksomewhere' tags='warning'>don't follow this link</a>

will render like this:

Basically, the rule is applied to the anchor element, because the value of its tag matched.

You can do some pretty cool things with this. If your browser supports it.

[All elements with an 'rss' or 'atom' tag could have a cute little feed icon beside them. Those with a 'microsoft' tag could have that oh so amusing "bill gates as locutus of borg" icon from slashdot circa 2001. And so on.]

Back to the future: A third example

Now, using the "attribute value" selector from CSS 3.1:

<STYLE type="text/css">
a[Tags]@ { display: inline; padding: 10 }
</STYLE>

The following html

<a href='linksomewhere' tags='warning'>don't follow this link</a>

will render like this:

which is semantically equivalent to injecting a span element at the front of the link, like this:

<a href='linksomewhere'><span style='padding: 10'>warning</span>don't follow this link</a>

The "@" in the above selector means, 'select the value of the attribute itself (rather than selecting the element it belongs to)'

So if we want to reveal the href of every link we can say:

<STYLE type="text/css">
a[href]@ { display: inline; padding: 10 }
</STYLE>

And thus a link to google, written like this:

<a href='http://www.google.com'>googleLink</a>

Would display like this:

[Okay -- I couldn't convince Gaks to forward me any further details of the CSS 3.1 spec, so you'll have to hassle Hixie, Tantek or Glaz directly if you want to know the future. Too bad ;-<]





'claire rand' on Fri, 21 Jul 2006 05:17:44 GMT, sez:

thats actually pretty useful, specifically for highlighting *where* a link goes, ala RSS feeds getting icons etc automatically. and having said icons change site wide as the stylesheet changes (e.g. allowing a CSS skining feature) without having to adjust server side graphics.

oh and the 'warning' feature is pretty good to. i want the ability to merge stylesheets, with *mine* taking priority, then i can probably highlight spam links when they start abusing all this (as they of course will).

if used right though it will make searching an article easy (if you can search on the tags) to extract info.. hmm..

could be good, but will be spammed to hell and back.



'karl' on Sat, 22 Jul 2006 00:14:08 GMT, sez:

not an announcement of W3C and you can already do that with the class attributes being valid.



'Pedro Rogério' on Tue, 05 Sep 2006 23:04:49 GMT, sez:

Thanks for the tips. It's cool!!!



'Nick Hebb' on Thu, 05 Apr 2007 16:42:04 GMT, sez:

I want variables for CSS so I can declare colors at the top of the file and change them in only one place.



'lb' on Tue, 10 Apr 2007 02:33:37 GMT, sez:

@Nick:
Rory Blyth has provided a tool for this, as has Mads Kristensen.

http://www.madskristensen.dk/blog/AddVariablesToStandardCSSStylesheetsInASPNET.aspx



'Josh' on Wed, 11 Apr 2007 18:56:27 GMT, sez:

Out of pure curiosity, isn't this bordering the line of content and presentation a bit? If the idea behind CSS is to clearly seperate the two, doesn't this technique start to open up a whole new realm of possibility for blending them back together? I am a humble programmer, and not a designer, but I can smell coupling a mile away and it is usually never good.



':-:s€zær->' on Sat, 03 May 2008 09:34:32 GMT, sez:

CSS "Cascading Style Sheets" LessoNs - WeB DesigN LessoN - - Web site : http://WWW.css-lessons.ucoz.com/index.html




name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. But the right to delete any post for any reason is reserved. Don't make me do it. Aim for constructiveness. Comments may be republished, emailed to your loved ones or printed and used as toilet paper. Also, I get particularly nasty on comment spam. It's not worth even trying to post comment spam here -- your html is escaped, and your links are given a rel='nofollow'. By attempting to post a comment, you understand that if the comment is considered spam, at my absolute discretion, your IP address may be used as the target of a prolonged distributed denial of service attack. Your electricity might suddenly stop working. Your car tyres will go mysteriously flat. You will suffer permanent hairloss. Your dreams will be filled with terrifying monsters. And in any case I reserve the right to record and publish your IP address.

 

TimeSnapper is a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

Use it for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. Use it right now! Go on! Hurry! Don't walk, run!

 

Articles

Just Wally Just Wally
The Correct Order for a First Time Viewing of The Lord Of The Rings The Correct Order for a First Time Viewing of The Lord Of The Rings
A new era for Android. A new era for Android.
Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion Mind-boggling Demo of New Gaming Genre, aka Folder-Based Hangman, aka Fun with Recursion
Got CSV in your javascript? Use agnes. Got CSV in your javascript? Use agnes.

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal
NimbleText -- World's Simplest Code Generator NimbleText: Code Generator, Text Manipulator, Data Extractor

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker


[powered by Google] 


How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
Thomas White
OJ Reeves
Eric Sink

Aggregated Links

proggit
dzone
hacker news
dot net kicks

Human Link Machines

interesting finds
a continuous learner's weblog
arjan's world
weekly link post

LinkedIn profile
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy