<?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>Web Designer Notebook &#187; CSS</title>
	<atom:link href="http://webdesignernotebook.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://webdesignernotebook.com</link>
	<description>Web Designer Notebook is a blog for web designers featuring topics like CSS, HTML and Wordpress, tutorials, reviews and inspiration.</description>
	<lastBuildDate>Mon, 06 Sep 2010 19:28:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>My thoughts on LESS</title>
		<link>http://webdesignernotebook.com/css/my-thoughts-on-less/</link>
		<comments>http://webdesignernotebook.com/css/my-thoughts-on-less/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 00:10:36 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=1327</guid>
		<description><![CDATA[I’ve started using LESS a few months ago on a few projects. LESS allows you to extend the way you write CSS, letting you use variables, nested selectors, operations and mixins. It sounds great — and it is great — but there are a few things that can make it work against you. These are [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve started using <a href="http://lesscss.org/" rel="nofollow" >LESS</a> a few months ago on a few projects. LESS allows you to extend the way you write CSS, letting you use variables, nested selectors, operations and mixins. It sounds great — and it <em>is</em> great — but there are a few things that can make it work against you. These are some of my thoughts on LESS.</p>
<p><span id="more-1327"></span></p>
<h3>What is LESS?</h3>
<p>LESS — Leaner CSS — is, in the <a href="http://www.usabilitypost.com/2009/06/16/introducing-less-a-better-css/" rel="nofollow" >authors&#8217; own words</a>, a “<strong>new version of CSS</strong>” (better yet, of writing CSS), that is then compiled into “traditional” CSS using the LESS compiler.</p>
<p>There are 4 main things you can do with LESS that you can’t with normal CSS:</p>
<h4>1. Variables</h4>
<p>You can define a variable, such as “<code>@text-color</code>”, and use it throughout your stylesheet. If the colour of your text changes, you only need to change it once in your CSS — where the variable is initially defined.</p>
<h4>2. Nested selectors</h4>
<p>With nested selectors, instead of doing this and repeating yourself:</p>
<pre class="brush: css;">aside h1 { font-size: 24px; }
aside h2 { font-size: 18px; }</pre>
<p>You can have:</p>
<pre class="brush: css;">aside {
	h1 { font-size: 24px; }
	h2 { font-size: 18px; }
}</pre>
<h4>3. Operations</h4>
<p>You can add, subtract, divide and multiply using operations. Here’s a quick example:</p>
<pre class="brush: css;">@wrappers: 600px;

aside {
    width: @wrappers / 2;
}</pre>
<p>This is definitely not the best example, but it should be enough for you to get the point.</p>
<h4>4. Mixins</h4>
<p>Mixins work a lot like variables, but you can specify a whole class in one. For example:</p>
<pre class="brush: css;">.b-radius {
	-moz-border-radius: 5px;
	-webkit-border-radius: 5px;
	border-radius: 5px;
}

.box {
	.b-radius;
}</pre>
<p>From these examples, I suppose you can say that <em>LESS is actually more</em>. (I’m sorry, I couldn’t help myself.)</p>
<h3>This is not a &#8220;how to&#8221; guide</h3>
<p>The <a href="http://lesscss.org/docs" rel="nofollow" >official LESS documentation</a> is very clear on how to install it. I have to admit I usually stop reading instructions whenever &#8220;Terminal&#8221; is mentioned (and I know more people do), but I guess most CSS authors will be OK with it — if not, ask for help to your nearest web dev (or email me and I’ll give you the phone number of one).</p>
<p>After it’s installed, you’ll have <strong>two files</strong>: the .less file — this is the file you&#8217;ll be working with — and the compiled .css file.</p>
<p>There&#8217;s also <a href="http://incident57.com/less/" rel="nofollow" >LESS app</a>, that makes it easier to use LESS. And I suppose that some CMS and servers let you use LESS directly, but the point of this article is not to teach anyone how to install it — it&#8217;s to go through its good and bad points.</p>
<p>On to the important bit…</p>
<h3>How LESS can make your life easier</h3>
<p>This is a list of things that, in my opinion, <strong>make LESS worthwhile</strong> and can really simplify your CSS. These are the things that I usually miss the most when I’m not working on LESS files.</p>
<h4>1. Variables</h4>
<p>Surely when you are writing your CSS there are colours, measurements, etc. that you <strong>keep using over and over</strong>. For example, let&#8217;s say your brand colour is jade (very fashionable for Spring/Summer 2010). You may use it on various elements in your design, for example, the main text:</p>
<pre class="brush: css;">body {
    …
    color: #77b59d;
    …
}</pre>
<p>Or the borders of your posts:</p>
<pre class="brush: css;">article {
    …
    border-bottom: 1px solid #77b59d;
    …
}</pre>
<p>Or as the background of your footer:</p>
<pre class="brush: css;">footer {
    …
    background-color: #77b59d;
    …
}</pre>
<p>If someone has to edit the CSS file and doesn&#8217;t know exactly which colour he or she is supposed to be using — it may even be you a few months later —, what happens is that either you&#8217;ll spend some time scanning through the document until you find the colour, you&#8217;ll use Firebug or, if you like to complicate things, use xScope or take a screenshot and use Photoshop to detect the colour.</p>
<p>This is silly. You&#8217;ll end up with many similar colours instead of just one. (As a note, Dreamweaver lists all the colours that a site is using — you&#8217;d be surprised at how inconsistent some CSS authors can be when applying colour.)</p>
<p>Another thing that may happen is when you actually want to change this colour throughout your stylesheet: <strong>you&#8217;ll have to edit every instance of it</strong> — that&#8217;s painful.</p>
<p>With a variable, you can have this:</p>
<pre class="brush: css;">@main-color: #77b59d;

body {
    …
    color: @main-color;
    …
}

article {
    …
    border-bottom: 1px solid @main-color;
    …
}

footer {
    …
    background-color: @main-color;
    …
}</pre>
<p>Beware though: you can easily <strong>go overboard with variables</strong>. I have to confess I was inebriated in the beginning by the thought of never having to declare a colour, a padding value, etc. again, and started adding too many variables to my LESS files. It gets messy and complicated quickly. You&#8217;ll have to <strong>find a balance</strong>.</p>
<h4>2. Accessors</h4>
<p>If you only need to <strong>access something once</strong>, you probably don’t need a variable. If you&#8217;re pretty sure that that thing you need to access is, and will always be, directly linked to whichever thing you&#8217;re linking it to, you can use an accessor.</p>
<p>Let&#8217;s say you have a block with a heading and some text. You want the border of that box to always be the same colour as the heading. You can have this:</p>
<pre class="brush: css;">#sales {
    border-color: #ae7b2a;
}

#sales h2 {
    color: #sales['border-color'];
}</pre>
<p>Using accessors may be going a step too far in some cases, but in other cases it makes a lot of sense — I think they&#8217;re quite useful.</p>
<h4>3. Mixins</h4>
<p>One example: gradients. Let’s face it, they are <strong>an absolute pain to write</strong>. Take a look at how LESS makes it easier for you:</p>
<p>The mixin:</p>
<pre class="brush: css;">.grad-linear (@start:&quot;&quot;, @end:&quot;&quot;) {
    background: -webkit-gradient(linear, left top, left bottom, from(@start), to(@end));
    background: -moz-linear-gradient(-90deg,@start,@end);
}</pre>
<p>Using the mixin in your .less file:</p>
<pre class="brush: css;">nav {
	.grad-linear(#b3cdcc,#718a89);
}</pre>
<p>What your compiled .css file will show:</p>
<pre class="brush: css;">nav {
	background: -webkit-gradient(linear, left top, left bottom, from(#b3cdcc), to(#718a89));
	background: -moz-linear-gradient(-90deg, #b3cdcc, #718a89);
}</pre>
<p>Mixins are great for properties that still require that we add some vendor-specific code (like <code>border-radius</code>) or for the latest CSS3 gradients, transitions, etc.</p>
<p>I have to say mixins, especially when used for gradients and <code>border-radius</code>, are my favourite part of LESS.</p>
<h4>4. C-style comments</h4>
<p>Some people prefer these to typical CSS inline comments. I&#8217;m OK with either, but if you&#8217;re using LESS, you can have either this:</p>
<pre class="brush: css;">/* A normal CSS comment */</pre>
<p>Or this:</p>
<pre class="brush: css;">// A C-style CSS comment</pre>
<h4>5. Nesting (in some cases)</h4>
<p>Nesting is one of those things that makes you think LESS is amazing at first. Then you start using LESS and start nesting selectors, and change your mind.</p>
<p>The rare instance where I think nesting is useful is with link states in simple selectors. In LESS you can have this:</p>
<pre class="brush: css;">a {
    :link, :visited { text-decoration:none; color:#edd273; font-weight:bold; }
    :hover, :active, :focus { color:#edd273; border-bottom:1px solid #edd273; }
}</pre>
<p>And the output will be this:</p>
<pre class="brush: css;">a:link {
  text-decoration: none;
  color: #edd273;
  font-weight: bold;
}
a:visited {
  text-decoration: none;
  color: #edd273;
  font-weight: bold;
}
a:hover {
  color: #edd273;
  border-bottom: 1px solid #edd273;
}
a:active {
  color: #edd273;
  border-bottom: 1px solid #edd273;
}
a:focus {
  color: #edd273;
  border-bottom: 1px solid #edd273;
}</pre>
<p>There&#8217;s a lot of repetition in here, I know (I&#8217;ll mention that on the next section), but it&#8217;s nice nonetheless.</p>
<h3>How LESS can easily become a nightmare</h3>
<p>This is a list of things that I would either <strong>avoid</strong> doing in LESS or that just <strong>don’t work</strong> the way you’d expect them to (so, annoyances).</p>
<h4>1. Nesting (in most cases)</h4>
<p>As I just mentioned in the previous section, nesting looks nice at first, but it doesn&#8217;t work flawlessly.</p>
<p>One of the things that I&#8217;ve noticed for example, is that, even though you can have this: </p>
<pre class="brush: css;">nav {
  ul {
    li a {
      :link { color: red; }
    }
  }
}</pre>
<p>This won&#8217;t work (notice that now I&#8217;m using a direct child selector instead):</p>
<pre class="brush: css;">nav {
  ul {
    li &gt; a {
      :link { color: red; }
    }
  }
}</pre>
<p>For this last bit of CSS to work, you&#8217;ll have to do it like this (notice the extra &#8220;&amp;&#8221;):</p>
<pre class="brush: css;">nav {
  ul {
    li &gt; a {
      &amp;:link { color: red; }
    }
  }
}</pre>
<p>This not a problem with LESS, I guess it&#8217;s just not a very intuitive way of doing it just for using a different type of selector.</p>
<p>The main thing, however, that I think makes nesting a poor choice in most cases, is how it can make <strong>a mess out of specificity</strong> [here's <a href="http://www.smashingmagazine.com/2010/04/07/css-specificity-and-inheritance/" rel="nofollow" >a post I've written previously on specificity</a> and other matters].</p>
<p>Your first instinct is to nest everything inside the main blocks, like <code>aside</code>, <code>#sidebar</code>, <code>#news</code>, etc. But then you realise you need to reutilise a piece of the CSS for another area on the site. You make another nested selector for that new block, because you don&#8217;t want to go over that first nested block of CSS that you created in the first place. You&#8217;ll be left out with numerous <strong>redundant selectors</strong>, with <strong>very long selectors</strong> (because you don&#8217;t notice this until the compiler phase), and with the need to create <strong>overly specific selectors</strong> to override your initial ones (that shouldn&#8217;t have been so specific to begin with).</p>
<p>Nesting selectors is one of those cases where the phrase &#8220;<em>with great power comes great responsibility</em>&#8221; makes a lot of sense. Use it wisely and carefully.</p>
<h4>2. Changes made to the compiled file</h4>
<p>This isn&#8217;t a problem with LESS per se, but rather with your <strong>working process</strong>.</p>
<p>Even if you are the only person in charge of the CSS on a given project, it&#8217;s possible that someday you will leave, or hand the project over to someone else, so it&#8217;s a good thing to make sure that no-one is going to edit the compiled .css file directly instead of the .less one.</p>
<p>If this happens, and then after a while someone <em>does</em> use the .less file, when it compiles, it will <strong>override the changes made</strong> to the .css file. Then you&#8217;ll have to go back and fix it.</p>
<p>This is just a general problem with people: if there&#8217;s a chance that we can make a mistake, we will make it.</p>
<h4>3. Formatting</h4>
<p>The .css file that results from the compiler gives you back your CSS with no comments and single-line declarations (that have more than one property). It would be useful if you could have some control over this. For example, you may want to minify the CSS (although you could argue that this should be a completely separate step), keep comments in, have multi-line CSS, group selectors, etc.</p>
<p>I&#8217;m not entirely sure if this has been resolved, so if someone knows better, do let me know.</p>
<h4>4. Using Firebug</h4>
<p>I can&#8217;t work without Firebug, and one of the best things about it is knowing exactly which line you&#8217;re looking at. If you&#8217;re using LESS, that&#8217;s broken: Firebug <strong>shows you the line of the compiled .css file</strong>, not the original .less file you&#8217;re editing, which is basically useless.</p>
<h3>Conclusion</h3>
<p>I love LESS and I think it&#8217;s <strong>a pleasure to use</strong>, until you start trying to be too clever and things start getting messy. My advice is to use it with care, take advantage of its niceties but don&#8217;t go overboard.</p>
<p>I know there are lot <a href="https://less.tenderapp.com/discussions/problems" rel="nofollow" >more problems</a> (and probably good things too) that I haven’t referred. These are the ones that I’ve <strong>personally</strong> came across with; I try not to use LESS on larger projects and I usually don&#8217;t use <code>@import</code> on my stylesheets (especially smaller projects) — which I know can cause some problems.</p>
<p>I’d love to know what your thoughts are on this: have you used it? Why, or why not? Which problems have you encountered? Do you find it helpful or just plain silly?</p>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/css/my-thoughts-on-less/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Books: &#8220;HTML and CSS Web Standards Solutions&#8221;</title>
		<link>http://webdesignernotebook.com/reviews/web-standardistas/</link>
		<comments>http://webdesignernotebook.com/reviews/web-standardistas/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 19:15:04 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Project 52]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=1308</guid>
		<description><![CDATA[The second book I&#8217;m reviewing is &#8220;HTML and CSS Web Standards Solutions&#8221;, by web standardistas Christopher Murphy and Nicklas Persson. What is the book about? The book provides the reader with a foundation in how to markup and style a web site — the right way. In the authors&#8217; own words this book is &#8220;a [...]]]></description>
			<content:encoded><![CDATA[<p>The second book I&#8217;m reviewing is <a href="http://www.amazon.com/HTML-CSS-Standards-Solutions-Standardistas/dp/1430216069/" rel="nofollow" >&#8220;HTML and CSS Web Standards Solutions&#8221;</a>, by web standardistas Christopher Murphy and Nicklas Persson.</p>
<p><span id="more-1308"></span></p>
<h3>What is the book about?</h3>
<p>The book provides the reader with a <strong>foundation</strong> in how to markup and style a web site — the right way. In the authors&#8217; own words this book is &#8220;a well-grounded, web standards-based approach <strong>in one package</strong>&#8220;.</p>
<p>Starting from the beginning, it explains the <strong>importance of solid, structured markup</strong> and of analysing a web site&#8217;s content before diving into the coding phase. It introduces the most important HTML tags and how to properly use them.</p>
<p>Following the HTML section of the book — which takes almost half of it — it dives into the CSS bit. Here it explains <strong>how to use CSS in a clean and effective way</strong> — just the way I like it :)</p>
<p>One of the most important aspects of this book is how it encourages the reader to <strong>continue to learn and explore</strong> — there is a very clear message that you can&#8217;t possibly learn everything from one book. It provides several paths in which the reader can further his or her knowledge and <strong>evolve</strong> as a web designer.</p>
<h3>Who is the book for?</h3>
<p>As I&#8217;ve mentioned above, the book is targeted at beginners — <strong>it doesn&#8217;t assume you know anything</strong> about HTML or CSS so everything is explained in a very clear and practical way.</p>
<p>I suppose it&#8217;s hard to assess whether the information would be easy to understand by an absolute beginner since I&#8217;m not one anymore (or at least I like to think I&#8217;m not). But every step of the book is so carefully explained, that I doubt anyone would have any problems.</p>
<p>Like Sam Brown mentioned in the title of his review, <a href="http://sam.brown.tc/entry/419/web-designers-who-can-t-code-need-to-read-this-book" rel="nofollow" >&#8220;Web designers who can&#8217;t code, need to read this book&#8221;</a>. I couldn&#8217;t agree more.</p>
<h3>A minor remark</h3>
<p>The only thing I would have changed, or better yet, added to the book would be a <strong>more detailed section on inheritance</strong>. This is, however, probably due to the fact that I just wrote <a href="http://www.smashingmagazine.com/2010/04/07/css-specificity-and-inheritance/" rel="nofollow" >a massive post about it</a> and all that information is fresh in my memory.</p>
<p>Inheritance is a fairly complicated topic and would probably not be relevant for this book; it&#8217;s one of the things that people can easily research on their own when any issues arise.</p>
<h3>Conclusion</h3>
<p>Reading this book felt like I was at the web design school I never had the change to attend. It is truly <strong>a course in a book</strong>: it explains the basics that every web designer should know — whether a coder or not.</p>
<p>The completed website that it provides the reader with at the end is invaluable, and I am not ashamed to admit that, even though I&#8217;m not within the book&#8217;s target audience, I&#8217;ve learned a few things I didn&#8217;t know, and remembered others I had forgotten.</p>
<p>I am lucky enough to know Christopher and Nicklas, the authors of this book, personally, and it was a pleasure to see that their charmingly friendly personalities show through in the writing of the book — which makes it an even more <strong>delightful read</strong>. Thoroughly recommended!</p>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/reviews/web-standardistas/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Little Known font-size-adjust CSS3 Property</title>
		<link>http://webdesignernotebook.com/css/the-little-known-font-size-adjust-css3-property/</link>
		<comments>http://webdesignernotebook.com/css/the-little-known-font-size-adjust-css3-property/#comments</comments>
		<pubDate>Thu, 25 Mar 2010 22:45:32 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Project 52]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=1287</guid>
		<description><![CDATA[Ever wanted to use fallback fonts on your CSS with different aspect ratios without them looking huge (or tiny)? The sparkling new CSS3 font-size-adjust property could do just that, maybe. What does font-size-adjust do? First, let me warn you: you will need to use Firefox to view the examples on this page properly. Yes, not [...]]]></description>
			<content:encoded><![CDATA[<p>Ever wanted to use fallback fonts on your CSS with different aspect ratios without them looking huge (or tiny)? The sparkling new CSS3 <code>font-size-adjust</code> property could do just that, maybe.</p>
<p><span id="more-1287"></span></p>
<h3>What does <code>font-size-adjust</code> do?</h3>
<p><em>First, let me warn you: you will need to use <strong>Firefox</strong> to view the examples on this page properly. Yes, not Safari, Firefox!</em></p>
<p>The <code>font-size-adjust</code> property allows you to specify an optimal aspect ratio <strong>for when a fallback font is used</strong>; if the substitute font has a different aspect ratio than the preferred one, the text’s <a href="http://en.wikipedia.org/wiki/X-height" rel="nofollow" >x-height</a> (roughly the size of its lowercase letters) will be preserved.</p>
<p>Take a look at the image bellow:</p>
<p><img src="http://webdesignernotebook.com/wp_livesite/wp-content/uploads/2010/03/fontsizeadjust-compare.png" alt="" title="Comparison of the aspect ratio of Baskerville and Georgia" width="390" height="279" class="alignnone size-full wp-image-1293" /></p>
<p>Baskerville and Georgia don’t have the same aspect ratio, so when font fallback occurs (if Baskerville is the optimal font), the text usually looks much bigger even at the same size.</p>
<p>By using <code>font-size-adjust</code>, the original <code>font-size</code> for the fallback fonts <strong>will be divided</strong> by the <code>font-size-adjust</code> value.</p>
<p><em>Do not confuse <code>font-size-adjust</code> with <code><a href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariCSSRef/Articles/StandardCSSProperties.html#//apple_ref/css/property/-webkit-text-size-adjust" rel="nofollow" >-webkit-text-size-adjust</a></code>, which is used to specify the size adjustment of text on the iPhone.</em></p>
<h3>How to determine the correct <code>font-size-adjust</code> value</h3>
<p>The example on the W3C specification is very clear:</p>
<blockquote cite="http://www.w3.org/TR/css3-fonts/#relative-sizing-the-font-size-adjust-pro"><p>
Authors can calculate the aspect value for a given font by comparing spans with the same content but different font-size-adjust properties. If the same font-size is used, the spans will match when the font-size-adjust value is accurate for the given font.
</p></blockquote>
<p>I’m going to basically repeat its example here.</p>
<p>Let’s take a look at the following code, in which we have a paragraph with two <code>span</code>s. </p>
<p>The CSS:</p>
<pre class="brush: css;">p { font-family:Times New Roman; font-size:400px; }

span { border:solid 1px red; }

.adjust { font-size-adjust:0.5; }</pre>
<p>The HTML:</p>
<pre class="brush: xml;">&lt;p&gt;&lt;span&gt;a&lt;/span&gt;&lt;span class=&quot;adjust&quot;&gt;a&lt;/span&gt;&lt;/p&gt;</pre>
<p>Both <code>span</code>s inherit the <code>font-family</code> from its parent (the <code>p</code> element), but the second <code>span</code> has the <code>font-size-adjust</code> property applied to it, with a <strong>random value</strong>.</p>
<p>If you check the <a href="http://webdesignernotebook.com/examples/font-size-adjust-test.html" rel="nofollow" >example page</a>, look at the example on the left: the red boxes don’t match size in height — the <code>font-size-adjust</code> value is wrong.</p>
<p><em>[Do all the boxes on the example page have the same height? What did I say? Firefox…]</em></p>
<p>After a few experiments, I’ve arrived at the value of “0.455”. Now here’s the CSS for the second example (on the right):</p>
<p>The CSS:</p>
<pre class="brush: css;">p { font-family:Times New Roman; font-size:400px; }

span { border:solid 1px green; }

.adjust { font-size-adjust:0.455; }</pre>
<p>If you go ahead to the <a href="http://webdesignernotebook.com/examples/font-size-adjust-test.html" rel="nofollow" >example page</a>, you will see that on the example with the green borders, both a’s bounding boxes have the same height — now we have the <strong>correct</strong> <code>font-size-adjust</code> value for our preferred font.</p>
<h3>An example</h3>
<p>Here’s <a href="http://webdesignernotebook.com/examples/font-size-adjust.html" rel="nofollow" >a quick example</a> I’ve created just to show this working on actual text.</p>
<p>The font stack consists of: Calibri, Lucida Sans and Verdana (and this is the order by which the fonts are displayed on the page).</p>
<p>Safari’s rendering of the page:</p>
<p><img src="http://webdesignernotebook.com/wp_livesite/wp-content/uploads/2010/03/font-size-adjust-safari.png" alt="" title="Font-size-adjust in Safari" width="597" height="361" class="alignnone size-full wp-image-1292" /></p>
<p>And Firefox’s:</p>
<p><img src="http://webdesignernotebook.com/wp_livesite/wp-content/uploads/2010/03/font-size-adjust-ff.png" alt="" title="Font-size-adjust in Firefox" width="597" height="357" class="alignnone size-full wp-image-1291" /></p>
<p>As you can see, Firefox maintains <strong>the same x-height</strong> independent of which font is being used.</p>
<p>I’m not concerned with the text not being aligned, the purpose of this example is to show how <code>font-size-adjust</code> can affect the <strong>consistency of the font size and the font&#8217;s legibility</strong>.</p>
<p>Also, even though the first <code>div</code> has the correct font stack, I had to manually specify Lucida Sans and Verdana for the other <code>div</code>s, so you (and I) can see the difference even if we have all three fonts installed.</p>
<h3>Last comments</h3>
<p>I guess using this property may eventually have some negative implications on how typography is treated throughout a website, but that can be the topic for another post — the main goal here is <strong>just to showcase</strong> a quite obscure CSS3 property that may be useful in some cases.</p>
<p>I confess I haven’t tested it on a “real” project yet, so I’d be happy to hear your thoughts.</p>
<p>This is, for now, only supported by Firefox for Windows from version 1.0 and from 3.0 on all platforms. There is a <a href="https://bugs.webkit.org/show_bug.cgi?id=15257" rel="nofollow" >bug filed for Webkit</a> to fix this issue though.</p>
<h3>References and further reading</h3>
<ul>
<li><a href="http://www.w3.org/TR/css3-fonts/#relative-sizing-the-font-size-adjust-pro" rel="nofollow" >Relative sizing: the ‘font-size-adjust’ property — CSS Fonts Module Level 3</a></li>
<li><a href="https://developer.mozilla.org/samples/cssref/font-size-adjust.html" rel="nofollow" >CSS Examples: font-size-adjust — Mozilla Developer Center</a></li>
<li><a href="https://developer.mozilla.org/en/CSS/font-size-adjust" rel="nofollow" >font-size-adjust — Mozilla Developer Center</a></li>
<li><a href="http://en.wikipedia.org/wiki/Comparison_of_layout_engines_%28Cascading_Style_Sheets%29" rel="nofollow" >Comparison of layout engines (Cascading Style Sheets) — Wikipedia</a></li>
<li><a href="http://dbaron.org/log/20080613-firefox3-css#font-size-adjust" rel="nofollow" >Some new CSS features in Firefox 3 — David Baron&#8217;s Weblog</a></li>
<li>And another CSS fonts-related article that might interest you (by me): <a href="http://www.smashingmagazine.com/2010/03/01/css-and-the-future-of-text/" rel="nofollow" >The Future Of CSS Typography</a> — on Smashing Magazine</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/css/the-little-known-font-size-adjust-css3-property/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>A Quick Note About the :empty Pseudo-class</title>
		<link>http://webdesignernotebook.com/css/a-quick-note-about-the-empty-pseudo-class/</link>
		<comments>http://webdesignernotebook.com/css/a-quick-note-about-the-empty-pseudo-class/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 23:34:02 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Project 52]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=1264</guid>
		<description><![CDATA[I&#8217;m in love with the simplicity that CSS3 selectors can bring to our stylesheets. Here&#8217;s a brief explanation of one of my favourites: the :empty pseudo-class. What is the :empty pseudo-class Here is the definition taken from the W3C Selectors Level 3 specification: The :empty pseudo-class represents an element that has no children at all. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m in love with the simplicity that CSS3 selectors can bring to our stylesheets. Here&#8217;s a brief explanation of one of my favourites: the <code>:empty</code> pseudo-class.</p>
<p><span id="more-1264"></span></p>
<h3>What is the <code>:empty</code> pseudo-class</h3>
<p>Here is the definition taken from the <a href="http://www.w3.org/TR/css3-selectors/#empty-pseudo" rel="nofollow" >W3C Selectors Level 3 specification</a>:</p>
<blockquote cite="http://www.w3.org/TR/css3-selectors/#empty-pseudo"><p>
The <code>:empty</code> pseudo-class represents an element that has no children at all.
</p></blockquote>
<p>Seems easy enough, right? That&#8217;s because it is. The <code>:empty</code> pseudo-class is going to target elements that are completely empty; for example, an empty paragraph:</p>
<pre class="brush: xml;">&lt;p&gt;&lt;/p&gt;</pre>
<p>Or an empty table cell:</p>
<pre class="brush: xml;">&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;</pre>
<p>It won&#8217;t target this paragraph though (there is a space within the <code>p</code> tag, therefore it isn&#8217;t <em>empty</em>):</p>
<pre class="brush: xml;">&lt;p&gt; &lt;/p&gt;</pre>
<h3>A practical example</h3>
<p>So when can this selector be useful?</p>
<p>Image you&#8217;re styling a table and some of the data cells have no content — you can style them differently using the magic <code>:empty</code> pseudo-class.</p>
<p>Let&#8217;s take the table I&#8217;ve created for the <a href="http://webdesignernotebook.com/css/a-beautiful-table/" rel="nofollow" >Adding Style with CSS: A Beautiful Table</a> article. I&#8217;m going to use the same CSS, but change the data to make it simpler (the data I&#8217;ve added makes no sense, but you get the point…). I&#8217;m also going to remove the content in a few cells, to make this example relevant.</p>
<p>So this is our markup:</p>
<pre class="brush: xml;">&lt;table&gt;

	&lt;caption&gt;A simple table&lt;/caption&gt;

	&lt;thead&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;col&quot; rowspan=&quot;2&quot;&gt;Some headings&lt;/th&gt;
			&lt;th scope=&quot;col&quot; colspan=&quot;4&quot;&gt;More headings&lt;/th&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;col&quot;&gt;Great&lt;/th&gt;
			&lt;th scope=&quot;col&quot;&gt;Brilliant&lt;/th&gt;
			&lt;th scope=&quot;col&quot;&gt;Genius&lt;/th&gt;
			&lt;th scope=&quot;col&quot;&gt;Good&lt;/th&gt;
		&lt;/tr&gt;
	&lt;/thead&gt;

	&lt;tfoot&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;row&quot;&gt;Interesting totals&lt;/th&gt;
			&lt;td&gt;155&lt;/td&gt;
			&lt;td&gt;165&lt;/td&gt;
			&lt;td&gt;70&lt;/td&gt;
			&lt;td&gt;140&lt;/td&gt;
		&lt;/tr&gt;
	&lt;/tfoot&gt;

	&lt;tbody&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;row&quot;&gt;Curious&lt;/th&gt;
			&lt;td&gt;5&lt;/td&gt;
			&lt;td&gt;35&lt;/td&gt;
			&lt;td&gt;50&lt;/td&gt;
			&lt;td&gt;15&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;row&quot;&gt;Awesome&lt;/th&gt;
			&lt;td&gt;75&lt;/td&gt;
			&lt;td&gt;90&lt;/td&gt;
			&lt;td&gt;&lt;/td&gt;
			&lt;td&gt;5&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;row&quot;&gt;Fabulous&lt;/th&gt;
			&lt;td&gt;30&lt;/td&gt;
			&lt;td&gt;&lt;/td&gt;
			&lt;td&gt;20&lt;/td&gt;
			&lt;td&gt;80&lt;/td&gt;
		&lt;/tr&gt;
		&lt;tr&gt;
			&lt;th scope=&quot;row&quot;&gt;Nice&lt;/th&gt;
			&lt;td&gt;45&lt;/td&gt;
			&lt;td&gt;40&lt;/td&gt;
			&lt;td&gt;&lt;/td&gt;
			&lt;td&gt;40&lt;/td&gt;
		&lt;/tr&gt;

	&lt;/tbody&gt;

&lt;/table&gt;</pre>
<p>This is what I&#8217;m going to add to the CSS:</p>
<pre class="brush: css;">tbody td:empty {
	background: #EFEFEF;
	}</pre>
<p>And now the empty cells are styled differently! I don&#8217;t think this could have been much easier.</p>
<p>Also, if you really need to ask, this selector works on the latest versions of Firefox, Safari, Chrome and Opera. It will probably work on Internet Explorer 9, like most CSS3 selectors will. (The first person to point out the obvious, will be directed to <a href="http://trentwalton.com/2010/03/08/quoting-lebowski/" rel="nofollow" >this link</a>. — Thanks, <a href="http://jackosborne.co.uk/" rel="nofollow" >Jack</a>, for helping me remember the link!)</p>
<p>Here&#8217;s the example:</p>
<p><a href="http://webdesignernotebook.com/examples/empty-selector.html" rel="nofollow" class="example" >View example</a></p>
<p>So, will you be using this selector any time soon?</p>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/css/a-quick-note-about-the-empty-pseudo-class/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Book Review: &#8220;CSS Mastery — 2nd Edition&#8221;</title>
		<link>http://webdesignernotebook.com/reviews/css-mastery/</link>
		<comments>http://webdesignernotebook.com/reviews/css-mastery/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 19:39:30 +0000</pubDate>
		<dc:creator>inayaili</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Project 52]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Reviews]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=1159</guid>
		<description><![CDATA[I&#8217;m frequently confronted with the question of &#8220;which CSS books would you recommend?&#8221; and CSS Mastery is always at the top of the list. Here&#8217;s the audio review I did for the Boagworld podcast. The audio Listen! Transcript If you&#8217;d rather read, here&#8217;s the transcript of the review: Hi, my name is Yaili and I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m frequently confronted with the question of &#8220;which CSS books would you recommend?&#8221; and <a href="http://www.amazon.com/CSS-Mastery-Advanced-Standards-Solutions/dp/1430223979/" rel="nofollow" >CSS Mastery</a> is always at the top of the list. Here&#8217;s the audio review I did for the <a href="http://boagworld.com/reviews/css-mastery-2" rel="nofollow" >Boagworld podcast</a>.</p>
<p><span id="more-1159"></span></p>
<h3>The audio</h3>
<p><object data="http://boos.audioboo.fm/swf/fullsize_player.swf" height="129" id="iefix1" type="application/x-shockwave-flash" width="400"><param name="movie" value="http://boos.audioboo.fm/swf/fullsize_player.swf" /><param name="scale" value="noscale" /><param name="salign" value="lt" /><param name="bgColor" value="#FFFFFF" /><param name="allowScriptAccess" value="always" /><param name="wmode" value="window" /><param name="FlashVars" value="mp3Author=yaili&amp;mp3LinkURL=http%3A%2F%2Faudioboo.fm%2Fboos%2F93079-css-mastery-2nd-edition-review&amp;mp3Title=CSS+Mastery+2nd+Edition+%E2%80%94+Review&amp;mp3Time=07.35pm+24+Jan+2010&amp;mp3=http%3A%2F%2Faudioboo.fm%2Fboos%2F93079-css-mastery-2nd-edition-review.mp3" /><a href="http://audioboo.fm/boos/93079-css-mastery-2nd-edition-review.mp3" rel="nofollow" >Listen!</a></object></p>
<h3>Transcript</h3>
<p><strong>If you&#8217;d rather read, here&#8217;s the transcript of the review:</strong></p>
<p>Hi, my name is Yaili and I&#8217;ll be reviewing the Second Edition of CSS Mastery, by Andy Budd.</p>
<h4>Who is the book for?</h4>
<p>The book states that it&#8217;s for &#8220;anybody with a basic knowledge of HTML and CSS&#8221; and experts. I&#8217;d say it&#8217;s more for the first case, but I&#8217;ll expand on that later.</p>
<p>There are lots of useful tips and tricks, that I&#8217;m sure you&#8217;ll use over and over, explained in a solid and easy to understand way. The fact that the examples can be seen online and that there are files that can be downloaded is great.</p>
<h4>It&#8217;s a second edition</h4>
<p>When I read the first edition, I was just starting to work with CSS, and CSS was still a bit of a mystery to me. I remember reading some things that I thought to be pure magic and that seemed very complicated, but now I realise they are used by any good CSS coder. So, at the time, the book opened my eyes to those techniques and to the possibilities of what could be done with CSS.</p>
<h4>Content</h4>
<p>The book covers subjects from the beginning to a more advanced level.</p>
<p>It starts with the importance of semantic HTML, how to set good foundations. It takes a very brief look into microformats and HTML5 as well.</p>
<p>Then it moves onto selectors, with some more advanced and CSS3 ones — but it doesn&#8217;t go very deep into that area to be honest.</p>
<p>It explains the box model, which is rather important, very well. Liquid and elastic layouts.</p>
<p>Some more advanced techniques, like sliding doors and even multiple backgrounds, which is quite refreshing. Opacity and rgba colours.</p>
<p>There are some clever uses for the :target pseudo-class and attribute selectors. Some webkit proprietary code like gradients and reflections.</p>
<p>It also explains how to style lists and navigation. I would have liked to see a larger section for definition lists, because there&#8217;s only a small section and it sounds a bit negative (or even dismissive) and I don&#8217;t think it makes them justice.</p>
<p>There are some negative comments on CSS frameworks. Which I frankly agree with.</p>
<p>A good introduction to the IE layout issue. Some common browser bugs and how to fix them. And how to work with graded browser support.</p>
<p>Then on the examples, at certain points they can be a little repetitive, but there&#8217;s an interesting discussion about website widths, a brief example of using jQuery, which is rather nice.</p>
<h4>Conclusion</h4>
<p>In conclusion, as someone who had already read the book, reading it again was good, as there are always things that you forget or that you weren&#8217;t aware of, even though my experience now is completely different, and I can be a little more critical about it.</p>
<p>If I could change something in the book, I think I&#8217;d change the naming of CSS3 — in the specs it&#8217;s always mentioned with no spaces, and in the book it has a space between the second &#8220;S&#8221; and the number &#8220;3&#8243;. I know it sounds nitpicky, but it&#8217;s rather annoying for me, for some reason…</p>
<p>Also, there are some mentions to browsers that are already dated, even though the book is fairly recent (like &#8220;Safari 4 beta&#8221;, which is already out of Beta). But that&#8217;s just something that happens in our industry — things move too quickly. I&#8217;m just being nitpicky again.</p>
<p>So, have <em>I</em> learned anything from this second edition? I did learn a few things, but not much. I already use or know most of the techniques. But would someone starting to work with CSS learn anything from the book? Definitely yes. I used to always recommend the first edition whenever someone asked me for book recommendations, and I will keep recommending it with the second edition. It&#8217;s a must-have.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/reviews/css-mastery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://audioboo.fm/boos/93079-css-mastery-2nd-edition-review.mp3" length="2928768" type="audio/mpeg" />
		</item>
		<item>
		<title>The CSS3 :target Pseudo-class And CSS Animations</title>
		<link>http://webdesignernotebook.com/css/the-css3-target-pseudo-class-and-css-animations/</link>
		<comments>http://webdesignernotebook.com/css/the-css3-target-pseudo-class-and-css-animations/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 07:30:05 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Project 52]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=1140</guid>
		<description><![CDATA[It&#8217;s no secret that I&#8217;m always looking for an easy way out using CSS instead of trying to replicate things with convoluted code — there are so many underused techniques that we could be applying to our designs as an enhancement layer! In this experience, I take a brief look into the :target pseudo-class and [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s no secret that I&#8217;m always looking for an easy way out using CSS instead of trying to replicate things with convoluted code — there are so many underused techniques that we could be applying to our designs as an enhancement layer! In this experience, I take a brief look into the <code>:target</code> pseudo-class and a very simple CSS animation.</p>
<p><span id="more-1140"></span></p>
<h3>The :target pseudo-class</h3>
<p>We often use <strong>fragment identifiers</strong> in our code — usually to point to a specific element on a page, represented by a &#8220;#&#8221; and an anchor. When we click on a link that ends with a fragment identifier (for example, <a href="http://en.wikipedia.org/wiki/Lost_%28TV_series%29#Fandom_and_popular_culture" rel="nofollow" >this one</a>), that element we are pointing to becomes the <strong>target</strong> (hence <code>:target</code>).</p>
<p>This <code>:target</code> pseudo-class can be styled, just like we style the <code>:hover</code> or <code>:active</code> pseudo-classes on links.</p>
<p>To see an example in the wild, go to Wikipedia and click on a reference link (for example, <a href="http://en.wikipedia.org/wiki/Lost_%28TV_series%29#cite_note-16" rel="nofollow" >this one</a>). If you are using a good browser, you will see it has a light blue background; and if you look at the CSS, you will see this:</p>
<pre class="brush: css;">ol.references &gt; li:target, sup.reference:target, span.citation:target, cite:target  {
background-color:#DDEEFF;
}</pre>
<p>Pretty easy, right?</p>
<h3>Our example</h3>
<p>If you&#8217;re impatient, you can take a look at the final example now (use Safari):</p>
<p><a href="/examples/target.html" rel="nofollow"  class="example">View example</a></p>
<p>I&#8217;m going to create a simple list of links (using fragment identifiers) to blocks of text bellow them. Here&#8217;s the markup:</p>
<pre class="brush: xml;">&lt;div id=&quot;content&quot;&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;#b1&quot;&gt;Block 1&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;#b2&quot;&gt;Block 2&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;#b3&quot;&gt;Block 3&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;#b4&quot;&gt;Block 4&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div id=&quot;b1&quot;&gt;
	&lt;p&gt;One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. &quot;What's happened to me? &quot; he thought.&lt;/p&gt;
&lt;/div&gt;

&lt;div id=&quot;b2&quot;&gt;
	&lt;p&gt;The quick, brown fox jumps over a lazy dog. DJs flock by when MTV ax quiz prog. Junk MTV quiz graced by fox whelps. Bawds jog, flick quartz, vex nymphs. Waltz, bad nymph, for quick jigs vex! Fox nymphs grab quick-jived waltz. Brick quiz whangs jumpy veldt fox. Bright vixens jump; dozy fowl quack.&lt;/p&gt;
&lt;/div&gt;

&lt;div id=&quot;b3&quot;&gt;
	&lt;p&gt;Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts. Separated they live in Bookmarksgrove right at the coast of the Semantics, a large language ocean.&lt;/p&gt;
&lt;/div&gt;

&lt;div id=&quot;b4&quot;&gt;
	&lt;p&gt;Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo.&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;</pre>
<h3>The basic CSS</h3>
<p>First, we need to cover the basics. I&#8217;ll use a very <strong>simple reset</strong> for this example, but you should use a proper one in your projects. I&#8217;ll just set the <code>font-size</code>, <code>line-height</code>, <code>font-family</code> and reset <code>padding</code> and <code>margin</code> for the elements we are using:</p>
<pre class="brush: css;">body {
	font:62.5%/1.5 Cambria,Georgia,&quot;Times New Roman&quot;,Times,serif;
	}
div, ul, li, a, p {
	padding:0; margin:0;
	}</pre>
<p>Second, I will quickly style the <strong>container</strong> <code>div</code> &#8220;<code>content</code>&#8220;:</p>
<pre class="brush: css;">#content {
	width:500px;
	margin:auto;
	font-size:1.4em;
	}</pre>
<p>Third, the rest of the elements. I will:</p>
<ol>
<li>Add a small bottom margin to the list and to each block of text.</li>
<li>Remove the bullets from our list — we don&#8217;t need them for the example.</li>
<li>Add some padding and a light border to the blocks of text.</li>
<li>Make the first line of each paragraph in small caps. Just because I can.</li>
</ol>
<p>Notice I&#8217;m using the <a href="http://www.w3.org/TR/2009/PR-css3-selectors-20091215/#child-combinators" rel="nofollow" ><strong>child combinator</strong></a> (or selector) to make sure the <code>div</code>&#8216;s I&#8217;m targeting are the ones that are <strong>direct descendants</strong> of the main &#8220;<code>content</code>&#8221; <code>div</code>. So if, for some reason, I were to have <code>div</code>&#8216;s inside the blocks of text, they wouldn&#8217;t be affected. Also, I don&#8217;t have to give these <code>div</code>&#8216;s a class or target them by their <code>id</code>&#8216;s.</p>
<pre class="brush: css;">ul, div &gt; div {
	margin-bottom:1em;
	}
li {
	list-style:none;
	}
div &gt; div {
	padding:1em;
	border:1px solid #ffffd3;
	}
div &gt; div p:first-line {
	font-variant:small-caps;
	font-size:1.2em;
	}</pre>
<h3>The juicy bit</h3>
<p>Now I&#8217;m going to style the <code>:target</code> pseudo-class. First, I&#8217;ll add a slightly <strong>darker border</strong> than the non-targeted <code>div</code>&#8216;s:</p>
<pre class="brush: css;">div &gt; div:target {
	border:1px solid #dac89d;
	}</pre>
<p>Enters the CSS animation. To create an animation you need two things: <strong>a definition</strong> of what effect the animation produces and <strong>a call</strong> to the animation from the element you want to animate.</p>
<p><strong>Let&#8217;s define the animation first.</strong></p>
<p>I&#8217;ll define the animation by setting up keyframes at certain points. In this case, I want the background to start as white, then fade to a light yellow, then back to white — I will need <strong>3 different steps</strong> (or keyframes).</p>
<p>Imagine each step is a simple selector, but instead of having for example this:</p>
<pre class="brush: css;">div {
	background: red;
	}</pre>
<p>we need to specify a moment in time (using percentages, or just &#8220;<code>to</code>&#8221; and &#8220;<code>from</code>&#8221; if we only need &#8220;<code>0%</code>&#8221; and &#8220;<code>100%</code>&#8220;):</p>
<pre class="brush: css;">10% {
	background: red;
	}</pre>
<p>Also, here I will <strong>name my animation</strong>. I will call it &#8220;<code>target</code>&#8220;:</p>
<pre class="brush: css;">@-webkit-keyframes target {
	from { background:#ffffff; }
	50% { background:#ffffd3; }
	to { background:#ffffff; }
	}</pre>
<p>So, the animation is defined, now we need to call it from the <code>:target</code> selector. We can either set each property separately, or use the shorthand version. Let&#8217;s see the full code:</p>
<pre class="brush: css;">div &gt; div:target {
	border:1px solid #dac89d;
	-webkit-animation-name:target;
	-webkit-animation-duration:.5s;
	-webkit-animation-iteration-count:1;
	-webkit-animation-direction:linear;
	}</pre>
<p>The <code>-webkit-</code> bits should be self-explanatory. We need to specify the animation&#8217;s name (&#8220;<code>target</code>&#8220;), it&#8217;s duration (&#8220;<code>.5s</code>&#8220;, half a second), how many times it should be repeated (&#8220;<code>1</code>&#8220;) and it&#8217;s direction (&#8220;<code>linear</code>&#8220;).</p>
<p>The <strong>shorthand</strong> version looks like this instead:</p>
<pre class="brush: css;">div &gt; div:target {
	border:1px solid #dac89d;
	-webkit-animation:target .5s linear;
	}</pre>
<p>Much simpler! Because we only want the animation to repeat once, we can even not specify the &#8220;<code>1</code>&#8221; in this case (if you wanted to, you could have it right after the &#8220;<code>.5s</code>&#8220;). Let&#8217;s say you want the animation to repeat twice, you would specify it like this:</p>
<pre class="brush: css;">div &gt; div:target {
	border:1px solid #dac89d;
	-webkit-animation:target .5s 2 linear;
	}</pre>
<h3>The end</h3>
<p>I hope you enjoyed this brief tutorial. There are endless possibilities for CSS animation and for more advanced CSS selectors, but I feel that the ones I&#8217;m showing here can actually be used on real projects with <strong>no damage for users</strong> browsing the web with less friendly browsers.</p>
<p>Do you agree? Have you used the <code>:target</code> pseudo-class on your projects? How about CSS animation?</p>
<p><em>Note: This animation is only visible on Safari (and Chrome, like <a href="http://webdesignernotebook.com/css/the-css3-target-pseudo-class-and-css-animations/#comment-4768" rel="nofollow" >Dougal kindly pointed out</a>!). The <code>:target</code> pseudo-class is not yet supported by Internet Explorer. Firefox and Opera will just show the darker border when you click on the links, but that is a good compromise.</em></p>
<h3>Resouces</h3>
<ul>
<li><a href="http://webkit.org/blog/324/css-animation-2/" rel="nofollow" >CSS Animation — Surfin&#8217; Safari Blog</a></li>
<li><a href="http://www.w3.org/TR/2009/PR-css3-selectors-20091215/#target-pseudo" rel="nofollow" >The target pseudo-class :target — W3C Specification</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/css/the-css3-target-pseudo-class-and-css-animations/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Remembering: The CSS3 Multi-Column Layout Module</title>
		<link>http://webdesignernotebook.com/css/remembering-the-css3-multi-column-layout-module/</link>
		<comments>http://webdesignernotebook.com/css/remembering-the-css3-multi-column-layout-module/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 19:55:58 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=1055</guid>
		<description><![CDATA[Because I will not shut up about CSS3, this time I&#8217;ve decided to show you a little bit of the multi-column layout module. This module allows you to layout the content of an element in multiple columns, like flowing text on a newspaper-type layout. CSS Modules Just to briefly make sure everybody understands what I [...]]]></description>
			<content:encoded><![CDATA[<p>Because I will <em>not</em> shut up about CSS3, this time I&#8217;ve decided to show you a little bit of the multi-column layout module. This module allows you to layout the content of an element in multiple columns, like flowing text on a newspaper-type layout.</p>
<p><span id="more-1055"></span></p>
<h3>CSS Modules</h3>
<p>Just to briefly make sure everybody understands what I mean by &#8220;modules&#8221;, <strong>the development of CSS3 has been divided in different Modules</strong>. For example, there is a <a href="http://www.w3.org/TR/css3-selectors/" rel="nofollow" >Selectors Module</a>, a <a href="http://www.w3.org/TR/css3-values/" rel="nofollow" >Values and Units Module</a>, a <a href="http://www.w3.org/TR/css3-background/" rel="nofollow" >Backgrounds and Borders Module</a>, etc.</p>
<p>Some of these Modules are at a more advanced stage of development and closer to being final than others. You can take a look at the <a href="http://www.w3.org/Style/CSS/current-work.html" rel="nofollow" >Current Work table here</a>.</p>
<h3>Browser support</h3>
<p>Let&#8217;s get this straight right away: <strong>only Safari and Firefox</strong> are currently supporting (some) of this module&#8217;s features, namely the properties <code>column-count</code>, <code>column-width</code>, <code>column-gap</code> and <code>column-rule</code>. Other browsers will render the content as if there were no columns at all.</p>
<p>There are more properties on the specs (and Safari supports a few more), but I&#8217;ll only mention these in this article, so we can all get a taste of what&#8217;s goin&#8217; on.</p>
<p>Also, I&#8217;ve picked this particular module, because it&#8217;s one of the few that is actually <a href="http://www.w3.org/Style/CSS/current-work.html#multicol" rel="nofollow" >in &#8220;Last Call&#8221; status</a>, so it&#8217;s closer to being finished than others.</p>
<h3>The markup</h3>
<p>For this example I grabbed some text from the excellent <a href="http://www.blindtextgenerator.com/" rel="nofollow" >Blind Text Generator</a> and created a basic page with some <code>div</code>s and paragraphs.</p>
<p>Here&#8217;s an example of one of the<code> div</code>s:</p>
<pre class="brush: xml;">&lt;div id=&quot;text1&quot;&gt;

	&lt;p&gt;One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections. The bedding was hardly able to cover it and seemed ready to slide off any moment.&lt;/p&gt;

	&lt;p&gt;His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. &quot;What's happened to me? &quot; he thought. It wasn't a dream. His room, a proper human room although a little too small, lay peacefully between its four familiar walls.&lt;/p&gt;

	&lt;p&gt;A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame. It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer.&lt;/p&gt;

	&lt;p&gt;Gregor then turned to look out the window at the dull weather. Drops of rain could be heard hitting the pane, which made him feel quite sad. &quot;How about if I sleep a little bit longer and forget all this nonsense&quot;, he thought, but that was something he was unable to do because he was used to sleeping on his right, and in his present state couldn't get into that position. However hard he threw himself onto his right, he always rolled back to where he was.&lt;/p&gt;

&lt;/div&gt;</pre>
<h3>The CSS</h3>
<p>I&#8217;m just going to quickly show what each of the properties does. To use them, we&#8217;ll need to apply <a href="http://reference.sitepoint.com/css/vendorspecific" rel="nofollow" >vendor-specific properties</a>: for Safari the properties will be prefixed with <code>-webkit-</code> and for Firefox with <code>-moz-</code>. Annoying, but nothing we&#8217;re not used to, right?</p>
<p>Please follow the examples below <a href="http://webdesignernotebook.com/examples/css3-layout.html" rel="nofollow" >on this page</a>.</p>
<h4><code>column-width</code></h4>
<p>The CSS for our first <code>div</code> will be the following:</p>
<pre class="brush: css;">#text1 {
	-webkit-column-width: 200px;
	-moz-column-width: 200px;
	column-width: 200px;
	}</pre>
<p>This will create <strong>200px wide columns</strong> until the width of the page is filled, with <strong>no gap</strong> between the columns.</p>
<p>Each column within the element is called a <strong>column box</strong>. A column box doesn&#8217;t have its own properties, like background, padding or margins (at least not for now, but that may change for future specs). Also, all columns within a row have the same width and the same height.</p>
<p>The <code>column-width</code> property is <strong>not definitive—it is actually the optimal size</strong> we want the columns to have, but that may vary if the container is wider or narrower than it would be required to fit those measures.</p>
<h4><code>column-gap</code> and <code>column-rule</code></h4>
<p>Now let&#8217;s add some space between the columns and a nice rule, shall we?</p>
<pre class="brush: css;">#text2 {
	-webkit-column-width: 390px;
	-webkit-column-gap: 20px;
	-webkit-column-rule: 1px solid #000000;
	-moz-column-width: 390px;
	-moz-column-gap: 20px;
	-moz-column-rule: 1px solid #000000;
	column-width: 390px;
	column-gap: 20px;
	column-rule: 1px solid #000000;
	}</pre>
<p>In this example, we are defining a gap between each column of 20px and also adding a rule between each of them.</p>
<p>The <code>column-rule</code> property follows the syntax of the <code>border</code> property. Also, the column rules don&#8217;t take up any space—if they are wider than the column gap, they will (or should) overlap the content.</p>
<p>The column gaps and column rules are all the same within a row.</p>
<p><em>Ignore the colourful blocks in this example for now, I explain those bellow.</em></p>
<h4><code>column-count</code></h4>
<p>On our third example, we will specify how many columns we actually want the element to have:</p>
<pre class="brush: css;">#text3 {
	-webkit-column-width: 200px;
	-webkit-column-count: 4;
	-webkit-column-gap: 20px;
	-moz-column-width: 200px;
	-moz-column-count: 4;
	-moz-column-gap: 20px;
	column-width: 200px;
	column-count: 4;
	column-gap: 20px;
	}</pre>
<p>If both <code>column-width</code> and <code>column-count</code> are specified (like in this example), the <code>column-count</code> value will be regarded as the <strong>maximum number of columns</strong>. So if only 3 columns fit in the element, but you&#8217;ve set it to have 4, only 3 will be created.</p>
<p>If you don&#8217;t specify the <em>width</em> of the columns, the <code>column-width</code> will be calculated automatically according to how many columns you have specified.</p>
<h4>Images, etc.</h4>
<p>You can have elements, like images, along the text, and even float them or make them a percentage in width. That percentage will be calculated according to the width of the column box they are in.</p>
<p>To test this theory, I added 3 coloured <code>div</code>s to the second example (<code>#test2</code>), with some inline coding (oh, the horror!). The first, red, <code>div</code> is floated but it has a width of 140%; the second, green, <code>div</code> is not floated and it&#8217;s also 140% wide; and the third, yellow, <code>div</code> is floated, but has 100% width .</p>
<p>According to the <a href="http://www.w3.org/TR/css3-multicol/#overflow-and-multicol-elements" rel="nofollow" >W3C specification</a>, this is what should happen:</p>
<blockquote cite="http://www.w3.org/TR/css3-multicol/#overflow-and-multicol-elements"><p>
Content in the normal flow that extends into column gaps (e.g., long words) is clipped in the middle of the column gap.</p>
<p>Floats that are wider than the column box intrude into neighboring columns.
</p></blockquote>
<p>Correct me if I&#8217;m wrong, but for what I see on these examples, Firefox is overflowing both 140% <code>div</code>s, even if the second one is <em>not</em> floated. Safari doesn&#8217;t do better: it&#8217;s overflowing <em>neither</em> of them.</p>
<h4>More overflowing stuff</h4>
<p>As a final example, I&#8217;m creating a div with a smaller width and a set height. I&#8217;m making the overflow visible, and see what happens…</p>
<pre class="brush: css;">#text4 {
	height: 200px;
	width: 500px;
	overflow: visible;
	border: 2px solid red;
	-webkit-column-width: 200px;
	-webkit-column-gap: 20px;
	-moz-column-width: 200px;
	-moz-column-gap: 20px;
	column-width: 200px;
	column-gap: 20px;
	}</pre>
<p><a href="http://www.w3.org/TR/css3-multicol/#overflow-outside-multicol-elements" rel="nofollow" >According to the specs</a>, this is what should happen:</p>
<blockquote cite="http://www.w3.org/TR/css3-multicol/#overflow-outside-multicol-elements"><p>A multi-column element can have more columns than it has room for due to:</p>
<ul>
<li>Constrained column height. […]</li>
</ul>
<p>In continuous media, the columns that do not fit within the multicol element are added in the inline direction. </p></blockquote>
<p>In human language, that means if the content is to be overflown, then it should be to the sides. In this case, Safari seems to be getting it right, while Firefox overflows the content vertically if the height is set via the <code>max-height</code> property, but correctly if via the normal <code>height</code> property. Take a look at the last block on the <a href="http://webdesignernotebook.com/examples/css3-layout.html" rel="nofollow" >example page</a> (with the red border).</p>
<h3>Final words</h3>
<p>And that&#8217;s it! I just wanted to remember you of this wonderful CSS3 feature that can make our lives a lot easier—and that degrades quite nicely for browsers that don&#8217;t support it.</p>
<p>I keep looking for examples of the multi-column layout in the wild, but I don&#8217;t think a lot of people are using it now. For what it&#8217;s worth, I&#8217;m using it on my personal site, <a href="http://yaili.com" rel="nofollow" >yaili.com</a>, and it&#8217;s also in use on the <a href="http://tweetcc.com/" rel="nofollow" >tweetCC</a> website.</p>
<p>Do you know of any more websites using it?</p>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/css/remembering-the-css3-multi-column-layout-module/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>How to use Modernizr</title>
		<link>http://webdesignernotebook.com/css/how-to-use-modernizr/</link>
		<comments>http://webdesignernotebook.com/css/how-to-use-modernizr/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 08:50:47 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=976</guid>
		<description><![CDATA[There is a tool that came to make our lives as progressive web designers a bit easier: Modernizr. In this short tutorial, learn how to apply this handy script to maximum effect on your sites. An overview Although CSS3’s use has been increasing among web designers, browser support for some of its features is still [...]]]></description>
			<content:encoded><![CDATA[<p>There is a tool that came to make our lives as progressive web designers a bit easier: Modernizr. In this short tutorial, learn how to apply this handy script to maximum effect on your sites.</p>
<p><span id="more-976"></span></p>
<h3>An overview</h3>
<p>Although CSS3’s use has been increasing among web designers, browser support for some of its features is still inexistent.</p>
<p>Lately, I’ve been using Modernizr more and more to cater for those <strong>browsers that don’t support specific CSS3 properties</strong>—for example, <a href="http://yaili.com" rel="nofollow" >on my site</a>—, and it makes the development much easier because I know I’m providing these lesser browsers with an alternative experience, rather than just ignoring them.</p>
<p>Bear in mind (and this is even splashed on Modernizr’s front page), that Modernizr <strong>doesn’t actually magically enable</strong> these properties for browsers that don’t support them. It just tells the page whether that feature is supported on the browser the visitor is using or not.</p>
<h3>How it works</h3>
<p>To install Modernizr, download the file from <a href="http://www.modernizr.com/" rel="nofollow" >this page</a>. Then, on your site’s head tag, add a link to the file. For example:</p>
<pre class="brush: xml;">&lt;script src=&quot;js/modernizr-1.0.min.js&quot;&gt;&lt;/script&gt;</pre>
<p>The second step is to include on your html tag a class of “<code>no-js</code>”:</p>
<pre class="brush: xml;">&lt;html class=&quot;no-js&quot;&gt;</pre>
<p><strong>Why add this tag?</strong><br />
Because that will be the default state of the page. If JavaScript (<code>js</code>) isn’t on, then Modernizr won’t work at all (and probably other features of your site won’t work either&#8230;), so it’s good that we have a <strong>fallback</strong> for that case.</p>
<p>If JavaScript is indeed enabled, once that page is loaded on the browser, that class will be replaced dynamically and it may look something like this:</p>
<pre class="brush: xml;">&lt;html class=&quot;js canvas canvastext geolocation rgba hsla no-multiplebgs borderimage borderradius boxshadow opacity no-cssanimations csscolumns no-cssgradients no-cssreflections csstransforms no-csstransforms3d no-csstransitions  video audio cufon-active fontface cufon-ready&quot;&gt;</pre>
<p><strong>What does this mean?</strong>  Let’s take a look, shall we?</p>
<p>In this case, I opened the page on Firefox 3.5. This browser (sadly) doesn’t support multiple backgrounds, CSS gradients or CSS transforms, therefore, Modernizr outputs &#8220;<code>no-multipebgs</code>&#8220;, &#8220;<code>no-cssgradients</code>&#8221; and &#8220;<code>no-csstransforms</code>&#8220;. On the other hand, it does support <code>canvas</code> and <code>border-radius</code>, which explains &#8220;<code>canvas</code>&#8221; and &#8220;<code>borderradius</code>&#8220;. Etc.</p>
<h3>How to use this (precious) information?</h3>
<p>So what can you actually do with this? How does that help you in any way?, you might ask.</p>
<p>Let’s look at an example:</p>
<h4>Multiple backgrounds</h4>
<p>Your site’s background has been carefully built and you’re using the multiple background technique to make it simpler (and faster!) to code. Your CSS may look like this:</p>
<pre class="brush: css;">#nice {
	background: url(background-one.png) top left repeat-x,
	url(background-two.png) bottom left repeat-x;
}</pre>
<p>And a nice browser will render this:</p>
<p><img src="http://webdesignernotebook.com/wp_livesite/wp-content/uploads/2009/11/modernizr-safari.jpg" alt="modernizr-safari" title="modernizr-safari" width="241" height="342" class="alignnone size-full wp-image-1034" /></p>
<p>Using Modernizr, your CSS will look instead like this:</p>
<pre class="brush: css;">#nice {
	background: url(background-one.png) top left repeat-x;
}
.multiplebgs #nice {
	background: url(background-one.png) top left repeat-x,
	url(background-two.png) bottom left repeat-x;
}</pre>
<p>This is what your visitors will get, depending on which browser they have:</p>
<p><img src="http://webdesignernotebook.com/wp_livesite/wp-content/uploads/2009/11/modernizr-safari.jpg" alt="modernizr-safari" title="modernizr-safari" width="241" height="342" class="alignnone size-full wp-image-1034" /> <img src="http://webdesignernotebook.com/wp_livesite/wp-content/uploads/2009/11/modernizr-opera.jpg" alt="modernizr-opera" title="modernizr-opera" width="241" height="342" class="alignnone size-full wp-image-1033" /></p>
<p>This is a very simplified use of Modernizr, but hopefully it&#8217;s enough to show you what you can do with it.</p>
<h3>HTML5</h3>
<p>Modernizr also allows you to <strong>use the new HTML5 elements</strong>—<code>header</code>, <code>hgroup</code>, <code>section</code>, <code>footer</code>, <code>video</code>, etc.—and style them.</p>
<p>This doesn’t mean that some of these elements will start working on Internet Explorer, but that you can <strong>style</strong> them and that IE will understand them and not ignore them.</p>
<h3>JavaScript</h3>
<p>You can also detect features using Modernizr in your JavaScript, using this syntax:</p>
<pre class="brush: jscript;">if (Modernizr.geolocation) {
}</pre>
<h3>Conclusion</h3>
<p>I hope that I managed to explain the <strong>usefulness</strong> of Modernizr. While we can’t rely on the fact that browsers support the full spectrum of features we want to use, this is the best tool out there to provide for both worlds.</p>
<p><strong>Do you use Modernizr too? How?</strong> If not, how do you deal with some browsers not supporting some features (assuming you <em>are</em> using the latest CSS3 techniques)?</p>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/css/how-to-use-modernizr/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Floated lists with CSS3 and jQuery</title>
		<link>http://webdesignernotebook.com/css/floated-lists-with-css3-and-jquery/</link>
		<comments>http://webdesignernotebook.com/css/floated-lists-with-css3-and-jquery/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 08:00:39 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=938</guid>
		<description><![CDATA[We should all be using advanced CSS selectors by now&#8212;they make our lifes so much easier! In this quick tutorial, I&#8217;m going to explain how you can have a nicely floated list of items. We will use jQuery to make sure IE understands it too. The markup Let&#8217;s start with a very clean semantic markup, [...]]]></description>
			<content:encoded><![CDATA[<p>We should all be using advanced CSS selectors by now&mdash;they make our lifes so much easier! In this quick tutorial, I&#8217;m going to explain how you can have a nicely floated list of items. We will use jQuery to make sure IE understands it too.</p>
<p><span id="more-938"></span></p>
<h3>The markup</h3>
<p>Let&#8217;s start with a very clean semantic markup, listing some photos:</p>
<pre>&lt;div id="page"&gt;

	&lt;ul id="food"&gt;

		&lt;li&gt;
			&lt;img src="pic-1.jpg" width="200" height="133" alt="Wagamama" /&gt;
		&lt;/li&gt;

		&lt;li&gt;
			&lt;img src="pic-2.jpg" width="200" height="133" alt="Strawberries" /&gt;
		&lt;/li&gt;

		&lt;li&gt;
			&lt;img src="pic-3.jpg" width="200" height="133" alt="The Horseshoe" /&gt;
		&lt;/li&gt;

		&lt;li&gt;
			&lt;img src="pic-4.jpg" width="200" height="133" alt="Brick Lane" /&gt;
		&lt;/li&gt;

		&lt;li&gt;
			&lt;img src="pic-5.jpg" width="200" height="133" alt="Portugal" /&gt;
		&lt;/li&gt;

		&lt;li&gt;
			&lt;img src="pic-6.jpg" width="200" height="133" alt="Burgers" /&gt;
		&lt;/li&gt;

	&lt;/ul&gt;

&lt;/div&gt;</pre>
<p>So here we basically have a container <code>div</code>, with the id of &#8220;page&#8221;. Then we have our list with the id of &#8220;food&#8221; and our list items, each one containing one image.</p>
<h3>The CSS</h3>
<p>After we&#8217;ve added some CSS resets (check the <a href="/examples/floated-list/floated-list.html" rel="nofollow" >example page</a> for this bit), let&#8217;s add some styling to our &#8220;page&#8221; <code>div</code>:</p>
<pre>#page {
	width: 640px;
	padding: 20px 0;
	margin: auto;
	text-align: left;
	}</pre>
<p>Here we&#8217;ve added a specific width to the container, some top padding and we&#8217;ve aligned it to the centre of the page.</p>
<p>Now let&#8217;s add some styling to the list:</p>
<pre>#food {
	overflow: hidden;
	}

#food li {
	list-style: none;
	width: 200px;
	float: left;
	margin-right: 20px;
	margin-bottom: 30px;
	}</pre>
<p>This should be all we need: a) we&#8217;ve added an overflow of &#8220;hidden&#8221; to the <code>ul</code> (because the elements inside it will be floated, this is the quickest way of clearing it); b) we&#8217;ve removed the default bullet points from the list items, added some width to them and floated them to the left; c) finally, some margins to add a bit of breathing space to the page.</p>
<p>If you check your page now, the layout is broken. The last item on each row has a right margin too, and there is no need for it.</p>
<p>We can fix it with some cool CSS:</p>
<pre>#food li.end-row {
	margin-right: 0;
	}
#food li:nth-child(3n) {
	margin-right: 0;
	}

#food li.first-row {
	clear: left;
	}
#food li:nth-child(3n+1) {
	clear: left;
	}</pre>
<p>Let&#8217;s look at it by steps:</p>
<ol>
<li>We&#8217;ve added this part <code>#food li.end-row</code> because some browsers (ahem!) don&#8217;t understand the more complex selector, so they will need a class to target those list items. We will add this class to our markup via jQuery in a bit.</li>
<li>We wanted to target every third list item within our list. We accomplish that with this selector: <code>#food li:nth-child(3n)</code>. This means that every three <code>li</code> our CSS will do something. (<a href="http://www.w3.org/TR/css3-selectors/#nth-child-pseudo" rel="nofollow" >Read more about the <code>:nth-child()</code> pseudo-class</a> on the W3C website.)</li>
<li><code>#food li.first-row</code>: this selector will just be useful for Internet Explorer, because it needs to have a specific class on the <code>li</code> item so it knows what we&#8217;re talking about.</li>
<li><code>#food li:nth-child(3n+1)</code>: this will target every third <code>li</code> item, but starting from the first one. Here we want to clear these <code>li</code> items on the left, so each line starts fresh.</li>
</ol>
<h3>The JavaScript</h3>
<p>The JavaScript part is only needed to accommodate Internet Explorer. Because it doesn&#8217;t understand the <code>:nth-child</code> selector (yet?), we need to add some very non-semantic classes to the <code>li</code> items we need to target, and we&#8217;ll be doing that via jQuery.</p>
<p>So, the next step is to <a href="http://jquery.com/" rel="nofollow" >download jQuery</a> and link it to the page, placing this bit on the header of the page:</p>
<pre>&lt;script type="text/javascript" src="jquery-1.3.2.min.js"&gt;&lt;/script&gt;</pre>
<p>We will also create our own JavaScript file to instruct the HTML on how to behave with jQuery. Place this after the previous code:</p>
<pre>&lt;script type="text/javascript" src="clear-list.js"&gt;&lt;/script&gt;</pre>
<p>Now on our newly created file (clear-list.js), we&#8217;ll add this code:</p>
<pre>$(document).ready(function () {

	$('#food li:nth-child(3n)').addClass('end-row');
	$('#food li:nth-child(3n+1)').addClass('first-row');

});</pre>
<p>Let&#8217;s focus on what&#8217;s important here. </p>
<p>We are using jQuery to add a class (<code>end-row</code> and <code>first-row</code>) to specific selectors (<code>#food li:nth-child(3n)</code> and <code>#food li:nth-child(3n+1)</code>), and that&#8217;s all you need to know. You can edit those parts according to your own HTML, but it&#8217;s quite simple!</p>
<h3>Conclusion</h3>
<p>In a perfect world, we wouldn&#8217;t need to use jQuery to make this code work. But we don&#8217;t live in a perfect world, and we have Internet Explorer to thank for that.</p>
<p>With this quick and very simple tutorial (for example, the <code>li</code> items have the same height, so I&#8217;m kind of cheating here!) my goal was just to show you can use more advanced CSS selectors, but if your layout breaks or is unusable on some browsers, there are some easy solutions to put it back in place.</p>
<p>You can download the example files here:</p>
<p><a href="/examples/floated-list/floated-list.html" rel="nofollow"  class="example">View example</a> <a href="http://webdesignernotebook.com/downloads/9" class="files" title="Floated List | 110.29 kB">Download source files</a></p>
<p><strong>If you&#8217;d like me to do more quick demonstrations of CSS selectors, just name them in the comments</strong> :)</p>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/css/floated-lists-with-css3-and-jquery/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Belgian Beer Types, or How to Style a Definition List the CSS3 Way</title>
		<link>http://webdesignernotebook.com/css/how-to-style-a-definition-list-css3/</link>
		<comments>http://webdesignernotebook.com/css/how-to-style-a-definition-list-css3/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 08:30:47 +0000</pubDate>
		<dc:creator>Inayaili León</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://webdesignernotebook.com/?p=779</guid>
		<description><![CDATA[Definition lists are an often forgotten HTML element, but they can be used in a wide variety of ways, and are actually the most semantically accurate element in many cases. So let&#8217;s see how we can mix up beer, HTML and CSS3, while explaining the purpose of the definition list element. When to use a [...]]]></description>
			<content:encoded><![CDATA[<p>Definition lists are an often forgotten HTML element, but they can be used in a wide variety of ways, and are actually the most semantically accurate element in many cases. So let&#8217;s see how we can mix up beer, HTML and CSS3, while explaining the purpose of the definition list element.</p>
<p><span id="more-779"></span></p>
<h3>When to use a DL</h3>
<p>First, what has the W3 to say about this?</p>
<blockquote><p>
Definition lists vary only slightly from other types of lists in that list items consist of two parts: a term and a description.
</p></blockquote>
<p>That means <strong>we can use them whenever we have something that needs a description</strong>. For example: a list of Belgian beer types, a list of services provided by a company, a list of the persons in a team, etc. Pretty straightforward: instead of using a normal list (<code>ul</code>) with headings and paragraphs in between, we can use an element which already has tags for our definition terms and descriptions.</p>
<h3>The anatomy of a DL</h3>
<p>A definition list is made up by 3 different tags: the opening <code>dl</code> tag; the definition term tag (<code>dt</code>); and the definition description tag (<code>dd</code>). That would look like this:</p>
<pre>&lt;dl&gt;
	&lt;dt&gt;Term goes here...&lt;/dt&gt;
	&lt;dd&gt;Description goes here...&lt;/dd&gt;
&lt;/dl&gt;</pre>
<p>Still easy, right?</p>
<p>To mix things up a bit, we can have more than one term, to more than one definition. For example, a word in a dictionary can have two correct ways of spelling and more than one definition.</p>
<h3>Beer o&#8217;clock</h3>
<p>Now we are going to style a definition list of Belgian beer types (which I recently tried and loved!).</p>
<p>First, some HTML:</p>
<pre>&lt;div id="beers"&gt;

	&lt;h1&gt;A Definition List: Belgian Beer Types&lt;/h1&gt;

	&lt;dl&gt;

		&lt;dt&gt;Amber ales&lt;/dt&gt;
		&lt;dd&gt;These are beers similar to the traditional pale ales of England, although somewhat less bitterly hopped. A notable example is the 5% abv De Koninck brand, with its distinctive spherical glasses (called 'bollekes').&lt;/dd&gt;

		&lt;dt&gt;Blonde or golden ale&lt;/dt&gt;
		&lt;dd&gt;These are a light variation on pale ale, often made with pilsener malt. Some beer writers regard blonde and golden ales as distinct styles, while others do not.&lt;/dd&gt;

		&lt;dt&gt;Brown Ale&lt;/dt&gt;
		&lt;dd&gt;Regular bruin or brune beers such as Grottenbier are darker than amber ales, less sour than Flemish brown ale, and less strong than dubbel.&lt;/dd&gt;

		&lt;dt&gt;Dubbel&lt;/dt&gt;
		&lt;dd&gt;Dubbel has a characteristic brown color. It is one of the classic Abbey/Trappist types, having been developed in the 19th century at the Trappist monastery in Westmalle.&lt;/dd&gt;

		&lt;dt&gt;Enkel&lt;/dt&gt;
		&lt;dd&gt;This beer is the basic recipe for what was traditionally a range of three beers of increasing alcohol content.&lt;/dd&gt;

		&lt;dt&gt;Flemish Red&lt;/dt&gt;
		&lt;dd&gt;Typified by Rodenbach, the eponymous brand that started this type over a century ago, this beer's distinguishing features from a technical viewpoint are a specially roasted malt, fermentation by a mixture of several 'ordinary' top-fermenting yeasts and a lactobacillus culture and maturation in oak.&lt;/dd&gt;

	&lt;/dl&gt;

&lt;/div&gt;</pre>
<p>So, we&#8217;re wrapping our content in a nice container (<code>div</code>), then a little descriptive title (<code>h1</code>) for our page and finally our definition list, with the beer types as definition terms (<code>dt</code>) and each description as a <code>dd</code>.</p>
<h3>CSS 3 magic</h3>
<p><em>I should warn you: this WILL NOT work on IE6. The page will still have its colours and main formatting, but none of the sweet CSS 3 styling is going to be seen. When you&#8217;re driving an inferior car, you don&#8217;t expect it to go as fast as a Ferrari, do you? You&#8217;ll still get there, but with less, or no style.</em></p>
<p>First we&#8217;ll <strong>add some defaults</strong> to our stylesheet (you should be using a proper reset on your stylesheets, but let&#8217;s make things simpler here), and we&#8217;ll also <strong>style the container</strong> <code>div</code>:</p>
<pre>body {
	margin: 0;
	padding: 20px;
	text-align: center;
	background: #fff;
	}

h1,
dl, dt, dd,
p,
a {
	margin: 0;
	padding: 0;
	}

#beers {
	width: 500px;
	padding: 20px;
	margin: auto;
	background: #eeebe3;
	border: 5px solid #5a523d;
	text-align: left;
	}</pre>
<p>Let me know in the comments if you need explaining for this part&#8230;</p>
<p>Now onto the type bit:</p>
<pre>h1 {
	font: 32px "Delicious-Bold", "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif;
	text-align: center;
	color: #3d3111;
	margin-bottom: 20px;
	}

p {
	font: 16px/1.3 "Delicious-Bold", "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif;
	}</pre>
<p>And this is where the fun begins: <strong>we are going to use the <code>@font-face</code> attribute</strong> to call the Delicious typeface. Remember that this typeface is available for <code>@font-face</code> embedding (you can see a list of available fonts in the Useful links section of this post), but not all are.</p>
<p>We&#8217;ll add this bit to the beginning of our stylesheet, before the <code>body</code> style details, so that all the <code>@font-face</code> info is easily seen. We then only have to call the font we want to use by the <code>font-family</code> value we give it here (see code above):</p>
<pre>@font-face{
	font-family: 'Delicious';
	src: url('Delicious-Roman.otf') format('opentype');
	}

@font-face{
	font-family: 'Delicious-Bold';
	src: url('Delicious-Bold.otf') format('opentype');
	}

@font-face{
	font-family: 'Delicious-Heavy';
	src: url('Delicious-Heavy.otf') format('opentype');
	}</pre>
<p>And now, our definition list:</p>
<pre>dl {
	margin-bottom: 20px;
	}

	dt {
		font: 22px "Delicious-Heavy", "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif;
		text-shadow: rgba(255,255,255,.8) 2px 2px 0;
		text-align: center;
		color: #822020;
		margin-bottom: 5px;
		}</pre>
<p>OK, lots to talk about here!</p>
<p>First we add a <strong>bottom margin</strong> to the <code>dl</code>, so that there is some space between it and the paragraph that comes next.</p>
<p>Then we define the <strong>font size and font family</strong> for our <code>dt</code> (and <code>dd</code>, see bellow, after the image). </p>
<p>We also add a <strong>nice little shadow</strong> to both of them. For that, we are using RGBa colours, which allow us to add, besides the r,g and b values, a transparency value between 1 (fully opaque) and 0 (fully transparent). The values that come after the <code>rgba</code> are the horizontal and vertical offset of the shadow, and then the amount of blur (in this case, zero).</p>
<p>Next, we add some <strong>white space around our terms</strong>, and give it a reddish <strong>colour</strong>.</p>
<p>Finally, we are going to add a <strong>decorative border</strong> to each of our descriptions, but we&#8217;re not using a background because each description has a different length: we need something more flexible, and we need to show off our CSS3 skills too. So we are going to use the <code>border-image</code> property.</p>
<p>The <code>border-image</code> property allows us to use an image and specify how much of its borders we want to apply to the borders of our element.</p>
<p>We need to specify the width of the border of the element, in this case it will be 20px. After that, we will specify the image we&#8217;re using for our border, which in our case is this one:</p>
<p><img src="http://webdesignernotebook.com/wp_livesite/wp-content/uploads/2009/07/bubble.png" alt="bubble" title="bubble" width="328" height="231" class="alignnone size-full wp-image-786" /></p>
<p>(Do you see a nasty light blue background around this image? You&#8217;re using IE6!)</p>
<p>We will also need to say how much of the image we are using for our borders: 20; and how it should behave: will it stretch to the size of the element, or will it be repeated? In our case, we want it to stretch. And this is what we get:</p>
<pre>dd {
	font: 16px "Delicious", "Lucida Grande", "Lucida Sans Unicode", Helvetica, Arial, sans-serif;
	text-shadow: rgba(255,255,255,.5) 1px 1px 0;
	padding: 10px;
	border-width: 20px;
	-moz-border-image: url(bubble.png) 20 stretch;
	-webkit-border-image: url(bubble.png) 20 stretch;
	-khtml-border-image: url(bubble.png) 20 stretch;
	border-image: url(bubble.png) 20 stretch;
	margin-bottom: 30px;
	}</pre>
<p>We are using the <strong>vendor specific properties</strong> so that the <code>border-image</code> is understood by all of them. Someday, we will only need the last line of this bit of code, instead of 4 lines.</p>
<h3>Browser support</h3>
<p>I&#8217;ve said that this is not going to work on IE6. What I didn&#8217;t say, was that it doesn&#8217;t work on IE8 or 7 either. Oh, and Opera will ignore the border-image property (at least on my copy of Opera 9.64, but correct me if I&#8217;m wrong).</p>
<p>For Internet Explorer to understand the <code>@font-face</code> attribute, you will need to use the <abbr title="Embedded OpenType">EOT</abbr> font format, so you will have to duplicate the 3 <code>@font-face</code> attributes and use the .eot files for that.</p>
<h3>Conclusion</h3>
<p>Hopefully this made it a bit easier to understand how definition lists can be really useful, and how CSS 3 makes styling rich designs so much easier.</p>
<p>You can download the example files bellow, and you can <a href="http://www.josbuivenga.demon.nl/delicious.html" rel="nofollow" >grab the Delicious font from here</a>.</p>
<p><a href="/examples/css-belgium-beers-dl/css-belgium-beers-dl.html" rel="nofollow"  class="example">View example</a> <a href="http://webdesignernotebook.com/downloads/8" class="files" title="CSS Belgian Beers Definition List | 5.82 kB">Download source files</a></p>
<p>Was this post too short? Did you need more details to understand what just happened? Let me know in the comments.</p>
<h3>Useful links</h3>
<ul>
<li><a href="http://webfonts.info/wiki/index.php?title=Fonts_available_for_%40font-face_embedding" rel="nofollow" >Fonts available for @font-face embedding</a></li>
<li><a href="http://www.w3.org/TR/html401/struct/lists.html#h-10.3" rel="nofollow" >Lists in HTML documents</a></li>
<li><a href="http://www.smashingmagazine.com/2009/06/15/take-your-design-to-the-next-level-with-css3/" rel="nofollow" >Take Your Design To The Next Level With CSS3</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://webdesignernotebook.com/css/how-to-style-a-definition-list-css3/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
