<?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>Pixel Acres &#187; CSS</title>
	<atom:link href="http://f6design.com/journal/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://f6design.com/journal</link>
	<description>Adventures in web and graphic design</description>
	<lastBuildDate>Wed, 16 May 2012 06:50:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Responsive elements that retain their aspect ratio</title>
		<link>http://f6design.com/journal/2011/10/18/responsive-elements-that-retain-their-aspect-ratio/</link>
		<comments>http://f6design.com/journal/2011/10/18/responsive-elements-that-retain-their-aspect-ratio/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 22:56:57 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=2194</guid>
		<description><![CDATA[Here is a quick tip for creating responsive elements that retain their aspect ratio as they scale. The problem In a fixed width layout it is simple to specify both the width and the height of an element: .rect &#123; width: 800px; height: 400px; &#125; When creating a responsive layout things get trickier, since (to [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick tip for creating responsive elements that retain their aspect ratio as they scale.</p>
<h3>The problem</h3>
<p>In a fixed width layout it is simple to specify both the width and the height of an element:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.rect</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">800px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">400px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>When creating a responsive layout things get trickier, since (to the best of my knowledge) it isn&#8217;t possible to specify a percentage based height that is relative to an element&#8217;s width. For example the following CSS rule won&#8217;t have the desired result, since the <code>height</code> value will be ignored:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.rect</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><img src="http://f6design.com/journal/wp-content/uploads/2011/10/ar-broken-578w.png" alt="Broken aspect ratio" width="578" height="56" class="contentImg" /></p>
<h3>A solution</h3>
<p>However, when we specify a <code>padding-bottom</code> value for the same element, the padding measurement <em>is</em> calculated relative to the element&#8217;s width:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.rect</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><img src="http://f6design.com/journal/wp-content/uploads/2011/10/ar-working-578w.png" alt="Correct aspect ratio" width="578" height="308" class="contentImg" /></p>
<p><a href="http://f6design.com/projects/responsive-aspect-ratio/">View a demo</a></p>
<p>You will notice that I have set the element&#8217;s <code>height</code> property to <code>0</code>, to ensure that the height of any child elements will not be added to the padding value when the visible height is calculated. </p>
<h3>A note about child elements</h3>
<p>If you also want to specify percentage based heights for a child element, you will need to assign an <code>absolute</code> or <code>relative</code> <code>position</code> value to both the parent and the child:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.rect</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    <span style="color: #6666ff;">.rect</span> p <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><a href="http://f6design.com/projects/responsive-aspect-ratio/absolute.html">View a demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2011/10/18/responsive-elements-that-retain-their-aspect-ratio/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Build a parallax scrolling website interface with jQuery and CSS</title>
		<link>http://f6design.com/journal/2011/08/06/build-a-parallax-scrolling-website-interface-with-jquery-and-css/</link>
		<comments>http://f6design.com/journal/2011/08/06/build-a-parallax-scrolling-website-interface-with-jquery-and-css/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 02:36:52 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML/XHTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=2141</guid>
		<description><![CDATA[Parallax scrolling website interfaces have been popping up all over the place recently. I didn&#8217;t want to miss out on the fun, so I have put together a parallax scrolling demo built using jQuery and CSS. Parallax what? Even if you&#8217;re not familiar with the term &#8220;parallax scrolling&#8221; you will certainly be familiar with the [...]]]></description>
			<content:encoded><![CDATA[<p>Parallax scrolling website interfaces have been popping up all over the place recently. I didn&#8217;t want to miss out on the fun, so I have put together a parallax scrolling demo built using jQuery and CSS.</p>
<p><a href="http://f6design.com/projects/parallax-scrolling/"><img src="http://f6design.com/journal/wp-content/uploads/2011/08/parallax-screenshot-578w.jpg" alt="Parallax scrolling interface" width="578" height="423" class="contentImg" /></a></p>
<h3>Parallax what?</h3>
<p>Even if you&#8217;re not familiar with the term &#8220;parallax scrolling&#8221; you will certainly be familiar with the technique. <a href="http://en.wikipedia.org/wiki/Parallax_scrolling">Parallax scrolling</a> is a 2d animation process that creates an illusion of depth by animating foreground layers faster than background layers. When you observe the landscape from a moving car, objects closer to the car appear to pass you faster than scenery further away. Parallax scrolling uses the same principle to trick the viewer into thinking they are observing a 3d scene.</p>
<h3>Demo and Download</h3>
<p>My demo web page shows one approach to building a vertical parallax scrolling interface:</p>
<p><a href="http://f6design.com/projects/parallax-scrolling/">View demo</a><br />
<a href="http://f6design.com/projects/parallax-scrolling/parallax-scrolling-demo.zip">Download source</a></p>
<p>You can scroll in the usual fashion, use the navigation menu at the right-hand side of the page, or the next/prev buttons that appear underneath each article. As you scroll, the page&#8217;s four content layers are animated independently of one another to create an illusion of depth.</p>
<p>The scrolling looks smoothest in Safari (at least that&#8217;s the case on my PC), but my demo should work in any modern browser.</p>
<p><em><strong>Disclaimer 1:</strong> Because this is just an experiment I&#8217;ve not spent any time optimising the demo to work on mobile devices. I wanted to keep the demo lean &#8216;n&#8217; mean, and not clutter it by sniffing mobile browsers and forking my code. On a production site you&#8217;d want to ensure that the site degrades gracefully on mobile devices, where scroll events and fixed positioning might work in unexpected ways.</em></p>
<p><em><strong>Disclaimer 2:</strong> The navigation menu in my demo is inspired by the menu on the Nike <a href="http://www.nikebetterworld.com/">Better World</a> website. If you plan on implementing a similar menu on a production site, please be aware of its origin.</em></p>
<h3>How it works</h3>
<p>The articles and background layers are given a fixed positioned with CSS, and assigned a <code>z-index</code> so that the foreground layers appear above the background layers. The four layers are: small clouds, large clouds, balloon/landscape images, articles.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* foreground (ballons/landscape) */</span>
<span style="color: #cc00cc;">#parallax-bg3</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">3</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">fixed</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">50%</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* align left edge with center of viewport */</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">940px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-470px</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* move left by half element's width */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Within each layer individual content elements are absolutely positioned. This was the most fiddly part of the process, since the elements need to positioned in such a way that they align in a pleasing manner when the user scrolls to any of the four articles. In this case it was really just a process of trial and error.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#bg3-1</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-111px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">355px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#bg3-2</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">812px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">321px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/* etc... */</span></pre></div></div>

<p>A few lines of jQuery control the parallax effect, triggered by a scroll event. I was surprised how easy this was to achieve, it is literally just a handful of lines of code.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">bind</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'scroll'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    parallaxScroll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> parallaxScroll<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> scrolled <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span>window<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">scrollTop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#parallax-bg1'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>scrolled<span style="color: #339933;">*</span>.25<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#parallax-bg2'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>scrolled<span style="color: #339933;">*</span>.5<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#parallax-bg3'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'top'</span><span style="color: #339933;">,</span><span style="color: #009900;">&#40;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span>scrolled<span style="color: #339933;">*</span>.75<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">'px'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As you can see the CSS <code>top</code> property is used to move each layer as the user scrolls. The foreground layer is always aligned to the top of the document, while the movement of other layers is adjusted according to their depth. The lower a layer sits in the stack, the less distance it is moved.</p>
<p>The rest of the jQuery is concerned with controlling the navigation menus. When the user clicks a navigation button the page scrolls to the top of the associated article. In the event that the user has JavaScript disabled, regular HTML anchor links still allow the page to be navigated, but without any fancy pants animations.</p>
<h3>Next steps</h3>
<p>I&#8217;m sure there are plenty of other approaches to parallax scrolling, and hopefully my experiment provides a starting point for your own explorations of the technique.</p>
<h3>Update</h3>
<p>I have updated the demo so that each parallax layer is given a fixed, rather than absolute, position. This approach gives a smoother scrolling effect.</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2011/08/06/build-a-parallax-scrolling-website-interface-with-jquery-and-css/feed/</wfw:commentRss>
		<slash:comments>71</slash:comments>
		</item>
		<item>
		<title>Goodbye conditional comments</title>
		<link>http://f6design.com/journal/2011/07/10/goodbye-conditional-comments/</link>
		<comments>http://f6design.com/journal/2011/07/10/goodbye-conditional-comments/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 01:46:42 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=2047</guid>
		<description><![CDATA[The very first article I wrote on this blog, back in July 2006, was titled Goodbye hacks. Hello conditional comments. In that post I discussed how conditional comments could be used to feed different stylesheets to older version of Internet Explorer, smoothing differences between browser rendering engines without resorting to CSS hacks. Conditional comments have [...]]]></description>
			<content:encoded><![CDATA[<p>The very first article I wrote on this blog, back in July 2006, was titled <em><a href="http://f6design.com/journal/2006/07/14/goodbye-hacks/">Goodbye hacks. Hello conditional comments</a></em>. In that post I discussed how conditional comments could be used to feed different stylesheets to older version of Internet Explorer, smoothing differences between browser rendering engines without resorting to CSS hacks.</p>
<p>Conditional comments have provided a great stopgap measure while we wait for obsolete versions of IE to fall into disuse, but as the market share of IE6 and IE7 has dwindled I&#8217;ve found myself relying on them less and less. In fact, I can&#8217;t remember the last time I resorted to a separate stylesheet to make an old browser behave.</p>
<p>Last week Microsoft announced that <a href="http://blogs.msdn.com/b/ie/archive/2011/07/06/html5-parsing-in-ie10.aspx">support for conditional comment</a>s will be dropped from version 10 of Internet Explorer. Like other modern browsers IE10 will treat conditional comments just like regular HTML comments, and ignore them. This is a very encouraging sign, since it means that Microsoft are confidant that IE&#8217;s support for web standards has reached a level where a standards compliant website ought to &#8220;just work&#8221; across all modern web browsers, without having to make special allowances for legacy rendering engines. </p>
<p>Of course, conditional comments will continue to be recognised by older versions of IE, but with IE6 and IE7 ready to disappear off the radar the time is clearly right for conditional comments to be put out to pasture. Goodbye conditional comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2011/07/10/goodbye-conditional-comments/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Getting unspecific with CSS</title>
		<link>http://f6design.com/journal/2011/05/19/getting-unspecific-with-css/</link>
		<comments>http://f6design.com/journal/2011/05/19/getting-unspecific-with-css/#comments</comments>
		<pubDate>Fri, 20 May 2011 04:27:06 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=1640</guid>
		<description><![CDATA[Anyone familiar with CSS will have encountered the concept of specificity, a nifty mechanism that allows web browsers to resolve conflicts between CSS declarations. Specificity is an essential component of the CSS cascade, and most of time it works in predictable ways which make your job simpler. However if you get too specific with your [...]]]></description>
			<content:encoded><![CDATA[<p>Anyone familiar with CSS will have encountered the concept of specificity, a nifty mechanism that allows web browsers to resolve conflicts between CSS declarations. Specificity is an essential component of the CSS cascade, and most of time it works in predictable ways which make your job simpler. However if you get <em>too</em> specific with your CSS selectors you might be making your stylesheets more complex than they need to be.</p>
<h3>Specificity in action</h3>
<p>Before we tackle the topic of over-specificity, let&#8217;s brush up on the basics. Here is a simple CSS/HTML snippet in which we want all <code>h1</code> headings to be blue, except for those which appear in a <code>section</code> element:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
section h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>I am blue!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
<span style="color: #009900;">&lt;section&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Big deal, I am red!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span></pre></div></div>

<p>When a browser renders the <code>h1</code> that is nested within the <code>section</code> element, it resolves the conflict between the two CSS rules by giving priority to the more specific selector: <code>section h1</code>.</p>
<p>In this example it&#8217;s easy to guess that the nested <code>h1</code> is going to be red, but specificity isn&#8217;t always so easy to grasp. Things get trickier when you start throwing IDs and classes into the mix, and in these cases it helps to understand how specificty is calculated.</p>
<h3>Calculating specificity</h3>
<p>When resolving a conflict between two rules, the cascade assigns the greatest weight to the rule with the most ID selectors. If the results are tied then the rule with the most class selectors wins out, and failing that the rule with the highest number of element selectors trumps any competing rules.</p>
<p>Many online resources state that specificity is calculated by assigning a numeric value to each selector, then adding them together: ID selectors are assigned a value of 100, class selectors a value of 10, and HTML elements a value of 1. This was how CSS1 worked, but CSS2 introduced the new calculation method which I outlined above. For most intents the two methods are identical, but results do differ when dealing with large numbers of selectors.</p>
<p>If you want the nitty gritty, the Sitepoint CSS reference <a href="http://www.w3.org/TR/CSS2/cascade.html#specificity">explains Specificity calculation</a> in great detail. If you find Sitepoint&#8217;s examples too difficult to digest then Andy Clarke&#8217;s humorous <a href="http://www.stuffandnonsense.co.uk/archives/css_specificity_wars.html">Specificity Wars</a> might be more your cup of tea.</p>
<p>Here is another example, showing the impact that an ID selector has on specificity. I&#8217;ve added a couple more HTML elments into the mix (you&#8217;ll see why soon), but we&#8217;re still trying to make the first <code>h1</code> blue, and the nested <code>h1</code> red:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#content</span> h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
section h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;home&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;article <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;blog-post&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>I am blue!<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
        <span style="color: #009900;">&lt;section&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>Big deal, I am red! Or am I?<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h1</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>section&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span>article&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>At first glance the second selector may appear to be more specific because it contains a reference to <code>section</code>, an element that is closer in proximity to the target heading. In fact the first rule will win out, and both <code>h1</code>&#8216;s will be blue. This is because the first rule includes an ID selector, while the second rule contains only element selectors. Remember that an ID selector trumps any number of class or element selectors.</p>
<p>To get the second color declaration working we would need to add a <code>#content</code> ID selector to it. This makes the selector more specific, and the nested <code>h1</code> will now be red as intended:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#content</span> section h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<h3>Don&#8217;t over-specify</h3>
<p>Complexity begets complexity, and the more specific a CSS selector is, the more difficult it becomes to overrule it. Imagine if our &#8216;blue&#8217; selector had looked like this:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #cc00cc;">#content</span><span style="color: #6666ff;">.home</span> article<span style="color: #6666ff;">.blog-post</span> h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">blue</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Talk about overkill. As well as an ID selector, the rule now also contains two class selectors and two additional element selectors. This forces us to make our &#8216;red&#8217; rule even <em>more</em> specific to ensure its <code>color</code> declaration is respected:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">div<span style="color: #cc00cc;">#content</span><span style="color: #6666ff;">.home</span> article<span style="color: #6666ff;">.blog-post</span> section h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This is clearly a much less efficient solution than the earlier example. Our &#8216;red&#8217; rule now requires one ID selector, two class selectors, and four element selectors to achieve what before we were doing with just one ID and two element selectors. </p>
<p>As well as being difficult to read, verbose CSS selectors make it harder to target nested elements. Conflicts may be easy to diagnose using a DOM inspector such as Firebug, but isn&#8217;t it better to avoid having to hunt for problems in the first place?</p>
<p>The solution is to <strong>make your selectors only as specific as they need to be</strong>. Use as few selectors as possible to achieve the desired result, and avoid adding extra ID or class selectors into your rule unless they really needs to be there. By crafting your selectors to be as unspecific as possible you can keep your stylesheets simple and readable, and preserve your sanity.</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2011/05/19/getting-unspecific-with-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best viewed in Safari</title>
		<link>http://f6design.com/journal/2011/05/05/best-viewed-in-safari/</link>
		<comments>http://f6design.com/journal/2011/05/05/best-viewed-in-safari/#comments</comments>
		<pubDate>Fri, 06 May 2011 05:45:37 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Typography]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=1498</guid>
		<description><![CDATA[Remember when websites came with disclaimers listing their minimum viewing requirements, and shooed away anyone who didn&#8217;t make the grade? &#8220;This website is best viewed in Netscape Navigator&#8221; visitors would be advised, or &#8220;View this site in Internet Explorer at 800&#215;600 resolution&#8221;. Those were the bad old days, and I would like to believe that [...]]]></description>
			<content:encoded><![CDATA[<p>Remember when websites came with disclaimers listing their minimum viewing requirements, and shooed away anyone who didn&#8217;t make the grade? &#8220;This website is best viewed in Netscape Navigator&#8221; visitors would be advised, or &#8220;View this site in Internet Explorer at 800&#215;600 resolution&#8221;. Those were the bad old days, and I would like to believe that as a community we have learned our lesson and moved on, embracing graceful degradation and progressive enhancement as alternatives to the &#8220;my way or the highway&#8221; mentality. </p>
<p>This morning I visited a website that caused me to wonder if we&#8217;ve come so far after all. I was looking forward to experiencing the site&#8217;s typography, which I&#8217;d been informed was exemplary, and was surprised when my browser served up fallback system fonts rather than the embedded web fonts I was expecting. A warning message in the masthead informed me that if the fonts looked &#8220;kind of weird&#8221; I should switch to Chrome or Safari.</p>
<p>My guess is that the site&#8217;s designer had chosen a typeface that wasn&#8217;t properly optimised for on-screen display, and as a consequence the site&#8217;s typography didn&#8217;t fare well on certain browser and operating system combinations. Rather than adapt their design to suit a wider audience the designer decided to try and change their user&#8217;s behavior by instructing them to switch to a different web browser. As a web professional I was surprised to be admonished for choosing to use Firefox 4 &#8211; the latest version of a modern web browser &#8211; and I can only imagine what a less technically inclined visitor would make of the warning message.</p>
<p>Thankfully browser sniffing is still a rarity, but all too often I see evidence of designers who are ignorant of, or choose to ignore the fact that many embedded web fonts render in a sub optimal fashion on the Windows platform. For these designers the fact that the website looks nice on their own (presumably Apple branded) computer seems to be enough. Never mind the fact that 85% of the average website&#8217;s audience <a href="http://www.statowl.com/operating_system_market_share.php">use the Windows platform</a>, and will experience the site&#8217;s typography in a very different fashion. </p>
<p>Jeffrey Zeldman called the disparity between various browser and OS font rendering engines the &#8220;<a href="http://24ways.org/2009/real-fonts-and-rendering">elephant in the room</a>&#8221; &#8211; everyone knows the problem is there, but none of us wants to mention it for fear of spoiling the web font party. Sadly his warning seems to have gone unheeded by some. Too many web designers continue to make poor font selections, ignore the majority of their users, and jeopardize their website&#8217;s usability in the process.</p>
<p>Thankfully typeface designers are beginning to acknowledge the problem, and hinting their fonts for improved performance on the Windows platform. Recently the Skolar typeface, which used to look very shabby in Windows, was <a href="http://blog.typekit.com/2011/03/16/skolar-web-hinted-for-better-screen-rendering/">skillfully re-hinted</a> by Ross Mills and now renders superbly. But the responsibility doesn&#8217;t rest solely with type designers &#8211; web designers and font vendors need to do their share too. Mills wrote an article for Typographica called <a href="http://typographica.org/2011/on-typography/the-state-of-webfont-quality-from-a-type-designers-view/">The State of Webfont Quality from a Type Designer’s View</a> in which he urges all parties involved in the production and distribution of web fonts to carefully consider the quality of the fonts being released. From my perspective that means web designers too: if we don&#8217;t choose our web fonts appropriately then can we really claim to be doing our jobs properly? </p>
<p>The case can be made that Apple&#8217;s approach to font rendering is superior to Microsoft&#8217;s, but that doesn&#8217;t give web designers an excuse for subjecting Windows users to a substandard typographic experience. Web design has always been about compromise and working within technical limitations. Trying to modify user&#8217;s behaviour by convincing them to switch operating system or browser won&#8217;t work, and designing for a single platform is simply irresponsible.</p>
<p>Instead, why not restrict our typeface choices to those fonts that have been optimised to render well on both the Macintosh and Windows platforms? There are plenty of well hinted fonts out there, and as the web font marketplace matures the number of choices will continue to grow. Yes, it requires patience and restraint, but restraint should be something we&#8217;re all used to by now &#8211; for years we&#8217;ve had to make do with the handful of fonts that come pre-installed on both Windows and Mac OS. Surely it won&#8217;t kill us to continue using a little of that self-control and limit ourselves to web fonts that render well for all our users, instead of designing for a minority.</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2011/05/05/best-viewed-in-safari/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monokai theme for phpDesigner</title>
		<link>http://f6design.com/journal/2011/04/27/monokai-theme-for-phpdesigner/</link>
		<comments>http://f6design.com/journal/2011/04/27/monokai-theme-for-phpdesigner/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 22:15:42 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML/XHTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Toolbox]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=1364</guid>
		<description><![CDATA[Last year I created a port of the Monokai syntax highlighting theme for phpDesigner and posted it in the phpDesigner forums, but I think it deserves a proper home so I&#8217;m archiving it here on Pixel Acres. PHP example: HTML example: CSS example: JavaScript example: I&#8217;m not sure who designed the Monokai theme originally, but [...]]]></description>
			<content:encoded><![CDATA[<p>Last year I created a port of the Monokai syntax highlighting theme for <a href="http://www.mpsoftware.dk/phpdesigner.php">phpDesigner</a> and posted it in the <a href="http://www.facebook.com/topic.php?uid=108672675347&#038;topic=11050">phpDesigner forums</a>, but I think it deserves a proper home so I&#8217;m archiving it here on Pixel Acres.</p>
<h4>PHP example:</h4>
<p><img src="http://f6design.com/journal/wp-content/uploads/2011/04/monokai_theme_php.png" alt="" title="monokai_theme_php" width="450" height="389" class="alignnone size-full wp-image-1377" /></p>
<h4>HTML example:</h4>
<p><img src="http://f6design.com/journal/wp-content/uploads/2011/04/monokai_theme_html.png" alt="" title="monokai_theme_html" width="450" height="179" class="alignnone size-full wp-image-1378" /></p>
<h4>CSS example:</h4>
<p><img src="http://f6design.com/journal/wp-content/uploads/2011/04/monokai_theme_css.png" alt="" title="monokai_theme_css" width="450" height="224" class="alignnone size-full wp-image-1381" /></p>
<h4>JavaScript example:</h4>
<p><img src="http://f6design.com/journal/wp-content/uploads/2011/04/monokai_theme_js.png" alt="" title="monokai_theme_js" width="450" height="258" class="alignnone size-full wp-image-1383" /></p>
<p>I&#8217;m not sure who designed the Monokai theme originally, but it has cropped up in <a href="http://macromates.com/">Textmate</a>, <a href="http://notepad-plus-plus.org/">Notepad++</a>, <a href="http://www.sublimetext.com/">Sublime</a> &#8211; where it is the default colour scheme &#8211; and no doubt a bunch of other editors as well.</p>
<p>My version of Monokai is based on a Notepad++ theme, but I have standardised the color of variables (green) and symbols (white) across all the languages.</p>
<p>I don&#8217;t actually use phpDesigner much these days &#8211; I&#8217;ve jumped ship for <a href="http://www.aptana.com/products/studio3">Aptana Studio 3</a> &#8211; but I still think it is a great code editor, and hopefully someone out there will get some use from my theme.</p>
<h3>Download</h3>
<p><a href="http://f6design.com/projects/f6-monokai-phpd-theme/f6_monokai_phpd_theme.rar">Download Monokai theme for phpDesigner</a></p>
<p>Installation and uninstallation instructions are included with the theme. The theme has syntax highlighting colors for the four languages I work with: HTML, CSS, JavaScript and PHP.</p>
<h3>Important</h3>
<p>There is currently a bug in phpDesigner that sometimes causes the ‘separator’ colors to revert to their defaults (e.g. the color of  tags reverts to black). The only sure-fire way to get things back to normal is to open the phpDesigner preferences dialog, and click ‘OK’.</p>
<p>Apparently this bug will be fixed in the next release of phpDesigner (yay!).</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2011/04/27/monokai-theme-for-phpdesigner/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Organise your CSS</title>
		<link>http://f6design.com/journal/2011/04/24/organise-your-css/</link>
		<comments>http://f6design.com/journal/2011/04/24/organise-your-css/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 06:07:31 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=1242</guid>
		<description><![CDATA[Over the years I have streamlined the way I write and structure CSS to make my workflow more efficient. Here are a few tips I have picked up along the way. Use a global reset Web browsers apply default styles to HTML documents, but they do so inconsistently. So that you have a level playing [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years I have streamlined the way I write and structure CSS to make my workflow more efficient. Here are a few tips I have picked up along the way.</p>
<h3>Use a global reset</h3>
<p>Web browsers apply default styles to HTML documents, but they do so inconsistently. So that you have a level playing field when you start writing your CSS rules it is important to &#8216;reset&#8217; those browser-defined styles.</p>
<p>Eric Myer&#8217;s venerable <a href="http://meyerweb.com/eric/tools/css/reset/">CSS Reset</a> is the best known global reset snippet, and he has recently updated it for HTML5. Others options to consider are the <a href="http://html5doctor.com/html-5-reset-stylesheet/">HTML5 Doctor Reset Stylesheet</a> and <a href="http://html5boilerplate.com/">HTML5 Boilerplate</a>.</p>
<p>It doesn&#8217;t matter <em>which</em> flavour of reset you use, just make sure you use one! A global reset saves you from having to overwrite browser-defined styles at multiple locations throughout your stylesheet, and leaves you to concentrate on defining the styles you <em>want</em> instead of removing the ones you <em>don&#8217;t</em>.</p>
<h3>Break your CSS files into logical blocks</h3>
<p>Stylesheets can grow very large, and the bigger they become the harder they are to navigate. One way to manage this complexity is to organise your CSS document into smaller blocks, each one dealing with a specific aspect of your application.</p>
<p>I use CSS comments to demarcate each block of rules in my stylesheet, making it easy to scan the document for section headings rather than hunting for individual selectors:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Navigation
**************************************************/</span>
&nbsp;
nav <span style="color: #00AA00;">&#123;</span> ... <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Footer
**************************************************/</span>
&nbsp;
footer <span style="color: #00AA00;">&#123;</span> ... <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The document outline you settle on will be a matter of taste, but  I typically divide my stylesheet into the following sections:</p>
<ul>
<li>Global reset</li>
<li>Minimal base styles (generic)</li>
<li>Extended base styles (site specific)</li>
<li>Common shared styles</li>
<li>Page structure</li>
<li>Navigation</li>
<li>Headings</li>
<li>Footer</li>
<li>Forms</li>
<li>Printer styles</li>
<li>Handheld styles</li>
</ul>
<p>The &#8216;global reset&#8217; and &#8216;minimal base styles&#8217; sections stay the same from one project to the next, but everything else will change depending on the project requirements. I also assign a block to each major section of the website: the homepage, image galleries, contact page, and so forth.</p>
<h3>Use indentation to nest CSS rules</h3>
<p>Certain CSS properties are inherited by descendant elements, and it can be helpful to visualise the inheritance chain by indenting your CSS rules. This makes it easy to see where an element sits within the document tree and inherits its properties from.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#nav</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
    <span style="color: #00AA00;">&#125;</span>
    <span style="color: #cc00cc;">#nav</span> li <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">;</span>
        <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
        <span style="color: #00AA00;">&#125;</span>
        <span style="color: #cc00cc;">#nav</span> li a <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
            <span style="color: #00AA00;">&#125;</span>
        <span style="color: #cc00cc;">#nav</span> li span <span style="color: #00AA00;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
            <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Indentation is very common when writing HTML markup, but I find it invaluable for organising my CSS too.</p>
<h3>Organise your declarations following the box model</h3>
<p>When I was a starting out with CSS I didn&#8217;t employ any particular system for organising declarations within my CSS rules. I imagine this is how most web designers start off, but the lack of logical structure makes it difficult to locate a specific property within your CSS rule.</p>
<p>Once I started to get more organised I began sorting declarations alphabetically, so for instance a <code>background</code> property would come before a <code>width</code> property. There is a certain logic to that approach, but it means that related properties (<code>font-family</code>, <code>color</code>, and <code>text-indent</code>, for instance) are scattered around the rule instead of being grouped together.</p>
<p>More recently I&#8217;ve settled on a method of organising declarations that keeps related properties grouped together, yet standardises the order in which they appear within a rule.</p>
<p>My method is to organise declarations following the<a href="http://www.w3.org/TR/CSS21/box.html"> CSS box model</a>, moving from the outside in. In addition I place properties that affect the element&#8217;s interaction with the rest of the document at the top of the rule, and text-level rules near the bottom.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#my-element</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">1</span> <span style="color: #993333;">px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #933;">4px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">14px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The precise order in which properties should appear is debatable (should <code>float</code> come before <code>display</code>, or after?), nevertheless I find that that this approach helps me construct a mental picture of the element&#8217;s box model and its interaction with other elements on the page.</p>
<h3>Use shorthand property values</h3>
<p>Many CSS properties support shorthand notation which allow you to define several properties in a single declaration. This minimizes bloat as well as making your CSS easier to read and edit.</p>
<p>For example instead of:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">dotted</span><span style="color: #00AA00;">;</span>
<span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ffffff</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>You could write:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">2px</span> <span style="color: #993333;">dotted</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span></pre></div></div>

<h3>Write for readability, not performance</h3>
<p>When multiple selectors share the same rule, place each selector on its own line. This increases readability and ensures the selectors don&#8217;t get lost in a lengthy list. The same goes for CSS declarations. Instead of chaining your declarations together on a single line give them room to breath.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#nav</span> li a<span style="color: #00AA00;">,</span>
h2 a<span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.home</span> aside h3 <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">1em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This is much more readable than:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#nav</span> li a<span style="color: #00AA00;">,</span>h2 a<span style="color: #00AA00;">,</span><span style="color: #6666ff;">.home</span> aside h3<span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">1em</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">50px</span><span style="color: #00AA00;">;</span>color<span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#ccc</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>If you want the benefits of readable CSS <em>and</em> the bandwidth savings of single-line notation, then all you need to do is <a href="http://stackoverflow.com/questions/787789/any-recommendations-for-a-css-minifier">minify your CSS</a> immediately prior to deploying your project or on the server. </p>
<h3>Use comments for storing notes</h3>
<p>I usually keep comments within my CSS files to a minimum, but one place where I like to be expansive is at the top of the document, where I store &#8216;meta information&#8217; about the stylesheet.</p>
<p>In this header comment I include the project name, the purpose of the stylesheet and author contact details.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* F6 DESIGN
   Master Styles
   Author: Jonathan Nicol (jonathan@f6design.com)
&nbsp;
   Resources
   HTML5 Boilerplate: html5boilerplate.com
&nbsp;
   Colors
   Text gray: #76797b
   Link blue: #03add1
   Heading black: #1b1d1e
**************************************************/</span></pre></div></div>

<p>In the example above I have also made a note of any CSS techniques I may want to refer back to later, and stored references to commonly used hex color codes. It is a pain in the butt to scour the entire document looking for a specific hex value, and I find it more efficient to store my color codes in one place. You could use the same technique to store other commonly referenced CSS values, and needn&#8217;t restrict yourself only to colors.</p>
<h3>Share your own tips</h3>
<p>Organising CSS is very much a matter of personal preference, and there is no right or wrong approach. If you have any of your own CSS efficiency tips to share, please leave a comment below.</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2011/04/24/organise-your-css/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Sunset: A syntax highlighting theme for phpDesigner</title>
		<link>http://f6design.com/journal/2010/09/29/sunset-a-syntax-highlighting-theme-for-phpdesigner/</link>
		<comments>http://f6design.com/journal/2010/09/29/sunset-a-syntax-highlighting-theme-for-phpdesigner/#comments</comments>
		<pubDate>Thu, 30 Sep 2010 07:19:24 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML/XHTML]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Toolbox]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=1057</guid>
		<description><![CDATA[My weapon of choice for code editing is the excellent program phpDesigner, but every so often I like to test drive a different editor to see what I might be missing out on. Recently I spent some time playing with Notepad++, and one feature that jumped out at me was the ability to choose from [...]]]></description>
			<content:encoded><![CDATA[<p>My weapon of choice for code editing is the excellent program <a href="http://www.mpsoftware.dk/">phpDesigner</a>, but every so often I like to test drive a different editor to see what I might be missing out on. Recently I  spent some time playing with <a href="http://notepad-plus-plus.org/">Notepad++</a>, and one feature that jumped out at me was the ability to choose from a large number of pre-installed <a href="http://en.wikipedia.org/wiki/Syntax_highlighting">syntax highlighting</a> themes.</p>
<p>When I switched back to phpDesigner, the default blue-on-white color scheme seemed a tad boring, so I decided it was time to pimp my IDE! Unfortunately user created themes for phpDesigner are thin on the ground, which left me no option but to make my own.</p>
<h4>PHP example:</h4>
<p><img src="http://f6design.com/journal/wp-content/uploads/2010/09/sunset_theme_php.png" alt="Sunset theme for phpDesigner - PHP code" width="450" height="389" /></p>
<h4>HTML example:</h4>
<p><img src="http://f6design.com/journal/wp-content/uploads/2010/09/sunset_theme_html.png" alt="Sunset theme for phpDesigner - HTML markup" width="450" height="164" /></p>
<h4>CSS example:</h4>
<p><img src="http://f6design.com/journal/wp-content/uploads/2010/09/sunset_theme_css.png" alt="Sunset theme for phpDesigner - CSS" width="450" height="224" /></p>
<h4>JavaScript example:</h4>
<p><img src="http://f6design.com/journal/wp-content/uploads/2010/09/sunset_theme_js.png" alt="Sunset theme for phpDesigner - JavaScript code" width="450" height="258" /></p>
<p>I&#8217;ve named my theme Sunset, and it is inspired by the <a href="http://alexgorbatchev.com/SyntaxHighlighter/manual/themes/midnight.html">Midnight theme</a> for <a href="http://alexgorbatchev.com/SyntaxHighlighter/">SyntaxHighlighter</a>. If any phpDesigner fans are looking for a light-on-dark color scheme to spruce up their code editor, perhaps Sunset will fit the bill.</p>
<h3>Download</h3>
<p><a href="http://www.f6design.com/projects/f6-sunset-phpd-theme/f6_sunset_phpd_theme_1.2.rar">Download Sunset theme for phpDesigner</a></p>
<p>Installation and uninstallation instructions are included with the theme. Currently the theme has syntax highlighting colors for the four languages I work with: HTML, CSS, JavaScript and PHP.</p>
<h3>Important</h3>
<p>There is currently a <a href="http://www.facebook.com/topic.php?topic=12989&#038;post=148620&#038;uid=108672675347">bug in phpDesigner</a> that sometimes causes the &#8216;separator&#8217; colors to revert to their defaults (e.g. the color of <code>&lt;?php ?&gt;</code> tags reverts to black). The only sure-fire way to get things back to normal is to open the phpDesigner preferences dialog, and click &#8216;OK&#8217;. You might also try closing all your open documents and restarting the application. Hopefully this bug will be fixed in a future version of phpDesigner.</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2010/09/29/sunset-a-syntax-highlighting-theme-for-phpdesigner/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Font Squirrel&#8217;s @font-face kit generator</title>
		<link>http://f6design.com/journal/2009/10/18/font-squirrel-font-face-generator/</link>
		<comments>http://f6design.com/journal/2009/10/18/font-squirrel-font-face-generator/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 02:25:29 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[News & Reviews]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Typography]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=749</guid>
		<description><![CDATA[If you want to create your own @font-face kits, you absolutely must check out Font Squirrel&#8217;s new @font-face generator tool. All you have to do is upload a TrueType or OpenType format font, and the generator spits out a zip file containing: The original typeface for Safari and Firefox 3.5 A WOFF font for Firefox [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to create your own <code>@font-face</code> kits, you absolutely must check out Font Squirrel&#8217;s new <a href="http://www.fontsquirrel.com/fontface/generator"><code>@font-face</code> generator tool</a>. All you have to do is upload a TrueType or OpenType format font, and the generator spits out a zip file containing:</p>
<ul>
<li>The original typeface for Safari and Firefox 3.5</li>
<li>A WOFF font for Firefox 3.6+</li>
<li>An SVG font for Opera, Chrome, and iPhone</li>
<li>An EOT font for Internet Explorer</li>
<li>A sample HTML page</li>
<li>A sample CSS stylesheet</li>
</ul>
<p>The generator also features options to reduce file size by subsetting the font, cleanup font outlines, and auto-hint glyphs to improve rendering.</p>
<p><img src="http://f6design.com/journal/wp-content/uploads/2009/10/font_squirrel_generator.jpg" alt="Font Squirrel Generator" title="Font Squirrel Generator"  width="450" height="550" class="" /></p>
<p>Sweet!</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2009/10/18/font-squirrel-font-face-generator/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Typekit and the future of web fonts</title>
		<link>http://f6design.com/journal/2009/10/17/typekit-and-the-future-of-web-fonts/</link>
		<comments>http://f6design.com/journal/2009/10/17/typekit-and-the-future-of-web-fonts/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 09:51:08 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Typography]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://f6design.com/journal/?p=575</guid>
		<description><![CDATA[Now that all major web browsers finally support the CSS @font-face declaration, embedding fonts in a web page is possible with just a few lines of CSS. In theory this means that web designers no longer need to limit their font choices to a handful of system fonts, and are free to use any typeface [...]]]></description>
			<content:encoded><![CDATA[<p>Now that all major web browsers <a href="http://webfonts.info/wiki/index.php?title=@font-face_browser_support">finally support</a> the CSS <a href="http://www.w3.org/TR/css3-fonts/#the-font-face-rule"><code>@font-face</code></a> declaration, embedding fonts in a web page is possible with just a few lines of CSS. In theory this means that web designers no longer need to limit their font choices to a handful of system fonts, and are free to use any typeface they please. In practice that freedom comes with a caveat: we are only allowed to use fonts with a license agreement that allows web embedding.</p>
<p>The trouble is that digital fonts have no provision for <a href="http://en.wikipedia.org/wiki/Digital_rights_management">DRM</a>, and pirating a copy of an embedded web font is a trivial exercise for anyone with the mind to do so. That&#8217;s obviously not a prospect type foundries are too keen on, and consequently no major foundry offers a licensing option for embedding their fonts in a web page. If you link to a commercial font from your CSS stylesheet the chances are that you are breaking your license agreement. Even the number of free fonts with an EULA that <a href="http://www.webfonts.info/wiki/index.php?title=Fonts_available_for_%40font-face_embedding">condones <code>@font-face</code> embedding</a> is pitifully small.</p>
<p>That&#8217;s where <a href="http://typekit.com/">Typekit</a> comes into the picture. Typekit is a new font delivery service devised by <a href="http://www.veen.com/jeff/">Jeffrey Veen</a> that promises to take the pain out of licensing fonts for web embedding. In their <a href="http://blog.typekit.com/2009/05/27/introducing-typekit/">own words</a>:</p>
<blockquote><p>We&#8217;ve been working with foundries to develop a consistent web-only font linking license. We’ve built a technology platform that lets us to host both free and commercial fonts in a way that is incredibly fast, smoothes out differences in how browsers handle type, and offers the level of protection that type designers need without resorting to annoying and ineffective DRM.</p></blockquote>
<p>Here&#8217;s how it works:</p>
<ul>
<li>Typekit strike up agreements with type foundries allowing fonts to be licensed for CSS linking.</li>
<li>Web designers subscribe to Typekit, and pay a monthly fee to embed typefaces on their websites using an <code>@font-face</code> declaration.</li>
<li>Would-be font pirates are deterred from stealing embedded Typekit&#8217;s fonts by security measures including: allowing only authorised domains to link to their fonts; source code obfuscation; and splitting fonts into multiple files.</li>
</ul>
<p>Problem solved, right? Well, perhaps.</p>
<p>Typekit&#8217;s font-as-a-service model navigates a clever path through the legal minefield of web font licensing, but I am not convinced that it is a perfect solution. In particular there are two aspects of Typekit&#8217;s approach that strike me as problematic: the fact that their pricing model is based around renting fonts rather than owning them, and the need to rely on remote servers for the delivery of fonts.</p>
<h3>Renting vs buying</h3>
<p>Because Typekit is still in beta <a href="http://twitpic.com/ekj82">details of its pricing</a> are sketchy, but it is clear that customers will pay a monthly or annual subscription fee to access Typekit&#8217;s font library. This pricing model is significantly different to the traditional one-off payment required to license fonts for offline applications.</p>
<p>Will website owners be prepared to continue paying for a font month after month, year after year? Over time Typekit subscription fees could conceivably exceed the cost of a standard font license, despite the fact that Typekit&#8217;s fonts cannot be reused in any other medium, or potentially even on another website. And if you ever cancel your Typekit subscription, the fonts vanish into thin air. This is a radical departure from the current font licensing model, which grants customers the right to perpetually reuse any fonts they purchase.</p>
<h3>Purchasing fonts twice</h3>
<p>In addition to the fact that font subscription models require designers to pay for fonts they can&#8217;t reuse, in most cases it will also be necessary to purchase a regular installable version of each typeface.</p>
<p>To produce mockups and work on a production version of a website, a web designer needs to work with the same typefaces that will feature in the final live site. Typekit only offer web embedding of fonts, so to install a typeface on their local computer a web designer would have to purchase a separate font from another vendor. It&#8217;s not going to cut the mustard to produce mockups set in Arial and tell the client to &#8220;imagine that the headings are actually Avant Garde&#8221;!</p>
<p>When you also consider that many websites have multiple domain aliases (mysite.com, mysite.com.au, etc), and Typekit uses a per-domain pricing model, it is clear that the potential exists to pay many times over for the same font.</p>
<h3>Network reliability</h3>
<p>Another potential problem with Typekit is network downtime.</p>
<p>I can&#8217;t imagine many designers would trust their CSS files to a remote delivery network, and I think we need to accord fonts a similar importance. If major players like Google and Amazon suffer network interruption from time to time, then it is reasonable to assume that Typekit will too.</p>
<p>Admittedly, occasional network outages may not be a deal breaker, what happens if Typekit goes out of business, or a foundry retracts the right for Typekit to distribute their fonts? In either of these scenarios it seems probable that Typekit subscribers would have the fonts rudely stripped from their websites. In a best case scenario subscribers could turn to a Typekit competitor such as Fontdeck to revive their font links, but what if no competitor offered the same typefaces? The design of countless websites could be irrevocably ruined due to their dependence on remotely hosted fonts.</p>
<h3>The future of font embedding</h3>
<p>Despite the reservations I have outlined above, I have to agree with <a href="http://www.stuffandnonsense.co.uk/">Andy Clarke</a> when he predicts that <a href="http://forabeautifulweb.com/blog/about/why_typekit_will_change_everything/">Typekit will change everything.</a></p>
<p>By coming up with a practical answer to the problem of <code>@font-face</code> licensing, Typekit has paved the way for alternative font embedding approaches. Clearleft and OmniTI have joined forces to create <a href="http://fontdeck.com/">Fontdeck</a>, and at least one foundry, <a href="http://www.typotheque.com/site/index.php">Typotheque</a>, has a web font service <a href="http://www.typotheque.com/news/typotheque_web_font_service_screencast_demo">under development</a>.</p>
<p>Soon there will be a number of services vying with Typekit to win the hearts (and wallets) of web designers, however I suspect the deciding vote will ultimately be cast by large font foundries such as Linotype and Adobe.</p>
<p>The type industry&#8217;s major players will need to decide where they stand on the issue of font embedding, or they risk being left behind while smaller type foundries reap the benefits of web font licensing. If they follow the lead of their counterparts in the music industry it might be years before our <code>@font-face</code> woes are sorted out. On the other hand they might choose to take the bull the horns and launch their own font hosting services to compete with Typekit.</p>
<p>Whatever the response of large type foundries and vendors turns out to be, it will very likely determine the future of typography on the web. Hopefully we end up with a solution that is fair to web designers, website owners and font foundries alike.</p>
<h3>Further reading</h3>
<h4><a href="http://blog.typekit.com/2009/05/27/introducing-typekit/">Introducing Typekit</a></h4>
<p>Jeffrey Veen announces the arrival of Typekit, and explains the basics of how the service will work.</p>
<h4><a href="http://www.webdirections.org/blog/ubiquitous-web-font-embedding-just-got-a-step-closer/">Ubiquitous web font embedding just got a step closer</a></h4>
<p>John Allsopp argues the case for more liberal font licensing. Recommended reading.</p>
<h4><a href="http://forabeautifulweb.com/blog/about/first_impressions_of_typekit">First impressions of Typekit</a></h4>
<p>A step-by-step tour of the Typekit beta.</p>
<h4><a href="http://designintellection.com/on-typekit/">On Typekit</a></h4>
<p>David Yeiser shares some of my reservations about Typekit.</p>
<h4><a href="http://ilovetypography.com/2009/08/07/the-font-as-service/">The Font-as-Service</a></h4>
<p>Jay Elliot Stocks gives an overview of Typekit and its competitors.</p>
<h4><a href="http://forabeautifulweb.com/blog/about/testing_typotheque_font-face_embedding/">Testing Typotheque @font-face embedding</a></h4>
<p>Andy Clarke takes Typotheque&#8217;s new web license for a spin. It is interesting to note that Typotheque requires a one-off payment rather than a subscription like Typekit.</p>
]]></content:encoded>
			<wfw:commentRss>http://f6design.com/journal/2009/10/17/typekit-and-the-future-of-web-fonts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

