Member Sign In
Not a member?

A Wired.com user account lets you create, edit and comment on Webmonkey articles. You will also be able to contribute to the Wired How-To Wiki and comment on news stories at Wired.com.


It's fast and free.

Sign in with OpenID
Sign In
Webmonkey is a property of Wired Digital.
processing...
Join Webmonkey

Please send me occasional e-mail updates about new features and special offers from Wired/Webmonkey.
Yes No

Please send occasional e-mail offers from Wired/Webmonkey affiliated web sites and publications, and carefully selected companies.
Yes No

I understand and agree that registration on or use of this site constitutes agreement to Webmonkey's User Agreement and Privacy Policy.
Webmonkey is a property of Wired Digital.
processing...

Retrieve Sign In

Please enter your e-mail address or username below. Your username and password will be sent to the e-mail address you provided us.

or
Webmonkey is a property of Wired Digital.
processing...

Welcome to Webmonkey

A private profile page has been created for you.
As a member of Webmonkey, you can now:
  • edit articles
  • add to the code library
  • design and write a tutorial
  • comment on any Webmonkey article
Close
Webmonkey is a property of Wired Digital.

Sign In Information Sent

An e-mail has been sent to the e-mail address registered in this account.
If you cannot find it in your in-box, please check your bulk or junk folders.
Sign In
Webmonkey is a property of Wired Digital.

WebKit Experiments with CSS Variables

WebKit, the code that makes up the guts of browsers such as Apple’s Safari, has gained a much-requested new feature with the addition of variables in cascading stylesheets.

The feature, which won’t be available publicly until the next major release of Safari — and then only if it survives this experiment — is available now with its latest nightly WebKit build.

The enhancement comes after ten years of pleas for the feature by web developers. It would make designing and reading website code much easier by allowing developers to reference commonly-used styles by names chosen by the site’s designer. For example, watch how variables make this little piece of code, used to make the background of the page and tables light gray, a little more readable:

Without variables:

//Sets the background of the page and tables to the hex code for the color gray.
body {
   background-color:#ECEAE1;}
table {
   background-color: #ECEAE1;}

With CSS variables:

//Defines "DefaultBGColor" to light gray
@variables {
  DefaultBGColor: #ECEAE1;}
//Sets the background and any table on the page to the default background color
body {
  background-color: var(DefaultBGColor);}
table {
  background-color: var(DefaultBGColor);}

Current implementations of CSS have some standard variables for properties like alignment or color (”left,” “dark blue” or “red,” for example). However, unless you design your site around those pre-defined colors, you’re stuck having to memorize hex codes and pixel lengths. This is especially challenging for sites with multiple designers referencing the same code. Variables would mirror other coding standards by making these references configurable and recognizable according to site design.

Webkit, the rendering engine that powers Apple’s Safari and Linux’s Konqueror, is the first browser to support CSS variables. Web designers are not likely to take advantage of it until other major browsers, like Microsoft’s Internet Explorer and Mozilla’s Firefox, hop on the bandwagon. Still, it’s a nifty advancement, and something worth noting for the future.

To get started with Cascading Style Sheets (CSS), follow Webmonkey’s tutorial.

Post Comment Comments Permalink Print
Reddit Digg

 
Subscribe now

Special Offer For Webmonkey Users

WIRED magazine:
The first word on how technology is changing our world.

Subscribe for just $10 a year