<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>CSS Wizardry</title>
	
	<link>http://csswizardry.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Wed, 16 May 2012 12:57:59 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/csswizardrycom" /><feedburner:info uri="csswizardrycom" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:browserFriendly></feedburner:browserFriendly><item>
		<title>Keep your CSS selectors short</title>
		<link>http://csswizardry.com/2012/05/keep-your-css-selectors-short/</link>
		<comments>http://csswizardry.com/2012/05/keep-your-css-selectors-short/#comments</comments>
		<pubDate>Tue, 15 May 2012 19:35:38 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Selectors]]></category>
		<category><![CDATA[OOCSS]]></category>
		<category><![CDATA[Performance]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3649</guid>
		<description><![CDATA[One thing I believe, as a very, very general rule of thumb, is that as sites get bigger, selectors should get shorter.
By this I mean that if you want to create extensible and maintainable, flexible and predictable websites, you should really take care to make your CSS selectors as dev-friendly as possible; i.e. short.
Keeping CSS [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I believe, as a very, <em>very</em> general rule of thumb, is that as sites get bigger, selectors should get shorter.</p>
<p>By this I mean that if you want to create extensible and maintainable, flexible and predictable websites, you should really take care to make your CSS selectors as dev-friendly as possible; i.e. short.</p>
<p>Keeping CSS selectors short helps with a lot of things:</p>
<ul>
<li>Increases selector efficiency</li>
<li>Reduces location dependency</li>
<li>Increases portability</li>
<li>Reduces chances of selector breakage</li>
<li>Decreases specificity</li>
<li>Can make code more forgiving</li>
</ul>
<p>This is a very vague list, so I’m going to address each in order. You will find that there is a lot of crossover between each point (e.g. reducing location dependency inherently means your selectors are more portable) but I feel they are all points in their own right.</p>
<h2>Increases selector efficiency</h2>
<p>I have written before about CSS selector efficiency. I&#8217;m going to gloss over a lot of the intricacies in this post so for a full background understanding I recommend you read <a href="http://csswizardry.com/2011/09/writing-efficient-css-selectors/"><cite>Writing efficient CSS selectors</cite></a> first.</p>
<p>If we ignore actual types of selector (<code>*{}</code> is typically the slowest, depending on how it&#8217;s being used, IDs are the fastest followed by classes, descendants are comparably quite slow followed by pseudo-selectors) then <em>in general</em> it is safe to say that shorter selectors are faster.</p>
<p>This stands to reason, if we compare these two selectors:</p>
<pre><code>html body .header .nav{}
.nav{}</code></pre>
<p>There we can see pretty clearly that in the first example, the browser has to look out for four things, the <code>.nav</code> class, then the <code>.header</code> class, then the <code>body</code> element and then, finally, the <code>html</code> element (browsers read selectors right-to-left).</p>
<p>With the second example the browser only needs to look for one thing; the <code>.nav</code> class. The browser has <em>four times</em> less work to do to match that selector. Every time you write a selector try and trim as much losable stuff from it as possible. Instead of <code>ul.nav{}</code> (two checks) write <code>.nav{}</code> (one check). Instead of <code>.nav li a{}</code> (three) write <code>.nav a{}</code> (two).</p>
<p>Now, <a href="http://calendar.perfplanet.com/2011/css-selector-performance-has-changed-for-the-better/">CSS selector performance is—by-and-large—not something we <em>really</em> need to worry about any more</a>, but that doesn&#8217;t mean we should be wasteful. I&#8217;m sure none of us would miss a lost &pound;5 but that doesn&#8217;t mean we go slipping banknotes into paper shredders… Selector efficiency <em>does</em> exist and you might as well improve it where you <strong>very easily</strong> can.</p>
<h2>Reduces location dependency</h2>
<p>By keeping selectors short you are likely to be reducing the amount of descendant (e.g. <code>.sidebar .promo{}</code>) and child (e.g. <code>.sidebar &gt; .promo{}</code>) selectors. By removing these descending types of selectors you are reducing the necessity for an element to live inside another one. Let&#8217;s reuse the <code>.sidebar .promo{}</code> example…</p>
<p>By having a selector like <code>.sidebar .promo{}</code> we are saying we want to target any promotional item that lives in an element with the class of <code>.sidebar</code>. This means that we are tied to always using that styling inside a certain element; we have a dependency on location.</p>
<p>By replacing <code>.sidebar .promo{}</code> with something like <code>.secondary-promo{}</code> we can now place the element in question <em>anywhere</em> we wish. In the sidebar—as before—but now also in the footer, or in the header, or after an article.</p>
<p>By reducing descendants we can really reduce dependency and make things a lot more portable…</p>
<h2>Increases portability</h2>
<p>So now that we&#8217;re not tied to locationally dependant selectors, we find that our components are a lot more portable. We can move things a lot more easily because our CSS doesn&#8217;t care where a thing lives, it just cares that it exists. Awesome!</p>
<p>Another way to increase portability is to not qualify selectors. A qualified selector is one like <code>ul.nav{}</code> or <code>a.button{}</code> or <code>div.content{}</code>.</p>
<p>Qualified selectors are bad because they reduce efficiency (more checks than we really need) but also because they tie us to specific elements. We can&#8217;t now use that <code>.button</code> class on an <code>&lt;input&gt;</code> or a <code>&lt;button&gt;</code>, for example. We can&#8217;t <a href="http://csswizardry.com/2011/09/the-nav-abstraction/">apply <code>.nav</code> to an <code>&lt;ol&gt;</code> to make a breadcrumb</a>.</p>
<p><strong>Selectors should be element-agnostic</strong>. Your CSS shouldn&#8217;t care what element you&#8217;re wanting to apply styling to.</p>
<p>Another way to make selectors more portable is to drop elements <em>altogether</em>. Take this, for example:</p>
<pre><code><span class=code-comment>/* Base widget styling */</span>
.widget{}

<span class=code-comment>/* Style up widget titles */</span>
.widget &gt; h2{}</code></pre>
<p>Here we have a troublesome selector; what if that <code>&lt;h2&gt;</code> needs to become a <code>&lt;h3&gt;</code>? What if we need to add another, non-titling <code>&lt;h2&gt;</code> as a child of <code>.widget</code>? We&#8217;ve made ourselves a very rigid and unportable selector here. Instead we should have:</p>
<pre><code><span class=code-comment>/* Base widget styling */</span>
.widget{}

<span class=code-comment>/* Style up widget titles */</span>
.widget-title{}</code></pre>
<p>Now we can apply <code>.widget-title</code> to <em>any</em> element—let&#8217;s say a <code>&lt;h4&gt;</code>—and can now also have any number of unclassed <code>&lt;h4&gt;</code>s in the widget without them adopting any title styling. Ossom!</p>
<h2>Reduces chances of selector breakage</h2>
<p>The longer a selector is, the more things the browser has to satisfy before it can match it. The more checks there are then—naturally—the more chance there is for something to go wrong.</p>
<p>A (very exaggerated) selector like <code>body &gt; div:nth-of-type(2) &gt; article:first-child &gt; p:first-child{}</code>—borrowed from my talk <a href="https://speakerdeck.com/u/csswizardry/p/breaking-good-habits?slide=15"><cite>Breaking Good Habits</cite></a>—has <em>ten</em> checks; ten things that must be satisfied in order for the browser to make that match.</p>
<p>All that needs to happen is the location of the <code>div:nth-of-type(2)</code> to change or the <code>p:first-child</code> to become a <code>blockquote</code> or the <code>article:first-child</code> to no longer be a child of the <code>div:nth-of-type(2)</code> or <em>any manner</em> of things before that selector will break. Simply replacing that with a class of <code>.intro{}</code> means that there is only one thing that could possibly break, and the chances of that happening are pretty much zero (you&#8217;d have to explicitly delete the class from your HTML to prevent a match).</p>
<p>Shorter selectors mean there is statistically less chance for things to go wrong.</p>
<h2>Decreases specificity</h2>
<p>This is the big one! This is where it really matters!</p>
<p>Longer selectors have a higher specificity. Specificity is a nightmare and <strong>you should keep specificity as low as possible all of the time</strong>. We already know that we <a href="http://csswizardry.com/2011/09/when-using-ids-can-be-a-pain-in-the-class/"><strong>do not use IDs in CSS</strong></a> but a chain of selectors are often just as bad (though not quite).</p>
<p>A selector like <code>.widget &gt; h2{}</code> has a higher specificity (as well as the other problems we discussed) than a selector like <code>.widget-title{}</code>.</p>
<p><code>.nav li a{}</code> has a higher specificity than <code>.nav a</code> (and is also less efficient). Reducing selector length reduces selector specificity and that is <strong>very important</strong>. High specificity leads to self-induced specificity battles that can only be won by making subsequent selectors <em>more</em> specific (or using <code>!important</code>, shame on you). This is a terrible thing. The easiest way to reduce specificity (after <em>dropping IDs from your CSS <strong>completely</strong></em>) is to keep your selectors short.</p>
<h2>Can make code more forgiving</h2>
<p>This is a very specific but very decent example of how short selectors can make code more forgiving. However, I will warn you, you can argue two sides of what I&#8217;m about to tell you; you can argue that it makes your code a lot more flexible and can gracefully handle breakages <strong>or</strong> you could argue that it allows breakages in the first place by being too lenient. Anyway, here&#8217;s a true story…</p>
<p>In working on a pretty huge project at Sky I stuck to my own rules and coded a (vertical) nav bar CSS like so:</p>
<pre><code>.nav{ <span class=code-comment>/* Nav styles */</span> }

<span class=code-comment>/* Note NO .nav li styles as this was a vertically stacking nav. */</span>

.nav a{ display:block; <span class=code-comment>/* More styles */</span> }</code></pre>
<p>Now, there was a CMS error which went undetected where the markup getting spat out was:</p>
<pre><code>&lt;ul class=nav&gt;
    &lt;a href=#&gt;&lt;/a&gt;
    &lt;a href=#&gt;&lt;/a&gt;
    &lt;a href=#&gt;&lt;/a&gt;
    &lt;a href=#&gt;&lt;/a&gt;
&lt;/ul&gt;</code></pre>
<p>Spot the problem? No <code>&lt;li&gt;</code>s! This is <em>really</em> not cool <strong>but</strong>, as I had used <code>.nav a{}</code> instead of <code>.nav li a{}</code> nothing broke. My code was a lot more forgiving than if I&#8217;d had that third check in there.</p>
<p>Now, this doesn&#8217;t make the markup right, and it does actually <em>allow</em> poorer markup than a more verbose selector, but you can see how the CSS was very forgiving of a markup error.</p>
<p>Now I said you could argue both sides here, a more verbose selector means that we&#8217;d have spotted the CMS error immediately as no styles would have hit the <code>&lt;a&gt;</code>s. But! In the same breath, our CSS was flexible enough to be okay with that. Make of it what you will, because I too am sat on the fence and a little disappointed that the error wasn&#8217;t spotted, but here is a very specific example of how shorter selectors can lead to more forgiving CSS.</p>
<h2>Final word</h2>
<p>I did mention that this is a rule I&#8217;ve applied to larger sites but, honestly, you should apply this everywhere. The things we&#8217;ve discussed tend to really come into their own (and their absence painfully aware) on larger builds, but they will definitely, <em>definitely</em> help you on builds of all sizes; small or large.</p>
<p>So, by using more classes and less descendants, keeping selectors short and portable, keeping selectors element-agnostic and generally considering maintenance and chance-of-change when writing our CSS, we can really easily improve the quality of our code infinitely. We can make things more efficient, more forgiving, more flexible and more reusable just by revisiting one of the most simple and fundamental aspects of CSS; our selectors.</p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/05/keep-your-css-selectors-short/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Front-Trends 2012</title>
		<link>http://csswizardry.com/2012/04/front-trends-2012/</link>
		<comments>http://csswizardry.com/2012/04/front-trends-2012/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 18:25:58 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[Speaking]]></category>
		<category><![CDATA[Front-Trends]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3626</guid>
		<description><![CDATA[Last night I landed back in a cold, miserable Leeds after spending what was by far the most exciting, amazing and fun few days I’ve ever had—as a speaker at Front-Trends.
Some time last year I was invited to speak at the conference, the first of its type I have ever spoken at; ‘nervous’ doesn’t even [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I landed back in <a href="http://instagr.am/p/KAOHsOojIg">a cold, miserable Leeds</a> after spending what was by far the most exciting, amazing and fun few days I’ve ever had—as a speaker at <a href="http://2012.front-trends.com/">Front-Trends</a>.</p>
<p>Some time last year I was invited to speak at the conference, the first of its type I have <em>ever</em> spoken at; ‘nervous’ doesn’t even come close.</p>
<p>I delivered my talk—<a href="http://speakerdeck.com/u/csswizardry/p/breaking-good-habits-1">Breaking Good Habits</a>—to 470 people! My only previous speaking experience was in the tiny English town of Barnsley to a small room of no more than 50. <a href="http://www.flickr.com/photos/csswizardry/7123682471/in/set-72157629558792354">This</a> was the most terrifying thing <em>ever</em> (and there are over a hundred people out of shot).</p>
<p><span id="more-3626"></span></p>
<p>I also snapped some pretty poor iPhone pictures of my time in Warsaw which, if you’re interested in, you can grab <a href="http://www.flickr.com/photos/csswizardry/sets/72157629558792354/">on Flickr</a>. If you’re a speaker and somehow find that you like my poorly focussed phone-camera snap of yourself then please, by all means, grab yourself a copy.</p>
<h2>The talks</h2>
<p>All of the talks were fantastic, very, very diverse, a mixture of technical and theoretical. They were all remarkable but my <em>personal</em> favourites were <a href="http://twitter.com/rachelandrew">Rachel</a>’s, <a href="http://twitter.com/chriscoyier">Chris</a>’, <a href="http://twitter.com/mathias">Mathias</a>’ and <a href="http://twitter.com/bartaz">Bartek</a>’s.</p>
<p>Rachel spoke about something that I’ve thought and agreed with for a long time; solving problems as and when they happen, not bloating your code from the outset with 101 different frameworks and, the thing that resounded with me the most, <em>we learn by making our own mistakes</em>.</p>
<p>Chris’ talk covered a lot about the concerns we as developers need to take into account these days with the shift in the web landscape. It was just <em>so</em> funny that you couldn’t help lap up everything he said. I can’t do his talk justice, wait for the video!</p>
<p>Mathias’ talk was just one of weird HTML quirkiness, something that I find super-interesting. I can’t wait for the video for that one (he was the only speaker to receive a full round of applause mid-talk!).</p>
<p>Bartek covered the fact that everyone who writes code is, whether they know it or not, teaching someone else who is reading that code. It was a really feel-good talk that has got me really excited to rewrite CSS Wizardry (which is long overdue anyway).</p>
<p>To see the videos and slides as they come available I recommend you follow <a href="http://twitter.com/fronttrends">the Front-Trends Twitter account</a>; you will definitely want to catch them when they get online!</p>
<h3>My talk</h3>
<p>I was so, so nervous when I woke up on the morning of my talk. All I ate all day was an apple. I got on stage at 13:00, and saw the crowd of 450+ staring back at me. I was terrified.</p>
<p>I got straight into the swing of things but was very aware of just how nervous I was. I can’t remember the half-hour of my talk at all, it’s now a total blur, and I was worried I’d really messed it up <em>but</em> I got some absolutely amazing feedback from Twitter and people who found me after the talk personally. It seems everything went well!</p>
<h2>The people</h2>
<p>Front-Trends allowed me to finally meet some people who I’ve known online for ages. Me and <a href="http://twitter.com/LeaVerou">Lea</a>, <a href="http://twitter.com/chriscoyier">Chris</a>, <a href="http://twitter.com/smashingmag">Vitaly</a> and others have followed each other for years and Front-Trends was my chance to finally meet them in person.</p>
<p>I took <a href="http://twitter.com/GotNoSugarBaby">Jamie Mason</a> along <a href="http://www.flickr.com/photos/csswizardry/7123696997/in/set-72157629558792354">with me</a>; Jamie is someone I met when I moved to BSkyB and he’s one of my best friends. Absolutely hilarious and incredibly likeable, as well as a very, very talented JS developer, he was a great person to have along (especially considering my nerves).</p>
<p>I got to meet <a href="http://twitter.com/rachelandrew">Rachel Andrew</a> who me and Jamie hung out with for a couple of days. Her talk was one of my favourites (she’s a great developer who speaks a <em>lot</em> of sense) and she’s also just super cool; she’s my new favourite person in the world! So clever yet humble, really laid back and fun, very easy to get on with and just all-round awesome. It was great to be able to hang out with her so much.</p>
<p><a href="http://twitter.com/smashingmag">Vitaly Friedman</a>, owner of Smashing Magazine, was someone I’d wanted to meet for <em>years</em> and owe a heck of a lot to. It’s likely that the only reason you know CSS Wizardry exists is because of a Smashing Magazine tweet (and there have been lots). Vitaly was one hell of a guy, absolutely lovely! It was ace having a few beers with him, and I really hope to meet him again soon.</p>
<p>Another person who was an absolute blast to hang out with was <a href="http://twitter.com/alexgiron">Alex Giron</a>; a fun, funny guy who was real great company!</p>
<p>Me and Jamie also met a lot of non-speakers which was really great. Far too many to name, but we spent a great chunk of time with <a href="http://twitter.com/RowanManning">Rowan</a>, <a href="http://twitter.com/samhicks1985">Sam</a>, <a href="http://twitter.com/monkeyhutch">Perry</a> (who can be seen with his hands in the air at the very back, <a href="http://www.flickr.com/photos/csswizardry/7123682471/in/set-72157629558792354">here</a>), <a href="http://twitter.com/tomalterman">Tom</a> and <a href="http://twitter.com/turbalan">Pavel</a> (I hope I got that right!).</p>
<h2>Beer</h2>
<p>This was a hot topic on Twitter&#8230; Free beer being served <em>throughout</em> the conference; not just after but <em>during</em>. You could sit with a beer and watch your favourite developer give a talk. That’s actually pretty awesome.</p>
<p>A lot of people on Twitter said to drink beer during a conference is unprofessional and that you shouldn’t serve any intoxicating beverages at such an event. To me that’s not right; drinking at a conference isn’t unprofessional, being drunk <em>is</em>.</p>
<p>The weather was amazing during the conference, hovering around 30&deg;C. There was a lot of grass outside the venue, it was <em>ideal</em> beer weather. The beer acted as a social lubricant; we’re a young dynamic industry, we deal day-in-day-out with cool and interesting stuff, we’re not a bunch of boring squares who dress in suits, we’re a community of interesting and excitable individuals, the exact kind of people I’d love to have a beer with—and got to!</p>
<p>The fact that beer was being served throughout the two days of baking sun where 470 like-minded people were gathered to watch some of the web’s best front-end developers (and me) give talks gave the whole thing a real festival feel. Front-Trends 2012 felt like a festival, a festival of designers, developers, sun, music and some absolutely stellar talks. Seriously, it was unreal. People commenting from afar on the beer situation unfortunately didn’t have the full context, they couldn’t see that no one was drunk, no one started any drinking games or competitions, no one embarrassed themselves; nothing went wrong.</p>
<h2>In short</h2>
<p>So, to sum up, in going to Front-Trends 2012 I:</p>
<ul>
<li>Delivered a talk to <a href="http://www.flickr.com/photos/csswizardry/7123682471/in/set-72157629558792354">470 people</a> from all over the globe.</li>
<li>Spent the whole time with Jamie Mason, one of my best and funniest friends.</li>
<li>Saw some absolutely fantastic talks by some truly genius people.</li>
<li>Hung out with Rachel Andrew for a couple of days.</li>
<li>Watched football in a bar with Jamie, Vitaly and Alex Giron.</li>
<li>Chilled out on a hammock with Lea Verou.</li>
<li>Almost died laughing at Chris Coyier.</li>
<li>Finally met Vitaly Friedman.</li>
<li>Saw a lot of beautiful sights in Warsaw.</li>
<li>Lots, lots more.</li>
</ul>
<p>Front-Trends was Wednesday to Saturday non-stop fun, interesting talks, great weather, lovely people and a beautiful city. It was my first and hopefully not my last talk at a proper conference, it was organised incredibly well and I would recommend that:</p>
<ol>
<li>Anyone thinking of heading to conferences over the next few years should get to Front-Trends.</li>
<li>People thinking of getting into speaking should try get a slot at Front-Trends (they got in touch with me even though I had zero speaking experience).</li>
<li>People organising conferences take a leaf out of <a href="http://twitter.com/czerskip">Paweł</a> and <a href="http://twitter.com/varjs">Damian</a>’s book.</li>
</ol>
<p>To the organisers, the lovely people of Warsaw and the speakers and attendees of Front-Trends, a massive, massive thank you!</p>
<p><i>Harry</i></p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/04/front-trends-2012/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>The single responsibility principle applied to CSS</title>
		<link>http://csswizardry.com/2012/04/the-single-responsibility-principle-applied-to-css/</link>
		<comments>http://csswizardry.com/2012/04/the-single-responsibility-principle-applied-to-css/#comments</comments>
		<pubDate>Sat, 28 Apr 2012 22:57:37 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Abstraction]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[OOCSS]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3614</guid>
		<description><![CDATA[Having just spoken at the Front-Trends conference in Warsaw, I’ve decided to expand on something which my talk mentioned a lot: classes.
My talk covered how to build big, scalable front-ends and one of the key factors involved in doing so is sensible and generous use of abstracted classes. One thing that really helps you achieve [...]]]></description>
			<content:encoded><![CDATA[<p>Having just spoken at <a href="http://2012.front-trends.com/">the Front-Trends conference in Warsaw</a>, I’ve decided to expand on something which my talk mentioned a lot: classes.</p>
<p>My talk covered how to build big, scalable front-ends and one of the key factors involved in doing so is sensible and generous use of abstracted classes. One thing that really helps you achieve this is the application of the <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">single responsibility principle</a>, a method used mainly in OO programming.</p>
<p><span id="more-3614"></span></p>
<p>Loosely, the single responsibility principle states that every module or chunk of code (a function etc) should do one job well and one job only. The benefits of this are mainly in the way of maintainability and extensibility.</p>
<p>If we don’t adhere to the SRP then we are likely to end up with code which does more than it should, this means that altering one part of that code could negatively impact a seemingly unrelated part of the same snippet. It also makes our code a lot less flexible in that we find our code is trying to do too much; it is too specific in its job to be portable and reusable. Abstracting chunks of functionality into several responsibilities means we can reuse a lot more of our code and recombine it over and over with other similarly abstracted chunks.</p>
<p>The <a href="http://en.wikipedia.org/wiki/Single_responsibility_principle">Wikipedia article</a> makes a much better job of explaining than I can so I would recommend giving that a quick read (it’s only short).</p>
<p>Also, you will find that a lot of us do this already, and perhaps without even realising. A class of <code>.wrapper</code> is a good example of the SRP at play; by having a single, reusable class whose sole job it is to group content we make our code a lot easier to work with. We don’t need to apply lots of widths to lots of elements; we use one extra <code>div</code> and delegate the width-constraining responsibility to that.</p>
<p>We do this because it makes sense, but we don’t do it often enough; if we start actually thinking like this all the time we find we can vastly improve our code&#8230;</p>
<p>The SRP is normally applied in programming circles but I have definitely found it is <em>incredibly</em> useful when making lean, scalable front-ends. Here’s a quick example of un-abstracted code that <strong>doesn’t</strong> follow the SRP:</p>
<pre><code><span class=code-comment>&lt;!-- HTML --&gt;</span>
&lt;a href=/product class=<mark>promo</mark>&gt;Buy now!&lt;/a&gt;

<span class=code-comment>/* CSS */</span>
.promo{
    display:block;
    padding:20px;
    margin-bottom:20px;
    background-color:#09f;
    color:#fff;
    tex-shadow:0 0 1px rgba(0,0,0,0.25);
    border-radius:4px;
}</code></pre>
<p>Here we have a class for a promotional box of content. Here we are doing <strong>two</strong> things—we are defining box model and structure <em>and</em> we are defining cosmetics (colouring etc).</p>
<p>We can refactor this code to adhere to the SRP by splitting those two chunks of functionality into two classes:</p>
<pre><code> <span class=code-comment>&lt;!-- HTML --&gt;</span>
&lt;a href=product class="<mark>island</mark> promo"&gt;Buy now!&lt;/a&gt;

<span class=code-comment>/* CSS */</span>
.island{
    display:block;
    padding:20px;
    margin-bottom:20px;
}

.promo{
    background-color:#09f;
    color:#fff;
    tex-shadow:0 0 1px rgba(0,0,0,0.25);
    border-radius:4px;
}</code></pre>
<p>We now have two classes which each carry a single responsibility; <code>.island</code> boxes off content and <code>.promo</code> applies our promotional styling. This now means that we can do things like this, which previously we couldn’t:</p>
<pre><code> <span class=code-comment>&lt;!-- HTML --&gt;</span>
&lt;h2&gt;Buy now with promo code: &lt;span class=<mark>promo</mark>&gt;0MG4WE50ME&lt;/span&gt;&lt;/h2&gt;</code></pre>
<p>Previously we couldn’t have managed this as the <code>.promo</code> class also carried a lot of box model; by abstracting our code into single responsibilities we can pick and choose what we want to use and where a lot more easily.</p>
<p>We can take this much, much further; now we also have a generic class for boxing off content! Where we once might have had:</p>
<pre><code><span class=code-comment>&lt;!-- HTML --&gt;</span>
&lt;div id=header&gt;
&lt;/div&gt;

&lt;div id=content&gt;
&lt;/div&gt;

&lt;div id=sub-content&gt;
&lt;/div&gt;

&lt;div id=footer&gt;
&lt;/div&gt;

<span class=code-comment>/* CSS */</span>
#header{
    padding:20px;
    margin-bottom:20px;
    background-color:#121416;
    color:#fff;
}

#content{
    width:640px;
    float:left;
    margin-right:20px;
    padding:20px;
    margin-bottom:20px;
}

#sub-content{
    width:280px;
    float:left;
    padding:20px;
    margin-bottom:20px;
}

#footer{
    padding:20px;
    margin-bottom:20px;
    background-color:#e4e4e4;
    color:#333;
}</code></pre>
<p>We would now have:</p>
<pre><code><span class=code-comment>&lt;!-- HTML --&gt;</span>
&lt;div class="<mark>island</mark> header"&gt;
&lt;/div&gt;

&lt;div class="<mark>island</mark> content"&gt;

    &lt;h2&gt;Buy now with promo code &lt;span class=<mark>promo</mark>&gt;0MG4WE50ME&lt;/span&gt;&lt;/h2&gt;

&lt;/div&gt;

&lt;div class="<mark>island</mark> sub-content"&gt;

    &lt;a href=product class="<mark>island</mark> <mark>promo</mark>"&gt;Buy now!&lt;/a&gt;

&lt;/div&gt;

&lt;div class="<mark>island</mark> footer"&gt;
&lt;/div&gt;

<span class=code-comment>/* CSS */</span>
.island{
    display:block;
    padding:20px;
    margin-bottom:20px;
}

.promo{
    background-color:#09f;
    color:#fff;
    tex-shadow:0 0 1px rgba(0,0,0,0.25);
    border-radius:4px;
}

.header{
    background-color:#121416;
    color:#fff;
}

.content{
    width:640px;
    float:left;
    margin-right:20px;
}

.sub-content{
    width:280px;
    float:left;
}

.footer{
    background-color:#e4e4e4;
    color:#333;
}</code></pre>
<p>Because we abstracted our code out we now have a really portable class for simply boxing off content!</p>
<p><strong>N.B.</strong> You should also abstract your layout to a grid system, taking the floats and widths off the page components and leaving that responsibility to the grids.</p>
<p>Just some of the benefits of working like this are:</p>
<ol>
<li>Your CSS is a lot DRYer.</li>
<li>You can make far-reaching changes to your designs by simply modifying a base abstraction only once.</li>
<li>You can make safer changes because you know that when editing a class you are only ever altering <em>one</em> responsibility.</li>
<li>You can combine responsibilities to make a variety of components from a lot of abstracted classes.</li>
</ol>
<p>Now we can take it further <em>still</em>.</p>
<p>Because we have a nice <code>.island</code> class whose sole responsibility is to box off content then we can now do things like this:</p>
<pre><code><span class=code-comment>&lt;!-- HTML --&gt;</span>
&lt;div class="island content"&gt;
    ...
    &lt;form&gt;
        &lt;p class="island <mark>error</mark>"&gt;Please provide your name.&lt;/p&gt;
        ...
        &lt;label class=<mark>error</mark>&gt;Name:&lt;/label&gt;
        ...
    &lt;/form&gt;
    ...
&lt;/div&gt;

<span class=code-comment>/* CSS */</span>
.island{
    display:block;
    padding:20px;
    margin-bottom:20px;
}

.error{
    background-color:#fce0e2;
    color:#c00;
}
.error.island{
    border:5px solid #c00;
    border-radius:4px;
}</code></pre>
<p>Because we have our chunks of CSS only working on one thing at a time then we can reuse and combine useful things time and time again. I’ve written about this before: <a href="https://plus.google.com/u/0/110483125936065828120/posts/DGPQzUdPi84">Class based builds are like eating at Subway</a>.</p>
<h2>When to use it?</h2>
<p>There’s no definite answer to questions like this but as a general rule try and stick to the SRP any time you think that subsets of a style rule could be split out into more manageable and <strong>reusable</strong> abstractions. Any time you are coding a potentially repeatable design pattern then try and split it out as per the single responsibility principle.</p>
<h3>But!</h3>
<p>It’s important not to take this too far; classes should be abstracted but ideally not presentational. Classes like <code>.round-corners</code> for the sake of SRP are really not all that advisable.</p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/04/the-single-responsibility-principle-applied-to-css/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>My HTML/CSS coding style</title>
		<link>http://csswizardry.com/2012/04/my-html-css-coding-style/</link>
		<comments>http://csswizardry.com/2012/04/my-html-css-coding-style/#comments</comments>
		<pubDate>Fri, 20 Apr 2012 18:58:53 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3561</guid>
		<description><![CDATA[Whenever I post jsFiddles, tutorials, articles or do some work here at Sky, I’m very particular about my coding style and am often asked questions about it. A lot of people say ‘code is art’; to me that sentence is a little pretentious but what I do think is that code can be a little [...]]]></description>
			<content:encoded><![CDATA[<p>Whenever I post jsFiddles, tutorials, articles or do some work here at Sky, I’m very particular about my coding style and am often asked questions about it. A lot of people say ‘code is art’; to me that sentence is a little pretentious but what I <em>do</em> think is that code can be a little more quirky and original than most people write it. It can be interesting. <a href="https://twitter.com/mathias">Mathias Bynens</a> is constantly tweeting crazy little snippets of quirky, valid JS; he’s also made <a href="http://mothereff.in">some great little tools</a> to help you explore the different avenues available to you when writing awesome, expressive and ‘different’ code.</p>
<p><span id="more-3561"></span></p>
<p>When I write HTML and CSS I have a certain set of rules and guidelines I stick to with regards syntax and formatting. I‘ve decided to write them up here <strong>not</strong> to preach or tell you how to do things, but simply to share how <em>I</em> like to work. If you hate the things I do that’s cool, these are not recommendations. If you like anything I do then great; you can have it. What I <em>would</em> love to see is other people doing the same; please consider writing up your coding styles, nuances and preferences and share them about!</p>
<hr />
<h2>HTML</h2>
<p>With HTML5 we have a lot looser syntax which means more scope for experimentation than we were typically used to with XHTML. With things like <code>&lt;li&gt;</code>s not requiring closing, some attributes not requiring quotes, tags not needing to be lowercase and elements like <code>&lt;hr /&gt;</code>s not needing to be self-closing, there’s a lot to play with! Here’s what I do with my HTML&#8230;</p>
<h3>Unquoted attributes</h3>
<p>Where I don’t need to, I don’t quote attributes. Where I would have had <code>class="wrapper"</code> I now have <code>class=wrapper</code>. Why? Because I can and I like the look of it!</p>
<p>Obviously, sometimes you do need to quote attributes. If you have multiple classes like <code>class=wrapper header-wrapper</code> then you <em>need</em> quotes. Without quotes the browser sees this as: <code>class="wrapper" header-wrapper=""</code>.</p>
<p>To know when you can and when you can’t use quotes then have a tinker with Mathias’ <a href="http://mothereff.in/unquoted-attributes"><cite>Mothereffing unquoted attribute value validator</cite></a>.</p>
<p>There are instances where you <em>could</em> use unquoted attributes but I choose not to. It’s hard to summarise this in a quick rule so I’ll give an example:</p>
<pre><code>&lt;input type=submit class=btn value=Login&gt;</code></pre>
<p>This is perfectly valid usage of unquoted attributes, however, imagine the client calls up the agency and (very rightly) says <q>Hey, the word <i>Login</i> needs to be <i>Log in</i>, can we change that please?</q> The project manager knows the designer is totally flat out busy and doesn&#8217;t have the time for smaller amends at the moment. Because project managers are awesome lovely people (right? Right?!), they decide that they can make this simple change themselves to save the designer a job. They open up the relevant file, see <code>value=Login</code> and simply change it to <code>value=Log in</code>, assuming that’s all there is to it. Now, the PM is likely not a technical person so they won’t necessarily know that this will now need quoting; the designer would have.</p>
<p>So, anywhere where the content of the attribute is subject to arbitrary change, I like to quote the attributes as a backup. Also, any time an attribute is populated dynamically (for example, through a CMS) it is best to quote it just in case; if you aren’t manually and consciously altering the attribute, play it safe and pop some quotes round it&#8230;</p>
<p>Now, I know what you’re thinking: <q>If you sometimes have to use quotes then why not always use quotes? It’s more consistent.</q> Well, you’re half right. It is more consistent on the whole, but by introducing rules I make my own consistency; if you can get away with not using quotes, then do so.</p>
<h3>No self closing tags</h3>
<p>With HTML5 we can write things like <code>&lt;hr /&gt;</code> as <code>&lt;hr&gt;</code>, <code>&lt;img /&gt;</code> as <code>&lt;img&gt;</code> and so on. I choose to omit the <code>/&gt;</code>, so in my HTML you’ll see things like:</p>
<pre><code>&lt;meta name=viewport content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"&gt;
&lt;link rel=stylesheet href=css/style.css&gt;</code></pre>
<p>Unquoted attributes where I can, and no self closing tags.</p>
<h3>Optional closing tags</h3>
<p>In HTML5 (or non-XHTML syntax) you can omit actual, full closing tags from <a href="http://meiert.com/en/blog/20080601/optional-tags-in-html-4/">certain elements</a>! This means that the following is totally valid:</p>
<pre><code>&lt;ul&gt;
    &lt;li&gt;Lorem
    &lt;li&gt;Ipsum
    &lt;li&gt;Dolor
    &lt;li&gt;Sit
    &lt;li&gt;Amet
&lt;/ul&gt;</code></pre>
<p>I <em>don’t</em> write my HTML like this as I’m just not too keen on the look of it&#8230; If you want to though, you certainly can.</p>
<h3>Whitespace</h3>
<p>This one is hard to quantify, but I like to use whitespace to loosely reflect the separation of elements that you might see once rendered. I group and space elements with whitespace as you would expect them to be grouped visually in the rendered page, for example:</p>
<pre><code>&lt;dl&gt;

    &lt;dt&gt;Lorem&lt;/dt&gt;
    &lt;dd&gt;Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.&lt;/dt&gt;

    &lt;dt&gt;Ipsum&lt;/dt&gt;
    &lt;dd&gt;Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante.&lt;/dt&gt;

    &lt;dt&gt;Dolor&lt;/dt&gt;
    &lt;dd&gt;Morbi in sem quis dui placerat ornare. Pellentesque odio nisi euismod in pharetra.&lt;/dt&gt;

&lt;/dl&gt;
&nbsp;
&nbsp;
&lt;div class=promo&gt;

    &lt;p&gt;&lt;strong&gt;Pellentesque habitant morbi tristique&lt;/strong&gt; senectus et netus et malesuada fames ac turpis egestas.&lt;/p&gt;
    &lt;a href=# class=btn&gt;Lorem&lt;/a&gt;

&lt;/div&gt;</code></pre>
<p>A mixture of no, single and double lines of whitespace help to separate elements, or show their visual relationship to one another. For example, the <code>&lt;dt&gt;</code>s and <code>&lt;dd&gt;</code>s belong with each other, but are separate from other groupings.</p>
<h3>Comments on closing tags</h3>
<p>After every major chunk of HTML, for example, the end of a carousel, or the end of the content <code>&lt;div&gt;</code>, I place a closing-comment, for example:</p>
<pre><code>&lt;div class=content&gt;

    ...

    &lt;div class=carousel&gt;
    ...
    &lt;/div&gt;<span class=code-comment>&lt;!-- /carousel --&gt;</span>

    ...

&lt;/div&gt;<span class=code-comment>&lt;!-- /content --&gt;</span></code></pre>
<p>This is certainly not uncommon practice, but because all closing tags look the same as each other (they can’t carry the classes that the opening tags do) it’s often nice to leave a comment so you know what element you’re dealing with.</p>
<h3>Namespaced fragment identifiers</h3>
<p>I came up with <a href="http://csswizardry.com/2011/06/namespacing-fragment-identifiers/">this idea to namespace fragment identifiers</a> last year. It’s basically, I think, a nice way to add a little more meaning to your fragment identifiers and give a little bit more of a clue as to what they actually link to.</p>
<pre><code>&lt;a href=<mark>#section:fragment-identifiers</mark>&gt;Fragment identifiers&lt;/a&gt;

...

&lt;div id=<mark>section:fragment-identifiers</mark>&gt;...&lt;/div&gt;</code></pre>
<hr />
<h2>CSS</h2>
<p>So far I’ve dealt with how I write HTML, but what about CSS? My CSS is a lot less ‘different’, it’s mainly only formatting and syntax rules here.</p>
<h3>No IDs</h3>
<p>This is more a technical thing, but I have <a href="http://csswizardry.com/2011/09/when-using-ids-can-be-a-pain-in-the-class/">a blanket-ban on IDs in CSS</a>. There is literally no point in them, and they only ever cause harm. Everything that needs styling is done so without using IDs.</p>
<h3>Table of contents</h3>
<p>At the top of my CSS files I have a table of contents that maps to the section titles in the document, it looks a little like:</p>
<pre><code><span class=code-comment>/*------------------------------------*\
    CONTENTS
\*------------------------------------*/</span>
<span class=code-comment>/*
NOTES
RESET
SHARED     Share anything we can across elements.
MAIN       HTML, BODY, etc.
*/</span></code></pre>
<h3>Section titles</h3>
<p>I denote each section (layout, type, tables etc) of my CSS thus:</p>
<pre><code><span class=code-comment>/*------------------------------------*\
    $MAIN
\*------------------------------------*/</span></code></pre>
<p>This section heading is also prepended with a <code>$</code>. This is so that&mdash;when I do a find for a section&mdash;I actually do a find for <code>$MAIN</code> and not <code>MAIN</code>. This means that I’m only ever searching within section headings. A search for <code>$MAIN</code> will only ever find me a section with that name whereas a search for <code>MAIN</code> could find me something like:</p>
<pre><code>.s{
    background-image:url(/img/css/sprites/<mark>main</mark>.png);
}</code></pre>
<p>Being able to search just in the scope of headings is very, very useful.</p>
<p>I also leave five carriage returns between each section, for example:</p>
<pre><code><span class=code-comment>/*------------------------------------*\
    $MAIN
\*------------------------------------*/</span>
&nbsp;
&nbsp;
&nbsp;
&nbsp;
&nbsp;
<span class=code-comment>/*------------------------------------*\
    $TYPE
\*------------------------------------*/</span></code></pre>
<p>This means that when scrolling quickly through my stylesheet I know that any gaps in the code are likely to be new sections.</p>
<h3>The shared section</h3>
<p>I wrote about the shared section briefly on Smashing Magazine in my article <a href=http://coding.smashingmagazine.com/2011/08/26/writing-css-for-others/><cite>Writing CSS for others</cite></a>. This is basically a section in a stylesheet where, instead of declaring one rule over and over, we define it once and attach selectors to it, for example:</p>
<pre><code>a,.brand,h1,h2,h3,h4,h5,h6{
    color:#BADA55;
}
h1,h2,h3,h4,h5,h6,
ul,ol,dl,
p,
table,
form,
pre,
hr{
    margin-bottom:24px;
    margin-bottom:1.5rem;
}</code></pre>
<p>Doing this means that things I want to use over and over are only written once, and I can update all instances in one place. It’s kinda like variables in vanilla CSS&#8230;</p>
<h3>Formatting</h3>
<p>I write multiline CSS with a distinct lack of whitespace that most people seem to hate:</p>
<pre><code>.wrapper{
    margin:0 auto;
    max-width:940px;
    padding:10px;
}</code></pre>
<p>No spaces before braces or after colons.</p>
<h3>Vendor prefixes</h3>
<p>I write vendor prefixes so that the values all line up vertically; this means I can scan them quicker (to check they&#8217;re all identical) and I can alter them all in one go if my editor supports typing in columns:</p>
<pre><code>.island{
    padding:1.5em;
    margin-bottom:1.5em;
    -webkit-border-radius:<mark>4px</mark>;
       -moz-border-radius:<mark>4px</mark>;
            border-radius:<mark>4px</mark>;
}</code></pre>
<h3>Indenting rulesets</h3>
<p>One thing I do like to do is indent my rulesets to mirror the nesting of their corresponding HTML. For example, take this carousel HTML:</p>
<pre><code>&lt;div class=carousel&gt;

    &lt;ul class=panes&gt;

        &lt;li class=pane&gt;

            &lt;h2 class=pane-title&gt;Lorem&lt;/h2&gt;

        &lt;/li&gt;<span class=code-comment>&lt;!-- /pane --&gt;</span>

        &lt;li class=pane&gt;

            &lt;h2 class=pane-title&gt;Ipsum&lt;/h2&gt;

        &lt;/li&gt;<span class=code-comment>&lt;!-- /pane --&gt;</span>

        &lt;li class=pane&gt;

            &lt;h2 class=pane-title&gt;Dolor&lt;/h2&gt;

        &lt;/li&gt;<span class=code-comment>&lt;!-- /pane --&gt;</span>

    &lt;/ul&gt;<span class=code-comment>&lt;!-- /panes --&gt;</span>

&lt;/div&gt;<span class=code-comment>&lt;!-- /carousel --&gt;</span></code></pre>
<p>My CSS for this would be formatted:</p>
<pre><code><span class=code-comment>/*------------------------------------*\
    $CAROUSEL
\*------------------------------------*/</span>
.carousel{
    [styles]
}

    .panes{
        [styles]
    }

        .pane{
            [styles]
        }

            .pane-title{
                [styles]
            }</code></pre>
<p>By doing this, I can see from the CSS roughly how the HTML should look; I don’t need the HTML in front of me in order to work out what lives in what.</p>
<h3>HTML in CSS</h3>
<p>In situations where it <em>would</em> be useful for a developer to know exactly how a chunk of CSS applies to some HTML, I often include a snippet of HTML in a CSS comment, for example:</p>
<pre><code><span class=code-comment>/*------------------------------------*\
    $TOOLTIPS
\*------------------------------------*/</span>
<span class=code-comment>/*
&lt;small class=tooltip&gt;&lt;span&gt;Lorem ipsum dolor&lt;/span&gt;&lt;/small&gt;
*/</span>
.tooltip{
    [styles]
}
    .tooltip &gt; span{
        [styles]
    }</code></pre>
<hr />
<h2>Final word</h2>
<p>For a loose example of the above, poke through <a href=https://github.com/csswizardry/vanilla><cite>vanilla</cite></a> or the <a href=http://hry.rbrts.me>hry.rbrts.me</a> source <a href=https://github.com/csswizardry/hry.rbrts.me>on GitHub</a>.</p>
<p>Just to reiterate, this is my coding <em>style</em>; I’m not making suggestions or laying down rules here. If you like anything then feel free to adopt it yourself, if you hate it then that’s cool (just hope you don’t inherit one of my projects!)</p>
<p>I’d really love if people wrote up and shared their own; there are loads of different ways of writing code and I’d be really interested to see what other people do. There’s a really good opportunity for learning some really neat tips!</p>
<p>If you do write your own, please tweet it at me <strong>with the hashtag <a href="https://twitter.com/#!/search/realtime/%23codestyle">#codestyle</a></strong>, that way everyone can easily keep track of any posts.</p>
<p><strong>Unquoted attributes, no self-closing tags, loads of whitespace, weird CSS indenting and a lot of comments; what&#8217;s yours?</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/04/my-html-css-coding-style/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Introducing faavorite</title>
		<link>http://csswizardry.com/2012/04/introducing-faavorite/</link>
		<comments>http://csswizardry.com/2012/04/introducing-faavorite/#comments</comments>
		<pubDate>Tue, 17 Apr 2012 21:25:51 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[faavorite]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3553</guid>
		<description><![CDATA[Okay, I say ‘introducing’, but it’s been live for almost a month now!
Me and one of my bestest friends and most-talented-developers-ever Nick Payne have been working since the beginning of 2012 on my faavorite project to date: faavorite.
faavorite is, at its heart, a tool for managing your Twitter favorites. You can tag, search, discuss, consume, [...]]]></description>
			<content:encoded><![CDATA[<p>Okay, I say ‘introducing’, but it’s been live for almost a month now!</p>
<p>Me and one of my bestest friends and most-talented-developers-ever <a href="http://twitter.com/makeusabrew">Nick Payne</a> have been working since the beginning of 2012 on my faavorite project to date: <a href="http://faavorite.com">faavorite</a>.</p>
<p>faavorite is, at its heart, <a href="http://faavorite.com">a tool for managing your Twitter favorites. You can tag, search, discuss, consume, read, share (and a lot, lot more) yours and others’ Twitter favorites</a> from right within the app. We’ve put your favorites to work <strong>big time</strong>.</p>
<p><span id="more-3553"></span></p>
<p>We all know how favorites work; you see a funny tweet, something you want to read later, a great code tip or just something that made you smile, and you favorite it. Whilst the intention is good, how often do you head back to your favorites? Twitter don’t really do anything of use with them; you can’t search them, you can sort or categorise them, you can’t <em>really</em> do anything with them…</p>
<p>This is a problem Nick and I really seemed agreed on, and we both wanted to solve it. And, over a few months, that’s what we did, and what we’re still doing.</p>
<p>I aim to do at least one technical post about faavorite pretty soon detailing the mobile-first, OOCSS, designed-in-the-browser, no-IE7-support approach. I want to document the front-end architecture and a few new things in quite a lot of detail but with 101 things on at the moment that will have to wait.</p>
<p>For now I’d like to thank:</p>
<ul>
<li><b><a href="http://twitter.com/makeusabrew">Nick</a></b>, for just being superawesome. He’s worn many hats throughout this project, including—but not limited to—developer, DevOps, SysAdmin, hotelier, barista and a whole host more. You can read <a href="http://paynedigital.com/2012/04/faavorite-tech-stack">his impressive and mind-boggling technical writeup</a> of the app at your own <del>risk</del> will.</li>
<li><b><a href="http://twitter.com/lucybest">Lucy</a></b>, Nick’s girlfriend, for putting up with me seeing Nick more than she now gets to, and for cooking up some ace meals during our full-weekend coding sessions.</li>
<li><b><a href="http://twitter.com/WengersToyBus">Bryan James</a></b>, the guy who created the faavorite brand. It’s a thing of beauty, I’m sure you’ll agree.</li>
<li><strong>You guys!</strong> The users, the people who’ve given feedback and suggestions and who’ve generally made the project worthwhile.</li>
</ul>
<p>If you’ve not signed up already but use Twitter then I encourage you to give it a whirl; it’s free and, well, I think it’s pretty awesome: <a href="http://faavorite.com">faavorite.com</a></p>
<p>Oh and one other thing; if you’re already in (and like) faavorite, please consider inviting your friends along. Content is better shared and the more the merrier. We really need to get some non-web-geeks in faavorite as soon as possible in order to diversify (and not seem like an app just for web dev types) so if you have any friends on Twitter who might be interested then please do send them our way! Happy faavoriting!</p>
<p>Cheers,<br />
<i>H</i></p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/04/introducing-faavorite/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Comments on CSS Wizardry</title>
		<link>http://csswizardry.com/2012/04/comments-on-css-wizardry/</link>
		<comments>http://csswizardry.com/2012/04/comments-on-css-wizardry/#comments</comments>
		<pubDate>Mon, 16 Apr 2012 08:08:07 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[CSS Wizardry]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3551</guid>
		<description><![CDATA[Hi guys, long time no speak. I&#8217;ve been absolutely rushed off my feet of late with 101 other things. CSS Wizardry&#8212;although it hasn&#8217;t been updated in far too long&#8212;has had a massive surge of comment spam. Massive :(
I can&#8217;t pick through 6,000+ comments looking for the odd real one so I&#8217;m gonna blitz them all [...]]]></description>
			<content:encoded><![CDATA[<p>Hi guys, long time no speak. I&#8217;ve been absolutely rushed off my feet of late with 101 other things. CSS Wizardry&mdash;although it hasn&#8217;t been updated in far too long&mdash;has had a massive surge of comment spam. Massive :(</p>
<p>I can&#8217;t pick through 6,000+ comments looking for the odd real one so I&#8217;m gonna blitz them all and if you have left a comment which hasn&#8217;t made it live just let me know and I&#8217;ll reinstate it.</p>
<p>Cheers, and sorry,<br />
<i>H</i></p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/04/comments-on-css-wizardry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hacker News rebuttal</title>
		<link>http://csswizardry.com/2012/03/hacker-news-rebuttal/</link>
		<comments>http://csswizardry.com/2012/03/hacker-news-rebuttal/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 01:29:12 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[Hacker News]]></category>
		<category><![CDATA[OOCSS]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3523</guid>
		<description><![CDATA[Yesterday I decided to post on Hacker News something I’ve recently been working on for both myself and Sky. That something was a list of guidelines as to how best write CSS for manageable and maintainable projects.
Unfortunately, a number of the HN community didn’t take so well to my points so I’ve decided to publish [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday <a href="http://news.ycombinator.com/item?id=3693610">I decided to post on Hacker News something I’ve recently been working on for both myself and Sky</a>. That something was a list of <a href="https://github.com/csswizardry/CSS-Guidelines/blob/master/CSS%20Guidelines.md">guidelines as to how best write CSS for manageable and maintainable projects</a>.</p>
<p>Unfortunately, a number of the HN community didn’t take so well to my points so I’ve decided to publish a full response, as opposed to the disjointed and frankly unprofessional comment discussion that was emerging.</p>
<p>One user in particular took exception to a lot of my advice and it is his issues I shall address most directly. This isn’t a vendetta at all, more my trying to answer his and others’ concerns at large. He offered a pretty 1:1 comeback to a lot of my points so I shall try to maintain a similar format here.</p>
<p>I may paraphrase a lot here so I urge you, <strong><a href="http://news.ycombinator.com/item?id=3693610">please, read the original thread</a></strong>. I apologise and regret and instances in which I come across as rude and/or unprofessional; I acted on impulse rather than rationally, as I should have done.</p>
<hr />
<p>I said:</p>
<blockquote>
<p>”For each level of markup nesting, try and indent your CSS to match.”</p>
</blockquote>
<p>He said:</p>
<blockquote>
<p>“Nope.”</p>
</blockquote>
<p>Indenting CSS to mirror your markup structure can be very useful for a number of reasons, chief among which is the ability to see <em>at a glance</em> how the listed CSS selectors should be used in HTML. For example, when building a carousel, I often find myself with CSS selectors like:</p>
<pre><code>.carousel{}
.panes{}
.pane{}
.slide-image{}
.slide-title{}
</code></pre>
<p>As these selectors are only one class deep it is difficult to see at a glance how they might map to my HTML. One solution might be to write my CSS like so:</p>
<pre><code>.carousel{}
.carousel .panes{}
.carousel .panes .pane{}
.carousel .panes .pane .slide-image{}
.carousel .panes .pane .slide-title{}
</code></pre>
<p>But of course you don’t need me to tell you how nasty that is…</p>
<p>Instead, I prefer a structure more like:</p>
<pre><code>.carousel{}
    .panes{}
        .pane{}
            .slide-image{}
            .slide-title{}
</code></pre>
<p>Here my selectors are still nice and short but I can still see how they map to my HTML structure. I find this really useful to see at a glance how these rules relate to one another.</p>
<p>If you don’t like this, or won’t find it useful, that’s cool! Just don’t use it.</p>
<hr />
<p>I said:</p>
<blockquote>
<p>“Also write vendor prefixed CSS so that colons all line up”</p>
</blockquote>
<p>He said:</p>
<blockquote>
<p>“Nope”</p>
</blockquote>
<p>I really have no idea why you wouldn’t do this one. It’s often been proposed that we should write vendor prefixed CSS thus:</p>
<pre><code>-webkit-border-radius:4px;
   -moz-border-radius:4px;
        border-radius:4px;
</code></pre>
<p>This means all our values—the bits that matter the most—are lined up to a) scan quickly and b) edit at once with columnal typing (in text editors which support it). This, to me, is a <a href="http://www.google.co.uk/search?sourceid=chrome&amp;ie=UTF-8&amp;q=define%3Ano-brainer">no-brainer</a> and a very quick-win.</p>
<hr />
<p>I said:</p>
<blockquote>
<p>“Instead of building dozens of unique components, try and spot repeated design patterns abstract them; build these skeletons as base ‘objects’ and then peg classes onto these to extend their styling for more unique circumstances.”</p>
</blockquote>
<p>He said:</p>
<blockquote>
<p>[Not unless you are a big website like Facebook]</p>
</blockquote>
<p>It doesn’t matter if you are working on the next Facebook or for some guy from the pub, if you can build a website from several repeated components you should. From a performance, consistency, maintainability and sheer sensibility point of view, don’t solve the same problem a dozen times when you can solve it once with an abstraction.</p>
<p>Best practices are best practices, the size of a project is irrelevant.</p>
<hr />
<p>I said:</p>
<blockquote>
<p>“All components should be left totally free of widths; your components should always remain fluid and their widths should be governed by a grid system.”</p>
</blockquote>
<p>He said:</p>
<blockquote>
<p>“Nope. Again, grid systems are something that should be used on a case-by-case basis, according to the nature of the site you&#8217;re building.”</p>
</blockquote>
<p>Here I made something of a mistake; when I say grid system what I actually mean is <em>any</em> means of abstracting your layout into its own layer.</p>
<p>If this <em>is</em> a grid system then this is simple; a grid system handles your layout and your components fill it.</p>
<p>If you are not using a grid system then wrapper and parent elements should handle layout and the components should still say fluid. As I said on Twitter just three days prior to this:</p>
<blockquote>
<p>“Box-model properties are the most fragile and unpredictable and thus should be avoided wherever you can. Leave layout to wrappers/parents…” (<a href="https://twitter.com/csswizardry/status/178062012742504448">#</a>)</p>
</blockquote>
<p>And:</p>
<blockquote>
<p>“When sites break it‘s usually because of layout—the less layout stuff we declare the less chance it has to break. Abstract layout to grids!” (<a href="https://twitter.com/csswizardry/status/178063631265710080">#</a>)</p>
</blockquote>
<p>Whether using a grid system or not, your components should not carry dimensions. Think of a page like a set of shelves; you set up your shelving units (grid system (or similar)) and then populate them with things (components). If you didn’t have the shelves erected then the components would be supporting themselves, holding themselves up; this makes moving or changing them very volatile.</p>
<p>Abstract your layout to wrappers, parents or grid systems, always.</p>
<hr />
<p>I said:</p>
<blockquote>
<p>“Heavily location-based selectors are bad for a number of reasons.”</p>
</blockquote>
<p>He said:</p>
<blockquote>
<p>“Nope. What you&#8217;re arguing against is a rule that has a high degree of specificity…”</p>
</blockquote>
<p>I’m not; I’m talking about location based styling. As soon as an elements begins to rely on its parent, and their parent, and their parent’s parent then you are doing it wrong. Your styles should never rely too heavily on where they live as this makes them <em>incredibly</em> unportable.</p>
<p>Putting classes on the elements you wish to affect rather than drilling down to them via the DOM tree is a lot better in terms of portability in that you don’t have to rely on a location in order to set styles. This one really is a <a href="http://www.google.co.uk/search?sourceid=chrome&amp;ie=UTF-8&amp;q=define%3Ano-brainer">no-brainer</a> for me…</p>
<hr />
<p>I said:</p>
<blockquote>
<p>“An over-qualified selector is one like div.promo”</p>
</blockquote>
<p>He said:</p>
<blockquote>
<p>[This is actually a good idea unless you want a class to be applicable to any element]</p>
</blockquote>
<p>Erm, yes please! Ideally classes are applicable to any element; classes should be element-agnostic. The ability to apply them to any element we wish is <em>exactly</em> what we want.</p>
<p>Why would you ever, <em>ever</em> write <code>div.promo{}</code> in your stylesheet if that could be left at <code>.promo{}</code>?! Why would you <em>ever</em> limit yourself to only being able to use a class on one type of element when you could leave the leading type selector off and have an element-agnostic rule?</p>
<p>This is another <a href="http://www.google.co.uk/search?sourceid=chrome&amp;ie=UTF-8&amp;q=define%3Ano-brainer">no-brainer</a> to me. Don’t tie yourself to things when you really just don’t need to. I think we can all agree that <code>.promo{}</code> is a lot more (re)usable than <code>div.promo{}</code>. By tying an element to any class you are the only thing that will hinder you going forward; you are preemptively closing a lot of doors on yourself…</p>
<hr />
<p>I said:</p>
<blockquote>
<p>“Do not use IDs in CSS at all.”</p>
</blockquote>
<p>He said:</p>
<blockquote>
<p>“NOPE NOPE NOPE NOPE NOPE. Understand specificity rules. Write good selectors. Don&#8217;t outright ban IDs just because you&#8217;re not careful enough to write clean CSS.”</p>
</blockquote>
<p>I’m pretty sure no CSS developer has ever said ‘I wish I’d used an ID here instead of a class.’</p>
<p>IDs work, sure, but they are way too specific. It doesn’t matter how good a developer you are, you cannot change the fact that an ID is massively more specific than a class.</p>
<p>I would genuinely love to see an elegant solution to <a href="http://jsfiddle.net/csswizardry/3sxZR/">this</a> that doesn’t use a class over an ID. <small>(<a href=http://csswizardry.com/2011/09/when-using-ids-can-be-a-pain-in-the-class/>There isn&#8217;t one.</a>)</small></p>
<p>There is literally <em>no</em> reason why, from a purely CSS point of view, that an ID is better than a class. An ID is impossible to reuse (whether you want to or not) and they have a way-over-the-top specificity.</p>
<p>Anything you can do with an ID can be done with a class, but with none of the drawbacks. IDs will only ever trip you up because you can never reuse them and they will trump your class-based-selectors by quite an order of magnitude.</p>
<p>Classes; all the bits you love about IDs with none of the bits that are like IDs.</p>
<p>To me, another <a href="http://www.google.co.uk/search?sourceid=chrome&amp;ie=UTF-8&amp;q=define%3Ano-brainer">no-brainer</a>.</p>
<hr />
<p>I said:</p>
<blockquote>
<p>“As a general rule, all layout and box-model rules can and will work without an IE stylesheet if you refactor and rework your CSS.”</p>
</blockquote>
<p>He said:</p>
<blockquote>
<p>“Hahahahahahahahahhaa”</p>
</blockquote>
<p>I was the sole CSS developer on <a href="http://skybet.com">Sky Bet</a>. This project (as a whole) has taken over a year for the whole team involved (and almost a year of my dev time).</p>
<p>To support IE7+ I used all of zero IE stylesheets. Not one. A project which took me almost a year did not require one single IE stylesheet. It is doable, it should be done.</p>
<p>I haven’t written an IE stylesheet in all of my professional career. I started working when I was 18 so that makes three years; I haven’t written an IE stylesheet in over three years. It’s not that hard, seriously.</p>
<p>To just laugh off such a statement seemed a little odd, but seriously, if you invest enough time and take enough care, you will not need an IE stylesheet.</p>
<hr />
<p>Like I said in <a href="https://github.com/csswizardry/CSS-Guidelines/blob/master/README.md">the documents’s README</a>, you can disregard the advice if you wish, but make sure you fully understand it before shunning it completely.</p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/03/hacker-news-rebuttal/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Pragmatic, practical font sizing in CSS</title>
		<link>http://csswizardry.com/2012/02/pragmatic-practical-font-sizing-in-css/</link>
		<comments>http://csswizardry.com/2012/02/pragmatic-practical-font-sizing-in-css/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 23:49:06 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[DRY]]></category>
		<category><![CDATA[OOCSS]]></category>
		<category><![CDATA[Typography]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3496</guid>
		<description><![CDATA[One thing I&#8217;ve been thinking a lot about lately is how to build sites properly. Not what we have been told is proper, but what actually makes sense for us as developers. I recently spoke at The Digital Barn on exactly this; my talk—Breaking Good Habits—dealt with how we as developers need to solve problems [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I&#8217;ve been thinking a lot about lately is how to build sites properly. Not what we have been <em>told</em> is proper, but what actually makes sense for us as developers. I recently spoke at <a href="http://thedigitalbarn.co.uk/"><cite>The Digital Barn</cite></a> on exactly this; my talk—<cite>Breaking Good Habits</cite>—dealt with how we as developers need to solve problems not only for our users and clients, but for ourselves as well.</p>
<p><a href="http://twitter.com/stubbornella">Nicole Sullivan</a>—who totally rocks—has laid a lot of new foundations for us in her work on <a href="http://oocss.org">OOCSS</a> and her &#8216;unconventional&#8217; but absolutely spot-on approach to building websites. Gems like <a href="http://www.stubbornella.org/content/2010/06/25/the-media-object-saves-hundreds-of-lines-of-code/"><i>the media object</i></a> have seriously changed how I build websites and, if you take the time to study it for yourself, I think it might just do the same for you as well.</p>
<h2>Double-stranded heading hierarchy</h2>
<p>Another absolutely stellar nugget of wisdom she&#8217;s given us is what I call <i>double-stranded heading hierarchy</i>. This is the practice of defining a class every time you define a heading in CSS.</p>
<p>For example, if&mdash;for whatever reason&mdash;we want our <code>h2</code>s in our sidebar to be the same size as a <code>h1</code>, and the <code>h4</code>s in our footer to be the same size as a <code>h3</code>, we might have had some code like this:</p>
<pre><code>&lt;div class=content&gt;
  &lt;h1&gt;Lorem&lt;/h1&gt;
&lt;/div&gt;

&lt;div class=sub-content&gt;
  &lt;h2&gt;Lorem&lt;/h2&gt;
&lt;/div&gt;

&lt;div class=footer&gt;
  &lt;h4&gt;Lorem&lt;/h4&gt;
&lt;/div&gt;

h1,
.sub-content h2{ [font styles] }
h2{ [font styles] }
h3,
.footer h4{ [font styles] }
h4{ [font styles] }
h5{ [font styles] }
h6{ [font styles] }</code></pre>
<p>But now we&#8217;d have:</p>
<pre><code>&lt;div class=content&gt;
  &lt;h1&gt;Lorem&lt;/h1&gt;
&lt;/div&gt;

&lt;div class=sub-content&gt;
  &lt;h2 class=h1&gt;Lorem&lt;/h2&gt;
&lt;/div&gt;

&lt;div class=footer&gt;
  &lt;h4 class=h3&gt;Lorem&lt;/h4&gt;
&lt;/div&gt;

h1,.h1{ [font styles] }
h2,.h2{ [font styles] }
h3,.h3{ [font styles] }
h4,.h4{ [font styles] }
h5,.h5{ [font styles] }
h6,.h6{ [font styles] }</code></pre>
<p>As you can see, the former is far more arbitrary and those lists of selectors can soon become unwieldy, especially over a larger project. By assigning a class along with each heading style we now have those styles attached to a very flexible selector that can be moved anywhere, rather than to a very specific and non-movable one.</p>
<p>Now, I&#8217;m not such a fan of the <code>.hN</code> notation, I much prefer a solution that I <em>believe</em> to have been suggested by Mr Jeremy Keith, and that is to use abstract classes made up of the first six letters of the Greek alphabet, thus:</p>
<pre><code>h1,.alpha   { [font styles] }
h2,.beta    { [font styles] }
h3,.gamma   { [font styles] }
h4,.delta   { [font styles] }
h5,.epsilon { [font styles] }
h6,.zeta    { [font styles] }</code></pre>
<p>Which now gives us:</p>
<pre><code>&lt;div class=content&gt;
  &lt;h1&gt;Lorem&lt;/h1&gt;
&lt;/div&gt;

&lt;div class=sub-content&gt;
  &lt;h2 class=alpha&gt;Lorem&lt;/h2&gt;
&lt;/div&gt;

&lt;div class=footer&gt;
  &lt;h4 class=gamma&gt;Lorem&lt;/h4&gt;
&lt;/div&gt;</code></pre>
<p>Neat, huh?</p>
<p>So now <code>.alpha</code> can carry the style information of a <code>h1</code> wherever you wish; it doesn&#8217;t depend on location <em>or</em> a type of element. A double-stranded heading hierarchy; lovely.</p>
<h2>Extending this?</h2>
<p>Okay, so now we have our heading styles all nice and portable we&#8217;ve won most of the battle. I&#8217;ve been using this method for months now and I <em>love</em> it. My CSS is so much more efficient, more portable, more powerful, I can build faster, I&#8217;m not repeating font styles over and over, but what next?</p>
<p>The other night whilst working on <a href="http://faavorite.com">faavorite</a> with <a href="http://twitter.com/makeusabrew">Nick</a> I came up with a full on font-sizing micro-framework.</p>
<p>The problems I found I had with font-sizing on <em>any</em> site include (but are not limited to):</p>
<ul>
<li>Repetition of <code>font-size</code>, <code>line-height</code> etc declarations.</li>
<li>Overly-specific and/or location-dependent selectors (e.g. <code>.sidebar h2{}</code>).</li>
<li>Arbitrary font sizes could and <em>did</em> creep into my CSS.</li>
<li>When using <code>rem</code> with <code>px</code> fallbacks, there is a lot to type!</li>
</ul>
<p>And a few important things to remember:</p>
<ul>
<li>Font sizes, like colour palettes, should be limited, preset and non-arbitrary.</li>
<li>Vertical rhythm is important and easy.</li>
<li>DRY code is important for both efficiency and maintainability.</li>
<li>It&#8217;s important to save yourself as much time as possible.</li>
<li>Classes are neither semantic or insemantic.</li>
</ul>
<p>With this in mind, I decided that I wanted to use font-sizing much like a grid system; define it once in the stylesheet and just constantly reuse it.</p>
<h3>Preset font sizes</h3>
<p>Like colour palettes are, font sizes should be strict, predefined and intentional. From both a code and design point of view, you shouldn&#8217;t deviate from your scale—you shouldn&#8217;t really ever need to and doing so will just make code harder to work with.</p>
<p>Presetting your font sizes is pretty easy; typically you might have requirements for:</p>
<ul>
<li>Normal body copy</li>
<li>Headings 1–6</li>
<li>Small print</li>
<li>A few other sizes for larger-than-normal headings etc.</li>
</ul>
<p>Setting the base font size is simple, just pop it on the <code>html</code> and everything will inherit it, paragraphs, lists, tables, you name it.</p>
<p>For your headings you define a series of <code>hN</code> and its corresponding Greek letter class, e.g. <code>h1,.alpha{}</code>.</p>
<h3>Non-standard font-sizing</h3>
<p>You ever had that need to turn a design <a href="http://www.youtube.com/watch?v=EbVKWCpNFhY">up to 11</a>? When you have a masthead promo and even a <code>h1</code> ain&#8217;t big enough? I think we all have…</p>
<p>It&#8217;s tempting to create a new, unique selector to cater for this new requirement, perhaps something like:</p>
<pre><code>.masthead h1{ font-size:5em; }</code></pre>
<p>And whilst this will work, you&#8217;ll only ever get that 5em goodness if you use <em>specifically</em> a <code>h1</code> that is <em>specifically</em> in a <code>.masthead</code>. This isn&#8217;t very reusable at all. Sadface.</p>
<p>To combat this, I decided to create some new abstract classes, this time borrowing <a href="http://en.wikipedia.org/wiki/SI_prefix">SI prefixes</a>. Now we have the <code>h1,.alpha{}</code> through to <code>h6,.zeta{}</code> that we did before, but as well as those we have:</p>
<pre><code>.giga{ [font styles] }
.mega{ [font styles] }
.kilo{ [font styles] }</code></pre>
<p>These classes are the ones <em>above</em> <code>h1</code> and are the seldom used ones that make stuff massive!</p>
<h3>Going the other way?</h3>
<p>Okay, so far we&#8217;ve worked with body copy to headings to beyond; what about small print? Well I opted to use:</p>
<pre><code>small,<del datetime="2012-03-01T00:00:16+00:00">.omega</del><ins datetime="2012-03-01T00:00:16+00:00">.milli</ins>{ [font styles] }</code></pre>
<p><a href="http://csswizardry.com/2011/01/html5-and-text-level-semantics/#small-el"><code>small</code> has been redefined in HTML5</a> so that&#8217;s an element we can use again freely<del datetime="2012-03-01T00:00:16+00:00"> and <code>.omega</code> is simply the last letter in the Greek alphabet</del>.</p>
<h4 id="lets-use-milli"><ins datetime="2012-03-01T00:06:30+00:00">Addendum</ins></h4>
<p>That there genius and awesome chap <a href="http://twitter.com/TomNomNom">Tom Hudson</a> suggested I use <code>.milli</code> for this as it goes <em>below</em> the regular scale. So, anything <em>on</em> the normal scale is Greek letters, anything <em>off</em> the scale (above or below) is SI prefixes.</p>
<h3>Vertical rhythm</h3>
<p>To maintain vertical rhythm we need two key ingredients; consistent line heights and consistent bottom margins. We need a <a href="http://coding.smashingmagazine.com/2011/03/14/technical-web-typography-guidelines-and-techniques/#tt-magic-number">magic number</a>. This number is typically defined by the line height of your body copy, so if you have <code>html{ font-size:16px; line-height:1.5; }</code> then your magic number is 16 x 1.5 = <strong>24</strong>.</p>
<p>Now you know that all your line heights and margin bottoms <em>have</em> to be a multiple of 24px.</p>
<h2>Bringing it together</h2>
<p>It really is imperative to take a look at an actual example of all the above brought together in order to fully &#8216;get&#8217; it. I made <a href="https://bitly.com/xxiqfm">this jsFiddle demo</a> of <em>just</em> CSS; you can add HTML and tinker with it yourselves, combining elements with classes to create double stranded, portable font sizing framework stuff!</p>
<h2>Where does that leave us?</h2>
<p>We now have a self-contained font-sizing framework which should hopefully mean we never need to define another <code>font-size</code> declaration again! We can manage our brand specific type rules from one place, we can build stuff faster, we can build faster stuff, we can keep our code DRYer, we can keep our styling a lot more consistent, we can keep styling location <em>in</em>dependent and we can make far reaching changes in one fell-swoop!</p>
<p>Feel free to take the code and modify or improve it.</p>
<p>Also please note that I am not suggesting we all use these specific classes; experiment, find your own, see what you&#8217;re comfortable with and report back!</p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/02/pragmatic-practical-font-sizing-in-css/feed/</wfw:commentRss>
		<slash:comments>47</slash:comments>
		</item>
		<item>
		<title>Breaking Good Habits—The Digital Barn</title>
		<link>http://csswizardry.com/2012/02/breaking-good-habits-the-digital-barn/</link>
		<comments>http://csswizardry.com/2012/02/breaking-good-habits-the-digital-barn/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 12:36:11 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[Speaking]]></category>
		<category><![CDATA[Breaking Good Habits]]></category>
		<category><![CDATA[Conference]]></category>
		<category><![CDATA[The Digital Barn]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3491</guid>
		<description><![CDATA[Yesterday—11 February, 2012—I gave my first talk ever to the attendees of The Digital Barn, a small independent conference organised by Matt Watson and Kimb Jones.
My talk, Breaking Good Habits, took a look at how we as front-end developers often, and usually with the best of intentions, solve the wrong problems for the wrong people, [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday—11 February, 2012—I gave my first talk ever to the attendees of <a href="http://thedigitalbarn.co.uk/"><cite>The Digital Barn</cite></a>, a small independent conference organised by <a href="http://about.me/mwatson">Matt Watson</a> and <a href="http://mkjones.co.uk/">Kimb Jones</a>.</p>
<p>My talk, <cite>Breaking Good Habits</cite>, took a look at how we as front-end developers often, and usually with the best of intentions, solve the wrong problems for the wrong people, causing ourselves maintainability nightmares in the name of &#8216;best practice&#8217;.</p>
<p>I looked at common misconceptions and offered more practical and sensible alternatives in the shape of OOCSS, and more.</p>
<p>I&#8217;d really like to thank everyone that turned up, but specific thanks go to:</p>
<ul>
<li><b><a href="http://twitter.com/makeusabrew">Nick Payne</a></b>—moral support (and chauffeur).</li>
<li><b><a href="http://about.me/mwatson">Matt</a> and <a href="http://mkjones.co.uk/">Kimb</a></b>—for organising the event and providing me with such a great opportunity.</li>
<li><b><a href="http://twitter.com/brucel">Bruce Lawson</a></b>—for being an absolute gent, easing my nerves before the talk and saying nice things about it afterward.</li>
<li><b><a href="http://twitter.com/stubbornella">Nicole Sullivan</a></b>—for changing the way I build websites and giving me, indirectly, knowledge I was able to share in my talk.</li>
</ul>
<h2>Slides</h2>
<p>My slides and personal notes are available online but if you are going to <a href="http://2012.front-trends.com/">Front-Trends 2012</a> I implore you <strong>please do not look at them</strong>. I shall be reworking/repurposing this talk for my appearance in Warsaw.</p>
<ul>
<li><a href="http://speakerdeck.com/u/csswizardry/p/breaking-good-habits">Slides on Speaker Deck</a></li>
<li><a href="https://github.com/csswizardry/Talks/tree/master/Digital%20Barn%202012">Notes and original Keynote file on GitHub</a></li>
</ul>
<p>Thanks all who turned out, I hope you enjoyed yourselves. I thoroughly enjoyed myself, and The North needs more mini-conferences!!!</p>
<p>For more info on the conference itself the super-awesome <a href="http://twitter.com/leannebuchan">Leanne Buchan</a> did <a href="http://theculturevulture.co.uk/blog/digital-design/a-digital-conference-in-the-metropolis/">a feature with me on <cite>The Culture Vulture</cite></a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2012/02/breaking-good-habits-the-digital-barn/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>On HTML and CSS best practices</title>
		<link>http://csswizardry.com/2011/12/on-html-and-css-best-practices/</link>
		<comments>http://csswizardry.com/2011/12/on-html-and-css-best-practices/#comments</comments>
		<pubDate>Sun, 11 Dec 2011 12:15:26 +0000</pubDate>
		<dc:creator>Harry Roberts</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://csswizardry.com/?p=3457</guid>
		<description><![CDATA[Best practices are exactly that; best. Not &#8216;better&#8217;, not &#8216;good when&#8230;&#8217; or &#8216;best if&#8230;&#8217;, just best. They&#8217;re always the best, no matter what.
This is something I learned whilst undertaking the single biggest project of my career so far; the complete (and not-yet-live) rebuild of one of BSkyB&#8217;s most trafficked websites. For years I&#8217;d been working [...]]]></description>
			<content:encoded><![CDATA[<p>Best practices are exactly that; <em>best</em>. Not &#8216;better&#8217;, not &#8216;good when&hellip;&#8217; or &#8216;best if&hellip;&#8217;, just best. They&#8217;re always the best, no matter what.</p>
<p>This is something I learned whilst undertaking the single biggest project of my career so far; the complete (and not-yet-live) rebuild of one of BSkyB&#8217;s most trafficked websites. For years I&#8217;d been working on medium-sized projects where I strove to use as few classes as possible, my CSS was so elegant and hand-crafted and everything used the cascade. I thought it was beautiful.</p>
<p>I found my old approach isn&#8217;t best practice when working on a big site, therefore it&#8217;s not best practice at all&hellip; You can scale down the big site mentality to smaller builds, you can&#8217;t scale up small site mentality to bigger ones. With this in mind, how you&#8217;d build bigger sites is best practice, how you tend to build smaller sites is <em>typically</em> (though, as ever, not always) based on fallacy and myth.</p>
<p><span id="more-3457"></span></p>
<p>I recently rebuilt my friend <a href="http://sampenrose.co.uk/">Sam&#8217;s design portfolio site</a>. Typically I&#8217;d have used IDs everywhere, not used any OO and not really paid much attention to the length or efficiency of my CSS selectors. This would have worked but only because the site is small. Any attempts by Sam to scale the site up, add pages, move components or alter the layout would have been hampered by these methods. Instead I decided to apply big-site mentality and dropped any IDs, used an OO approach and made sure every component is reusable. <a href="https://github.com/csswizardry/sampenrose.co.uk">The resulting code</a> is incredibly flexible, very efficient and still looks nice.</p>
<ul>
<li>OOCSS is <em>always</em> best practice.</li>
<li>DRY is <em>always</em> best practice.</li>
<li>Efficiency is <em>always</em> best practice.</li>
<li>Maintainability is <em>always</em> best practice.</li>
<li>Flexibility is <em>always</em> best practice.</li>
</ul>
<p>It doesn&#8217;t matter if you&#8217;re building the next Facebook or if it&#8217;s just a site for the builder down the road; best practice is always best. You might not notice an inefficient selector on a small site, but it doesn&#8217;t mean that it&#8217;s not still inefficient. Just because you don&#8217;t notice something it doesn&#8217;t mean it&#8217;s not still happening.</p>
<p>Build every site like it&#8217;s a 1000 page behemoth because then it can scale; it may never need to, but it <em>can</em>. Building every site like it&#8217;s a piece of art, using convoluted selectors and rigid, ID ridden code, it can never scale, even if you want it to.</p>
<p>Your code might look like the <a href="http://en.wikipedia.org/wiki/Sistine_Chapel">Sistine Chapel</a>, but if it&#8217;s a chore to maintain, or you find you can&#8217;t pick up a component and drop it anywhere with zero worry, then it&#8217;s not powerful. Code is about power before prettiness. You might feel dirty at first, but when you realise how nicely things fall into place using proper best practices you&#8217;ll see the benefits.</p>
<p>The only person who cares how pretty your code is is you. Your users want fast UIs, your clients want reliable builds and you and your team want code that is easy to maintain 6 months and a dozen client mind-changes down the line.</p>
<p><strong>Best always means best, it has no caveats or conditions.</strong></p>
<h2>Further reading</h2>
<ul>
<li><a href="http://www.lukew.com/ff/entry.asp?1379"><cite>Our Best Practices are Killing Us</cite></a> by Nicole Sullivan</li>
<li><a href="http://oocss.org/">OOCSS.org</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://csswizardry.com/2011/12/on-html-and-css-best-practices/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>

