<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>uxebu » blog &#187; themes</title>
	<atom:link href="http://uxebu.com/category/dojo/themes/feed/" rel="self" type="application/rss+xml" />
	<link>http://uxebu.com/blog</link>
	<description></description>
	<lastBuildDate>Thu, 19 Jan 2012 14:53:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Optimizing visual identities, an introduction to CSS variables</title>
		<link>http://uxebu.com/blog/2008/09/07/optimizing-visual-identities-an-introduction-to-css-variables/</link>
		<comments>http://uxebu.com/blog/2008/09/07/optimizing-visual-identities-an-introduction-to-css-variables/#comments</comments>
		<pubDate>Sat, 06 Sep 2008 22:32:56 +0000</pubDate>
		<dc:creator>nonken</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[themes]]></category>
		<category><![CDATA[css variables]]></category>
		<category><![CDATA[dijit]]></category>
		<category><![CDATA[themeing]]></category>
		<category><![CDATA[visual identities]]></category>

		<guid isPermaLink="false">http://blog.uxebu.com/?p=34</guid>
		<description><![CDATA[A few months ago, Daniel Glazman and David Hyatt have written a proposal for CSS variables. This is a great step forward and hopefully we will find cross browser implementations some time soon. In this article I will show how you can use CSS variables to optimize CSS. In the second part of this series [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago, Daniel Glazman and David Hyatt have <a href="http://disruptive-innovations.com/zoo/cssvariables/">written a proposal</a> for CSS variables. This  is a great step forward and hopefully we will find cross browser implementations some time soon.</p>
<p>In this article I will show how you can use CSS variables to optimize CSS. In the second part of this series you will learn how to use CSS variables efficiently in themeing applications (using the Dijit themes of the <a href="http://dojotoolkit.org">Dojo toolkit</a>) and in the last part we will take a look how we can deal with all the new technology and convert it into a cross-browser solution with the help of a little bit of server-side magic.<br />
<span id="more-34"></span></p>
<h2>How do CSS variables work?</h2>
<p>Using CSS variables is pretty simple, lets dive right in and look at an example:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a1a100;">@variables {</span><br />
&nbsp; CorporateBGColor<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#123123</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #cc00cc;">#logo</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>CorporateBGColor<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #cc00cc;">#contact</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>CorporateBGColor<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>Thats all there is to it (I admit there are a few more things but I leave those to you to find out &#8211; for now. The next blog post will cover it in more detail).</p>
<h2>Optimizing CSS</h2>
<p>When writing themes for toolkits, creating new visual identities, or designing complex websites you will notice that you will use the same CSS values over and over again.<br />
CSS already provides you with a lot of granularity, you are able to separate content from visual appearance, but there are still many cases where you will find yourself repeating things over and over again.</p>
<p>Usually front-end developers tend to move in two directions:</p>
<p>1. Describing the visual appearance of a an element by trying to be as descriptive in regards to that element as possible:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.shoppingBasket</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000333</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fefefe</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>The respective shopping element would then look as follows:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;shoppingBasket&quot;</span>&gt;</span>Basket<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>2. Describing an elements visual appearance by using several classes which can be used in a wider context and are combined to create a &#8220;visual event&#8221;:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.borderActive</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#ccc</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.backgroundActive</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fefefe</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<span style="color: #6666ff;">.textDefault</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000333</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>The respective element would then use the classes as follows:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;borderActive backgroundActive textDefault&quot;</span>&gt;</span>Basket<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>You already will have noticed that just taking one of the two roads will result in suboptimal CSS in regards to code beauty-ness, maintainability and performance.<br />
Using the first route you will find yourself using the same &#8220;background: #fefefe;&#8221; all over again and taking the second road you will find yourself trying to create as much granularity as possible losing the larger overview.</p>
<p style="margin: 40px;">
<a href='http://hub.uxebu.com:33550/wp-content/uploads/2008/09/css2.png'><img src="http://hub.uxebu.com:33550/wp-content/uploads/2008/09/css2.png" alt="" title="css2" width="500" height="292" class="alignnone size-full wp-image-58" /></a></p>
<p>Most front-end developers usually take the middle path, a mixture of both those techniques and this is good. Though many times &#8211; and especially in the cases of large cooperate themes, websites and toolkits &#8211; it is not optimal.</p>
<h2>Are CSS variables a solution?</h2>
<p>Lets just take a look at following implementation of above usecase, using CSS variables.</p>
<p>First we will create a dictionary with the visual identity (dictionary.css), containing all CSS variable definitions:</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a1a100;">@variables {</span><br />
&nbsp; backgroundActive<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fefefe</span><span style="color: #00AA00;">;</span><br />
&nbsp; backgroundHover<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span><br />
<br />
&nbsp; <span style="color: #808080; font-style: italic;">/* ... */</span><br />
<br />
&nbsp; textColorActive<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000333</span><span style="color: #00AA00;">;</span><br />
&nbsp; textColorHover<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#333000</span><span style="color: #00AA00;">;</span><br />
<br />
&nbsp; <span style="color: #808080; font-style: italic;">/* ... */</span><br />
<br />
&nbsp; borderDefaultWidth<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span><span style="color: #00AA00;">;</span><br />
&nbsp; borderDefaultStyle<span style="color: #00AA00;">:</span> <span style="color: #993333;">solid</span><span style="color: #00AA00;">;</span><br />
&nbsp; borderDefaultColor<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span><br />
<br />
&nbsp; <span style="color: #808080; font-style: italic;">/* ... */</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>Now we will implement those variables in the master CSS file (layout.css):</p>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666ff;">.shoppingBasket</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>textColorActive<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>backgroundActive<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>borderDefaultStyle<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>borderDefaultWidth<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>borderDefaultColor<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #6666ff;">.userDetails</span> <span style="color: #00AA00;">&#123;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>borderDefaultStyle<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>borderDefaultWidth<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>borderDefaultColor<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span><br />
<br />
<span style="color: #808080; font-style: italic;">/* ... */</span></div></td></tr></tbody></table></div>
<p>The respective element would still look like following:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;shoppingBasket&quot;</span>&gt;</span>Basket<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></td></tr></tbody></table></div>
<p>The benefit of this approach will clearly get visible when you are starting to deal with more than 10 classes. Envision a project with hundreds of classes, many of them describing similar things but not the same.</p>
<h2>So what are the benefits?</h2>
<ol>
<li><strong>Clearly structured CSS</strong><br />You might argue that your CSS will be less readable because you don&#8217;t see the actual value of the css property you are looking at. This is a valid concern, but we have to realize that the benefit completely outweighs that issue (if seeing the visual effect of a class in the browser is not enough, there are great debugging tools which give you all the info you need). The fact that a developer can tell you with one look that the background color of one and all active panes is &#8220;#133213&#8243; (paneBackgroundActive: #133213;) &#8211; that is all Tab panes, Accordion panes, etc. etc. &#8211; will improve development cycles incredibly</li>
<li><strong>Maintainability</strong><br />The visual definition is stored in one (maybe a few more) files. A front-end developer will not have to deal with a whole bunch of un-overseeable files but can focus on pure visual definitions. Changing a visual identity is a matter of adjusting one dictionary and not hundreds of CSS files.</li>
<li><strong>Documentation</strong><br />One factor which unfortunately has not yet been covered by too many people is CSS documentation. This is as important as any other documentation &#8211; especially if you are developing large scale apps. Having dictionary files with visual definitions will enable you to write clear documentation.
</li>
</ol>
<div class="codecolorer-container css twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="css codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #a1a100;">@variables {</span><br />
&nbsp; <span style="color: #808080; font-style: italic;">/* <br />
&nbsp; &nbsp;* used by the entire applications text <br />
&nbsp; &nbsp;* unless overridden by another variable <br />
&nbsp; &nbsp;*/</span><br />
&nbsp; defaultTextColor<span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#123321</span><span style="color: #00AA00;">;</span><br />
<span style="color: #00AA00;">&#125;</span></div></td></tr></tbody></table></div>
<p>The exact specification of how to document CSS best is a different discussion, there are already projects existing which are trying to push into that direction. </p>
<h2>Why is this good if no browser supports it?</h2>
<p>Since at the moment of writing only Webkit nightly is supporting CSS variables you might wonder why this whole thing should bother you at all.</p>
<p>The first step we should take is trying to abstract and generalize even more when we write CSS &#8211; not in the way as I described in the two examples at the beginning of this post but in the &#8220;CSS variable way&#8221; I described in the above example.<br />
Once we understand this we can decide whether it is worth shifting our development process to using CSS variables (this is not an easy decision, there is no (non-nightly) browser out there supporting it).</p>
<p>Until CSS variables are widely supported by browsers you could write a simple parser which would do the search and replace for you on the server, you would actually be serving plain old CSS files.</p>
<p>We will look into those possibilities in the next article using tools which allow you to preview a visual identity in real time, using the Dijit widgets and converting the CSS variable dictionary into plain CSS files on the server in the last article.</p>
]]></content:encoded>
			<wfw:commentRss>http://uxebu.com/blog/2008/09/07/optimizing-visual-identities-an-introduction-to-css-variables/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

