<?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>Six Revisions &#187; CSS</title>
	<atom:link href="http://sixrevisions.com/category/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://sixrevisions.com</link>
	<description></description>
	<lastBuildDate>Thu, 02 Sep 2010 10:30:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>3 Advanced CSS3 Techniques You Should Learn</title>
		<link>http://sixrevisions.com/css/3-advanced-css3-techniques-you-should-learn/</link>
		<comments>http://sixrevisions.com/css/3-advanced-css3-techniques-you-should-learn/#comments</comments>
		<pubDate>Sun, 15 Aug 2010 16:00:50 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3868</guid>
		<description><![CDATA[
If you&#8217;re reading this, then I can safely assume that you&#8217;ve at least heard of CSS3. The latest version of CSS includes properties that allow you to style your HTML elements with rounded corners, drop shadows, and even color gradients.
However, these techniques  just scratch the surface of what CSS3 can really do. In this [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/3-advanced-css3-techniques-you-should-learn/"><img src="http://images.sixrevisions.com/2010/08/19-01_advanced_css3_ld_img.jpg" width="550" height="200" alt="3 Advanced CSS3 Techniques You Should Learn" /></a></p>
<p>If you&#8217;re reading this, then I can safely assume that you&#8217;ve at <a href="http://sixrevisions.com/css/20-useful-resources-for-learning-about-css3/" title="20 Useful Resources for Learning about CSS3 - sixrevisions.com">least heard of CSS3</a>. The latest version of CSS includes properties that allow you to style your HTML elements with <a href="http://sixrevisions.com/css/basic-css3-techniques-that-you-should-know/" title="Basic CSS3 Techniques That You Should Know - sixrevisions.com">rounded corners, drop shadows</a>, and even <a href="http://sixrevisions.com/css/css3-techniques-you-should-know/" title="CSS3 Techniques You Should Know - sixrevisions.com">color gradients</a>.</p>
<p>However, these techniques  just scratch the surface of what CSS3 can <em>really</em> do. In this guide, I am going to be talking about <strong>three advanced CSS3 techniques.</strong></p>
<p><span id="more-3868"></span></p>
<h3>View Demo</h3>
<p>Here is a single demo page of all the code I&#8217;ll be using in this guide. It&#8217;s best viewed on WebKit browsers (like Google Chrome and Apple Safari) so you can see the CSS3 <code>-webkit</code> animation properties in action.</p>
<p><a class="more-link" href="http://demos.sixrevisions.com/2010/08/19/index.html">View Demo</a></p>
<h3>1.  Advanced Selectors</h3>
<p>One of the most important but under-hyped features of CSS3 is the new advanced selectors. I&#8217;m sure I don&#8217;t have to tell you why being able to target specific  HTML elements without having to use an ID attribute is a good thing!</p>
<p>Traditionally, CSS selectors have always been: IDs (<code>#id</code>), classes (<code>.class</code>), HTML elements (such as <code>p</code>), and occasionally pseudo-classes like <code>:hover</code> or <code>:active</code>.</p>
<p>The problem with this formula is that nearly every element needs to have a <em>hook</em>. This means that to get specific with what you&#8217;re selecting, the element needs to have either an ID (if it&#8217;s just one element) or a class (if it&#8217;s a group of elements) so that the browser knows what you&#8217;re talking about.</p>
<p>When you start working with very complex layouts, the amount of IDs and classes you need to add to your markup begins to slow you (and your web pages) down.</p>
<p>Enter CSS3. With numerous new pseudo-classes to choose from, your markup and <a href="http://sixrevisions.com/web-development/five-ways-to-speed-up-page-response-times/" title="Five Ways to Speed Up Page Response Times - sixrevisions.com">page response times</a> will thank you.</p>
<p>To demonstrate some of these new selectors, I&#8217;ve marked up a simple example: two unordered lists.</p>
<pre>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;body&gt;
  &lt;ul&gt;
    &lt;li&gt;First Line&lt;/li&gt;
    &lt;li&gt;Second Line&lt;/li&gt;
    &lt;li&gt;Third Line&lt;/li&gt;
    &lt;li&gt;Fourth Line&lt;/li&gt;
    &lt;li&gt;Fifth Line&lt;/li&gt;
    &lt;li&gt;Sixth Line&lt;/li&gt;
  &lt;/ul&gt;
  &lt;ul&gt;
    &lt;li&gt;First Line&lt;/li&gt;
    &lt;li&gt;Second Line&lt;/li&gt;
    &lt;li&gt;Third Line&lt;/li&gt;
    &lt;li&gt;Fourth Line&lt;/li&gt;
    &lt;li&gt;Fifth Line&lt;/li&gt;
    &lt;li>Sixth Line&lt;/li&gt;
  &lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The following code block  is  some basic CSS just for visuals. All I&#8217;ve done is reset the margins and padding of every element using the universal selector (<code>*</code>) and applied some basic styles to both unordered lists.</p>
<pre>
* {
  margin: 0;
  padding: 0;
}
ul {
  list-style-type: none;
  margin: 2%;
  border: 1px solid #ccc;
  padding: 5px;
  width: 44%;
  float: left;
}
ul li {
  margin-bottom: 5px;
  padding: 2px;
}</pre>
<p>Now it&#8217;s time to write our first advanced selector! (Don&#8217;t be scared!)</p>
<p>The first part of our selector just says to select the <code>&lt;ul&gt;</code> that is the <strong>first child</strong> of another element (the <code>&lt;body&gt;</code> in this case).</p>
<p>Then it goes on to select the <strong>odd</strong> list items (first, third, fifth, and so on) in the first unordered list.</p>
<p>As you can see, using a combination of pseudo-classes and HTML element selectors, we&#8217;ve managed to only select the first of the two <em>identical</em> unordered lists.</p>
<pre>
ul<strong>:first-child</strong> li:nth-child(odd)</pre>
<p>Another way of doing this is shown below, which does the same thing except this time it does so by selecting the first <code>&lt;ul&gt;</code> on the page, regardless of whether or not it&#8217;s the first child of another element.</p>
<pre>
ul<strong>:first-of-type</strong> li:nth-child(odd)
</pre>
<p> As you progress further into using  CSS selectors, you&#8217;ll find that there are many ways of doing the same thing, and it&#8217;s up to you to decide which one to use.</p>
<p>With the first unordered list selected, we can style the odd list items (we will give them a different background color than the other list items).</p>
<pre>
ul:first-child li:nth-child(odd) {
  background-color: #d2fffe;
  border: 1px solid #000;
}</pre>
<p>That isn&#8217;t the only way of using <code>:nth-child</code>, though. We can also use it to style individual elements based on their position. The code block below gives the <strong>5th list item</strong> of the <strong>first unordered list</strong>  on our web page a pink background.</p>
<pre>
body > ul:first-child li:nth-child(5) {
  background: #ffd2d2;
}</pre>
<p><img src="http://images.sixrevisions.com/2010/08/19-02_first_ulstyled.png" width="550" height="145" /></p>
<p>For another example, let&#8217;s add   a web form to our HTML document. Please note the fact that one of the input elements (<code>name=email</code>) has the Boolean attribute of <code>disabled</code> so that I can demonstrate the <code>:disabled</code> pseudo-class later on.</p>
<pre>
&lt;form method="post" action="#"&gt;
&lt;p&gt;
  &lt;label for="name"&gt;Name:&lt;/label&gt;
  &lt;input type="text" name="name" value="" /&gt;
&lt;p&gt;
  &lt;label for="email"&gt;Email:&lt;/label&gt;
  &lt;input type="text" name="email" value="" disabled /&gt;
&lt;/p&gt;
&lt;p&gt;
  &lt;label for="message">Message:&lt;/label&gt;
  &lt;textarea name="message">&lt;/textarea&gt;
&lt;/p&gt;
&lt;/form&gt;
</pre>
<p>The following code block is  just some basic styles for our web form. What this will do is remove some default styling on the form and float the labels to the left and the inputs to the right.</p>
<pre>
form {
  clear: both;
  width: 95%;
}
form p {
  margin-bottom: 15px;
  clear: both;
  overflow: hidden;
}
form label {
  float: left;
}
form input, form textarea {
  width: 70%;
  float: right;
  border: 1px solid #000;
}
form textarea {
  height: 50px;
}</pre>
<p>We&#8217;re now going to take advantage of the <code>disabled</code> attribute on the <code>email</code> input to add a darker gray background to it.</p>
<pre>
input:disabled {
  background: #e7e7e7;
}</pre>
<p>Next up, we have a complex-looking selector, but it&#8217;s actually quite simple.</p>
<p>By using the <code>:not</code> pseudo-class, we are selecting everything inside a paragraph that is also inside a form <strong>except</strong> for <code>&lt;textarea&gt;</code> and <code>&lt;label&gt;</code> elements.</p>
<p> Essentially, what this will do is target all form fields that aren&#8217;t textareas.</p>
<pre>
form p *:not(textarea):not(label) {
  height: 20px;
}</pre>
<p>In actual practice, it would be more efficient to use <code>input</code> as the selector in our particular case,  but I chose to do it this way to demonstrate the <code>:not</code> selector and how we can chain different pseudo-classes together to produce a  more specific selector.</p>
<p>That&#8217;s it for advanced selectors. We   covered a lot, but we still have two more techniques to look at! Let&#8217;s get started with those.</p>
<h3>2. Animations</h3>
<p>Animation on the web has long been the domain of Flash and JavaScript. Now, with CSS3, it&#8217;s possible to do the same sorts of animation with only a few lines of code!</p>
<p>To demonstrate animation techniques, let&#8217;s add another section to our markup: a simple div with no class or ID, and inside it, an <code>&lt;h1&gt;</code> &#8212; nothing too fancy. </p>
<pre>
&lt;div&gt;
  &lt;h1&gt;Hover over to see animation&lt;/h1&gt;
&lt;/div&gt;
</pre>
<p>Since it&#8217;s our first div, we can use the <code>:first-of-type</code> pseudo-class to select it. I&#8217;ve made it a 200px by 200px blue box  just to make it easy to see. I&#8217;ve also styled the <code>h1</code> for visuals.</p>
<pre>
div:first-of-type {
  width: 200px;
  height: 200px;
  background: blue;
  color: #fff;
  clear: both;
}
h1 {
  color: #fff;
  font: 30px/1.5 Helvetica, Arial, sans-serif;
  width: 150px;
  margin: 25px auto;
}</pre>
<p><img src="http://images.sixrevisions.com/2010/08/19-03_blue_box.png" width="212" height="212" alt="3 Advanced CSS3 Techniques You Should Learn" /></p>
<p>Now comes the fun part! To create the animation, add the following three lines to the <code>div:first-of-type</code> selector. You&#8217;ll see nothing yet, but this sets the stage for the animation functionality, which will kick in when the box is hovered on.</p>
<pre>
-webkit-transition-property: background, border;
-webkit-transition-duration: 2s, 1s;
-webkit-transition-timing-function: linear, ease-in-out;</pre>
<p>I&#8217;m using three properties to define two animations for the box (<code>background</code> and <code>border</code>). By adding commas between the properties of each option, I can distinguish which ones will be applied to which animation.</p>
<p>The <code>-webkit-transition-property</code> value defines which CSS properties will be animated (background and border).</p>
<p>The <code>-webkit-transition-duration</code> property defines how long the animation transition will be &#8212; in this case, 2 seconds for the background and 1 second for the border.</p>
<p>The last <code>-webkit-transition-timing-function</code> tells the browser what equation to use for the transition.</p>
<p>So we&#8217;ve set the stage for the animation, but we haven&#8217;t added any animation yet!</p>
<p>Let&#8217;s fix that by declaring our <code>:hover</code> properties.</p>
<pre>
div:first-of-type:hover {
  background: #ccc;
  border: 20px solid blue;
}</pre>
<p>Now, when you hover over our blue box, the background and border will change and grow. That&#8217;s it. We don&#8217;t have to add any other code, the animation will run automatically!</p>
<p>We&#8217;re not done yet, let&#8217;s add one more example animation to the markup.</p>
<pre>
&lt;div onclick="this.style.webkitTransform='rotate(360deg)'"&gt;
  &lt;h1>Click me!&lt;/h1&gt;
&lt;/div&gt;&lt;!--end clickable--&gt;
</pre>
<p>I&#8217;ve used a bit of inline Javascript so that when the div is clicked, it rotates itself around 360 degrees (in production, you will want to do this unobtrusively by using JavaScript DOM selection methods &#8212; but that&#8217;s out of the scope of this guide).</p>
<p>Next for the CSS, we&#8217;ll use the <code>:last-child </code> pseudo-class (since we want to target the  last div in our HTML).</p>
<pre>
div:last-child {
  width: 95%;
  height: 100px;
  -webkit-transition: -webkit-transform 3s ease-in;
  background: rgba(0,0,0,.5);
  cursor: pointer;
}</pre>
<p> The things to note about the above CSS code block is that the background property uses the <code>rgba</code> property to give the div a semitransparent background. The other thing to note is the use of the <code>-webkit-transition</code> property shorthand to animate the rotation of the div.</p>
<p><img src="http://images.sixrevisions.com/2010/08/19-04_spinning_click.png" width="550" height="326" /></p>
<p>And with that, we&#8217;re done with the animation. It&#8217;s full steam ahead to the last CSS3 technique we&#8217;ll cover: media queries.</p>
<h3>3. Media Queries</h3>
<p>The third and last advanced CSS3 technique I&#8217;ll be discussing is media queries. What are they? Media queries allow web designers to add conditional CSS rules depending on what the user is using to view the web page.</p>
<p>The advantage of this is that we can make new rules on how to display a web page depending on the situation of our user. For example, if their viewport&#8217;s width is thinner than 800 pixels, we can adjust the layout accordingly, giving us a truly fluid and flexible layout. So how do we do it? Easy.</p>
<pre>
<strong>@media</strong> screen and (max-width:800px) {
  ...properties when browser is 800px or less...
}</pre>
<p>If you open up the demo in a web browser that supports media queries, you will see that as you reduce the size of the browser, the boxes change sizes, which is great.</p>
<p>However, wouldn&#8217;t it be awesome if when the browser&#8217;s width gets reduced, the two lists stop floating? Yes, it would be. And the CSS for that is the following:</p>
<pre>
@media screen and (max-width:800px) {
  ul {
    float: none;
    max-width: auto;
    width: auto;
  }
}</pre>
<p><img src="http://images.sixrevisions.com/2010/08/19-05_media_query.png" width="550" height="350" /></p>
<p>While we&#8217;re at it, let&#8217;s make a few other changes. In the following code block, we&#8217;ll make it so that the first div disappears if the viewport is less than 800px.</p>
<pre>
div:first-of-type {
  display: none;
}</pre>
<p>Now when the browser is reduced past 800px, the blue box will disappear!</p>
<p>We can even have multiple <code>@media</code> rules in one document. How about we do something else if the browser is lowered to 600px in width?</p>
<pre>
@media screen and (max-width:600px) {
  ul:last-of-type {
    display: none;
  }
}</pre>
<p>Now, when you reduce the browser a little more (less than 600px) &#8212; like magic &#8212; the second unordered list disappears!</p>
<p>Here&#8217;s some styles for when the width is reduced to 400px.</p>
<pre>
@media screen and (max-width: 400px) {
  div:last-child, form {
    display: none;
  }
  ul:first-of-type {
    height: auto;
    padding: 50px;
  }
  ul:first-of-type li {
    margin-bottom: 50px;
  }
}</pre>
<p>I hope you see the potential of media queries, especially with the growing number of ways people view websites (<a href="http://sixrevisions.com/user-interface/a-quick-look-at-mobile-web-designs/" title="A Quick Look at Mobile Web Designs - sixrevisions.com">such as through mobile devices</a>).</p>
<h3>Wrapping Up</h3>
<p>Now you  know  three advanced CSS3 techniques! Give yourself a pat on the back, you deserve it.</p>
<p>It&#8217;s important to note that while the selectors and media queries will work in most modern browsers (Firefox, Safari, Chrome), the animation will only work on Webkit-based browsers like Safari and Chrome.</p>
<h3>Further Reading</h3>
<ul>
<li><a href="http://www.w3.org/TR/css3-selectors/">Selectors</a> (W3C specs)</li>
<li><a href="http://webkit.org/blog/138/css-animation/">CSS Animation</a> (WebKit&#8217;s blog)</li>
<li><a href="http://www.w3.org/TR/css3-mediaqueries/">Media Queries</a> (W3C specs)</li>
<li><a href="http://css-tricks.com/css-media-queries/">CSS Media Queries &amp; Using Available Space</a></li>
<li><a href="http://sixrevisions.com/css/css3-demos-experiments/">10 Interesting CSS3 Experiments and Demos</a></li>
<li><a href="http://sixrevisions.com/css/semantic-css3-lightboxes/">Semantic CSS3 Lightboxes</a></li>
<li><a href="http://sixrevisions.com/css/examples-of-css3-in-the-wild/">Examples of CSS3 in the Wild</a></li>
</ul>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/">How to Create Inset Typography with CSS3</a></li>
<li><a href="http://sixrevisions.com/css/examples-of-css3-in-the-wild/">Examples of CSS3 in the Wild</a></li>
<li><a href="http://sixrevisions.com/interviews/six-questions-eric-meyer-on-css3/">Six Questions: Eric Meyer on CSS3</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/max_luzuriaga_small.jpg" alt="" width="80" height="80" /><strong>Max Luzuriaga</strong> is a freelance web designer (see his work on his <a href="http://www.maxluzuriaga.com/">portfolio site</a>). He&#8217;s also a design blogger at <a href="http://www.thedesigngnome.com/">The Design Gnome</a>. He likes web standards and loves talking in the third person. Follow him on Twitter as @<a href="http://twitter.com/designgnome">designgnome</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/3-advanced-css3-techniques-you-should-learn/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>10 Interesting CSS3 Experiments and Demos</title>
		<link>http://sixrevisions.com/css/css3-demos-experiments/</link>
		<comments>http://sixrevisions.com/css/css3-demos-experiments/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 16:00:42 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3747</guid>
		<description><![CDATA[
You&#8217;ve heard it plenty of times before: We&#8217;re at the precipice of a transition in the way we, as developers, do things. Leading the way are future standards like CSS3 and HTML5, both already partially implemented in 4 out of the 5 major web browsers, with IE9 promising support, empowering us with new ways of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/css3-demos-experiments/"><img src="http://images.sixrevisions.com/2010/07/30-01_css3_demo_experiments_ld_img.jpg" width="550" height="200" alt="10 Interesting CSS3 Experiments and Demos" /></a></p>
<p>You&#8217;ve heard it plenty of times before: We&#8217;re at the precipice of a transition in the way we, as developers, do things. Leading the way are future standards like CSS3 and HTML5, both already partially implemented in 4 out of the 5 <a href="http://sixrevisions.com/infographics/performance-comparison-of-major-web-browsers/">major web browsers</a>, with <a href="http://sixrevisions.com/web-development/five-things-ie9-is-actually-doing-right/" title="Five Things IE9 is (Actually) Doing Right - sixrevisions.com">IE9 promising support,</a> empowering us with new ways of making interactive and rich user experiences.</p>
<p>Just how awesome is CSS3? Find out by checking out these 10 experiments and demos that push the capabilities of the specs.</p>
<p><span id="more-3747"></span></p>
<h3>1. <a href="http://neography.com/experiment/circles/solarsystem/" target="_blank">Our Solar System</a></h3>
<p><a href="http://neography.com/experiment/circles/solarsystem/"><img src="http://images.sixrevisions.com/2010/07/30-02_css3_our_solar_system.jpg" width="550" height="300" alt="Our Solar System" /></a></p>
<p>This experiment presents our solar system&#8217;s planetary orbits (fast-forwarded, of course) by utilizing CSS3&#8217;s <code>border-radius</code>, <code>transform</code>, and <code>animation</code>. Additionally, hovering over the names of each planet on the right displays an animated tooltip using CSS (learn <a href="http://sixrevisions.com/css/css-only-tooltips/" title="Sexy Tooltips with Just CSS - sixrevisions.com">how to make CSS3 animated tooltips</a>). You can read about how this experiment was developed from <a href="http://neography.com/journal/our-solar-system-in-css3/" title="Our Solar Sys­tem in CSS3 - neography.com">this walkthrough</a> by Alex Girón, the creator of this stellar CSS3 demonstration. The animation, at the moment, only works on the WebKit browsers (Google Chrome and Safari).</p>
<h3>2. <a href="http://www.sencha.com/deploy/css3-ads/">CSS3 Ads Versus Flash Ads</a></h3>
<p><a href="http://www.sencha.com/deploy/css3-ads/"><img src="http://images.sixrevisions.com/2010/07/30-03_css3_flash_ads.png" width="550" height="300" alt="CSS3 Ads Versus Flash Ads" /></a></p>
<p>Flash animated web banners are notorious for being intrusive in the user&#8217;s experience. Ad-blocking apps can turn these off by looking for all embedded Flash objects on a web page and hiding them. However, using CSS3 animation, these Flash ads can be mimicked in functionality, but will be harder to disable with third-party software. In this experiment, several ads were recreated using CSS3, and the results are almost identical to their Flash-constructed counterpart.</p>
<h3>3. <a href="http://www.optimum7.com/css3-man/animation.html" target="_blank">CSS3-Man</a></h3>
<p><a href="http://www.optimum7.com/css3-man/animation.html"><img src="http://images.sixrevisions.com/2010/07/30-05_css3-man.png" width="550" height="300" alt="CSS3-Man" /></a></p>
<p>This is a robust animation sequence inspired by the <a href="http://en.wikipedia.org/wiki/Spider-Man_(1967_TV_series)" title="Spider-Man (1967 TV series) - en.wikipedia.org">Spider-Man</a> animated television series in the 60&#8217;s. Making the sequence work involved using CSS3&#8217;s <code>transform</code>, <code>@key-frame</code> and <code>rotate</code>; a bit of jQuery was used to preload the images as well as HTML5 for the audio. The creator wrote an explanation of <a href="http://www.optimum7.com/internet-marketing/web-development/pure-css3-spiderman-ipad-cartoon-jquery-html5-no-flash.html">how the CSS3-Man animated sequence works</a>, which will give you a general idea of the level of effort involved in this amazing experiment.</p>
<h3>4. <a href="http://tylergaw.com/www/lab/themanfromhollywood/" target="_blank">The Man From Hollywood</a></h3>
<p><a href="http://tylergaw.com/www/lab/themanfromhollywood/"><img src="http://images.sixrevisions.com/2010/07/30-04_css3_kinetic_type.jpg" width="550" height="300" alt="The Man From Hollywood" /></a></p>
<p>This demonstration is an animated sequence (based on <a href="http://en.wikipedia.org/wiki/Kinetic_typography" title="Kinetic typography - en.wikipedia.org">kinetic typography</a>) that explores a way in which we can replace rich animation components such as Flash or After Effects. This proof of concept chiefly utilizes advanced CSS selectors and CSS3 animation, however, it&#8217;s not purely CSS since JavaScript was used to toggle element classes on and off.</p>
<h3>5. <a href="http://icefox.net/anigma/" target="_blank">Anigma</a></h3>
<p><a href="http://icefox.net/anigma/"><img src="http://images.sixrevisions.com/2010/07/30-07_css3_anigma.png" width="550" height="300" alt="Anigma" /></a></p>
<p>We often use Flash (or Silverlight) for rich and interactive web-based video games. This CSS3 demonstration is a puzzle game and a proof-of-concept of how we can use open standards to create games &#8212; though admittedly, not as facile as Flash <em>yet</em> if you compare it to Flash games on sites like Kongregate. HTML5&#8217;s <code>&lt;audio&gt;</code> element was used to embed the sound.</p>
<h3>6. <a href="http://media.24ways.org/2009/14/5/index.html" title="Animated Polaroids">Animated Polaroids</a></h3>
<p><a href="http://media.24ways.org/2009/14/5/index.html"><img src="http://images.sixrevisions.com/2010/07/30-09_css3_polaroids.jpg" width="550" height="300" alt="Animated Polaroids" /></a></p>
<p>This demonstration is of stacked images that look like Polaroids. Hovering over a photograph transitions it smoothly to the front of the stack, making for an interesting interaction for presenting your photo gallery. The demo was made by leveraging <code>transition</code>, <code>transform</code>, dynamic psuedo-selectors (to animate the target element), as well as stylistic properties such as <code>box-shadow</code> for visual effects. Read <a href="http://24ways.org/2009/going-nuts-with-css-transitions">the tutorial</a> on how this was constructed if you&#8217;d like to learn how this was developed.</p>
<h3>7. <a href="http://webstuffshare.com/demo/CSSMusicPlayer/" target="_blank">CSS3 Music Player Menu</a></h3>
<p><a href="http://webstuffshare.com/demo/CSSMusicPlayer/"><img src="http://images.sixrevisions.com/2010/07/30-08_music_player.png" width="550" height="300" alt="CSS3 Music Player Menu" /></a></p>
<p>With HTML5&#8217;s <code>&lt;audio&gt;</code> and <code>&lt;video&gt;</code> APIs, which will enable us to utilize multimedia without dependence from proprietary plugins, we&#8217;ll eventually have a need for GUIs that provide our users with controls for the media we serve them. Though we could use static images in conjunction with other HTML elements (such as buttons) to build these interfaces, using just HTML and CSS to render media controls mean we&#8217;ll have a more malleable solution. This <a href="http://sixrevisions.com/category/user-interface/" title="User Interface category on Six Revisions - sixrevisions.com">user interface</a> for a music player was built using only CSS3 (<code>gradient</code>, <code>border-radius</code>, <code>box-shadow</code> and all that good stuff). Read the explanation on how this was contructed in <a href="http://www.webstuffshare.com/2010/05/css3-music-player-menu/">this tutorial</a>.</p>
<h3>8. <a href="http://www.zurb.com/playground/sliding-vinyl">Sliding Vinyl with CSS3</a></h3>
<p><a href="http://www.zurb.com/playground/sliding-vinyl"><img src="http://images.sixrevisions.com/2010/07/30-10_css3_vinyl.jpg" width="550" height="300" alt="Sliding Vinyl with CSS3" /></a></p>
<p>This demonstration, found in the <a href="http://www.zurb.com/playground/sliding-vinyl">ZURB Playground</a>, takes vinyl album covers that, when hovered on, animates the sliding out of a vinyl record that contains additional controls (&quot;more information&quot; and &quot;play&quot;). This proof of concept could one day be used as an elegant web-based interface for a site that plays music when combined with HTML5&#8217;s  <code>&lt;audio&gt;</code> API.</p>
<h3>9. <a href="http://eriksharp.com/gabs/sun/" target="_blank">Gabriel Sharp&#8217;s Small Planet</a></h3>
<p><a href="http://eriksharp.com/gabs/sun/"><img src="http://images.sixrevisions.com/2010/07/30-06_csse3_small_planet.jpg" width="550" height="300" alt="Gabriel Sharp's Small Planet" /></a></p>
<p>This animated cartoon sequence depicts a fast-forwarded cycle of day and night. It works on WebKit browsers (Safari and Chrome) using the <code>@keyframes</code> CSS3 property for moving and transitioning PNG images.</p>
<h3>10. <a href="http://webkit.org/blog-files/leaves/index.html">Falling Leaves</a></h3>
<p><a href="http://webkit.org/blog-files/leaves/index.html"><img src="http://images.sixrevisions.com/2010/07/30-11_css3_animate_fallingleaves.jpg" width="550" height="300" alt="Falling Leaves" /></a></p>
<p>WebKit presents the capabilities of CSS3&#8217;s <code>animate</code> property with a spectacularly smooth demonstration of falling leaves. Tip: Use your browser&#8217;s &quot;view source&quot; feature to read the source code of the demonstration &#8212; the code&#8217;s well documented with explanations of how it works. Read WebKit&#8217;s <a href="http://webkit.org/blog/324/css-animation-2/">blog post</a> about the <code>animate</code> property to get a better feel for all the possibilities.</p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/css/css3-techniques-you-should-know/">CSS3 Techniques You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/basic-css3-techniques-that-you-should-know/">Basic CSS3 Techniques That You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/20-useful-resources-for-learning-about-css3/">20 Useful Resources for Learning about CSS3</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/jacob_gube_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Jacob Gube</strong> is the Founder and Chief Editor of <strong><a href="http://sixrevisions.com/">Six Revisions</a></strong>. He&#8217;s also a web developer/designer who specializes in front-end development (JavaScript, HTML, CSS) and also a <a href="http://www.amazon.com/gp/product/1847194583?ie=UTF8&amp;tag=sixrevi-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1847194583"><strong>book author</strong></a>. If you&#8217;d like to connect with him, head on over to the <a href="http://sixrevisions.com/contact/"><strong>contact page</strong></a> and follow him on Twitter: <strong>@<a href="http://twitter.com/sixrevisions">sixrevisions</a></strong>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/css3-demos-experiments/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Create a CSS3 Call to Action Button</title>
		<link>http://sixrevisions.com/css/create-a-css3-call-to-action-button/</link>
		<comments>http://sixrevisions.com/css/create-a-css3-call-to-action-button/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 12:00:32 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3565</guid>
		<description><![CDATA[
Continuing on with my previous article showing the power of CSS3 for web designers,  I&#8217;m  now going to share with you a method for  making a slick call to action button using only CSS.
Like the last article, I&#8217;m going to take a previous Photoshop tutorial called How to Create a Slick and [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/create-a-css3-call-to-action-button/"><img src="http://images.sixrevisions.com/2010/06/30-01_css3_calltoaction_ld_img.jpg" width="550" height="200" alt="Create a CSS3 Call to Action Button" /></a></p>
<p>Continuing on with my <a href="http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/">previous article</a> showing the power of CSS3 for web designers,  I&#8217;m  now going to share with you a method for  making a slick call to action button using only CSS.</p>
<p>Like the last article, I&#8217;m going to take a previous Photoshop tutorial called <a href="http://sixrevisions.com/tutorials/photoshop-tutorials/how-to-create-a-slick-and-clean-button-in-photoshop/">How to Create a Slick and Clean Button in Photoshop</a> by Six Revisions Chief Editor, Jacob Gube, and try my best to recreate it without using a graphics editor. I think doing this is one of the best ways to highlight the fact that  CSS3 can make our jobs as web designers much easier.</p>
<p>			<span id="more-3565"></span></p>
<p>Check out that Photoshop tutorial and let me know how close I got to recreating its final product.</p>
<h3>Live Demo of CSS3 Call to Action Button</h3>
<p>Here&#8217;s what we&#8217;re going to make. It&#8217;s actually live, so feel free to hover over the button (clicking on it, though, will take you to the Six Revisions front page).</p>
<p>If you can&#8217;t see it right below, you may have iFrames disabled, or are using a browser that doesn&#8217;t yet support these CSS3 modules.</p>
<h4>In-Page Demo</h4>
<p>
<iframe src="http://downloads.sixrevisions.com/css3-call-to-action-button/css3-call-to-action-button-demo.html" height="60" width="100%" frameBorder="0" scrolling="no"></iframe>
</p>
<h4>Screenshot of Call to Action Button</h4>
<p>Here&#8217;s how the call to action button <em>should</em> look like (along with its hover state in blue).</p>
<p><img src="http://images.sixrevisions.com/2010/06/30-07_rounded_corners.jpg" width="225" height="101" alt="Create a CSS3 Call to Action Button" /></p>
<h3>Basic HTML Markup</h3>
<p>Okay, here we go: Let&#8217;s start with the HTML. Very simple here, just a <code>div</code> to contain the button and a normal hyperlink element with a class of <code>.btn</code> (short for &quot;button&quot;) that will represent our call to action button. What a great reminder of what life was like before CSS!</p>
<p><strong>Note:</strong> The <code>div</code> around the hyperlink element is not really needed for this to work, but it&#8217;s always a good idea to have a container for flexibility.</p>
<pre>&lt;div id="linear"&gt;
  &lt;a href="http://www.sixrevisions.com" class="<strong>btn</strong>"&gt;CLICK THIS BUTTON&lt;/a&gt;
&lt;/div&gt;</pre>
<p><img src="http://images.sixrevisions.com/2010/06/30-02_basic_markup.jpg" width="225" height="58" alt="Basic Markup" /></p>
<h3>Basic CSS</h3>
<p>Here we will add our first bit of CSS — just some basic styles for the normal and hover states of the button.</p>
<p><strong>Note:</strong> The background colors will be superseded by CSS3 gradients later on, but it&#8217;s always good practice to have a back-up plan in case the user is using a browser that doesn&#8217;t support CSS3.</p>
<pre>a.btn {
  width: 250px;
  padding: 10px 25px 10px 25px;
  font-family: Arial;
  font-size: 16px;
  text-decoration: none;
  color: #ffffff;
  <strong>background-color: #98ba3f;</strong>
}

a.btn:hover {
  <strong>background-color: #245191;</strong>
}</pre>
<p><img src="http://images.sixrevisions.com/2010/06/30-03_basic_style.jpg" width="225" height="101" alt="Basic Styles" /></p>
<h3>Give the Button a text-shadow CSS Attribute</h3>
<p>In this step, we give our call to action button text a subtle text shadow. This actually isn&#8217;t CSS3, but it&#8217;s also not a highly used CSS attribute.</p>
<p>We make the color of the <code>text-shadow</code> attribute different for the normal state and the hover state (using the <code>:hover</code> pseudo-class).</p>
<pre>a.btn {
  text-shadow: -1px -1px 2px <strong>#618926</strong>;
}

a.btn:hover {
  text-shadow: -1px -1px 2px <strong>#465f97</strong>;
}</pre>
<p><img src="http://images.sixrevisions.com/2010/06/30-04_text_shadow.jpg" width="225" height="101" alt="Give the Button text-shadow" /></p>
<h3>Give the Button a Thin Border</h3>
<p>Let&#8217;s add a thin, 1px border to both button states to make the button a bit more interesting.</p>
<pre>a.btn {
  <strong>border: 1px solid #618926;</strong>
}

a.btn:hover {
  <strong>border: 1px solid #0f2557;</strong>
}</pre>
<p>Since up to this point we have only used CSS2 specs, this is how our call to action button will look like (degrade) in older web browsers.</p>
<p><img src="http://images.sixrevisions.com/2010/06/30-05_border.jpg" width="225" height="101" alt="Give the Button 1px Borders" /></p>
<h3>Round the Corners with CSS3</h3>
<p>Alright, here&#8217;s where things get interesting. We are going to use CSS3 to add a subtle rounded corner effect to the button.</p>
<p>Using browser vendor prefixes (e.g. <code> -moz-</code> for Mozilla browsers), we can add a 3px <code>border-radius</code> attribute to the <code>.btn</code> class that will round the corners of the button.</p>
<p> <strong>Tip:</strong> To learn more about some CSS3 basics and why we have to use those crazy-looking vendor prefixes, check out my previous article called <a href="http://sixrevisions.com/css/css3-techniques-you-should-know/">CSS3 Techniques You Should Know</a>.</p>
<pre>a.btn {
  border-radius: 3px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
}

a.btn:hover {
  border-radius: 3px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
}</pre>
<p>It&#8217;s not a huge change, but it looks more interesting. Agree?</p>
<p><img src="http://images.sixrevisions.com/2010/06/30-06_rounded_corners.jpg" width="225" height="101" alt="Give the Button 1px Borders" /></p>
<h3>Add CSS3 Gradients</h3>
<p>In this final step, we add in the styles that really make this button come to life.</p>
<p>We implement the background gradients that give the button its characteristic slick/modern look. We need a starting and ending gradient color, as well as a stop color in between.</p>
<p>I&#8217;ll admit, the WebKit version (which affects Apple Safari and Google Chrome) looks pretty complicated. I&#8217;ve seen numerous ways of creating gradients for WebKit-based browsers, but none of them seem to be as simple as  Mozilla browsers&#8217; method.</p>
<pre>a.btn {
  background: -moz-linear-gradient(#98ba40, #a6c250 35%, #618926);
  background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #98ba40),color-stop(.35, #a6c250),color-stop(1, #618926));
}

a.btn:hover {
  background: -moz-linear-gradient(#245192, #1e3b73 75%, #12295d);
  background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #245192),color-stop(.75, #1e3b73),color-stop(1, #12295d));
}</pre>
<p>Here&#8217;s what it should look like (I&#8217;d say it&#8217;s pretty close to the original <a href="http://sixrevisions.com/tutorials/photoshop-tutorials/how-to-create-a-slick-and-clean-button-in-photoshop/">Photoshop tutorial</a> that this is based off of).</p>
<p><img src="http://images.sixrevisions.com/2010/06/30-07_rounded_corners.jpg" width="225" height="101" alt="Gradient" /></p>
<h3>All the CSS Together Now!</h3>
<p>Here is our complete CSS for the <code>.btn</code> class.</p>
<pre>a.btn {
  width: 250px;
  padding: 10px 25px 10px 25px;
  font-family: Arial;
  font-size: 16px;
  text-decoration: none;
  color: #ffffff;
  text-shadow: -1px -1px 2px #618926;
  background: -moz-linear-gradient(#98ba40, #a6c250 35%, #618926);
  background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #98ba40),color-stop(.35, #a6c250),color-stop(1, #618926));
  border: 1px solid #618926;
  border-radius: 3px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
}

a.btn:hover {
  text-shadow: -1px -1px 2px #465f97;
  background: -moz-linear-gradient(#245192, #1e3b73 75%, #12295d);
  background: -webkit-gradient(linear,left top,left bottom,color-stop(0, #245192),color-stop(.75, #1e3b73),color-stop(1, #12295d));
  border: 1px solid #0f2557;
}</pre>
<h3>Finished!</h3>
<p>There you have it! With a relatively low number of styles, we get a button that looks quite similar to the Photoshop version. If you weren&#8217;t already as excited as I am about CSS3, then hopefully this article will encourage you to explore and use this next iteration of CSS.</p>
<p><img src="http://images.sixrevisions.com/2010/06/30-07_rounded_corners.jpg" width="225" height="101" alt="Gradient" /></p>
<h3>More CSS3 Reading</h3>
<p>Read these other articles and tutorials to learn more about CSS3.</p>
<ul>
<li><a href="http://sixrevisions.com/css/css3-techniques-you-should-know/">CSS3 Techniques You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/basic-css3-techniques-that-you-should-know/">Basic CSS3 Techniques That You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/semantic-css3-lightboxes/">Semantic CSS3 Lightboxes</a></li>
<li><a href="http://sixrevisions.com/css/examples-of-css3-in-the-wild/">Examples of CSS3 in the Wild</a></li>
<li><a href="http://sixrevisions.com/css/20-useful-resources-for-learning-about-css3/">20 Useful Resources for Learning about CSS3</a></li>
</ul>
<h3>Download Source Files</h3>
<ul>
<li><a href="http://downloads.sixrevisions.com.s3.amazonaws.com/css3-call-to-action-button/css3-call-to-action-button-demo.zip">css3-call-to-action-button-demo</a> (ZIP, 0.1 KB)</li>
</ul>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/tutorials/web-development-tutorials/create-an-animated-call-to-action-button/">Create an Animated &quot;Call to Action&quot; Button</a></li>
<li><a href="http://sixrevisions.com/tutorials/photoshop-tutorials/how-to-create-a-slick-and-clean-button-in-photoshop/">How to Create a Slick and Clean Button in Photoshop</a></li>
<li><a href="http://sixrevisions.com/web_design/a-look-into-registration-buttons-in-web-design/">A Look into Registration Buttons in Web Design</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web_design/">Web Design</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/andrew_roberts_small.jpg" alt="" width="80" height="80" /><strong>Andrew Roberts</strong> is a Christian with a passion for web design and development. His web interests focus mostly on HTML/CSS, JavaScript, &amp; PHP/MySQL. When he&#8217;s not glued to the computer, he&#8217;s spending time with his girlfriend Kaitlynn, <a href="http://www.flickr.com/photos/zoonino">photographing animals</a>, or reading. His goal is to attend graduate school for Biblical Studies &amp; Ministry.</p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/create-a-css3-call-to-action-button/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Saving Bandwidth and Improving Site Speed Using CSS Sprites</title>
		<link>http://sixrevisions.com/css/css-sprites-site-speed/</link>
		<comments>http://sixrevisions.com/css/css-sprites-site-speed/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 09:41:02 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3552</guid>
		<description><![CDATA[
As a site owner, possibly the worst experience that you could serve upon your visitors is a frustrating wait whilst the clock spins and the page loads. In most cases, most of your potential customers would have pressed the back button in their browser and headed off somewhere else; this inevitably means a loss of [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/css-sprites-site-speed/"><img src="http://images.sixrevisions.com/2010/06/28-01_css_sprite_ld_bandwidth_ld_img.jpg" width="550" height="200" alt="Saving Bandwidth and Improving Site Speed Using CSS Spites" /></a></p>
<p>As a site owner, possibly the worst experience that you could serve upon your visitors is a frustrating wait whilst the clock spins and the page loads. In most cases, most of your potential customers would have pressed the back button in their browser and headed off somewhere else; this inevitably means a loss of potential business.</p>
<p>Site speed is predicted to become one of Google&#8217;s next <a href="http://googlewebmastercentral.blogspot.com/2010/04/using-site-speed-in-web-search-ranking.html" title="Using site speed in web search ranking - googlewebmastercentral.blogspot.com">ranking factors</a>, although as per normal, the company tends to keep the nitty-gritty close to its chest.</p>
<p><span id="more-3552"></span></p>
<p>In a <a href="http://searchengineland.com/site-speed-googles-next-ranking-factor-29793" title="Site Speed, Google’s Next Ranking Factor - searchengineland.com">presentation in Las Vegas</a>, when pressed on the subject of site speed integration into the Google search ranking algorithm, Matt Cutts, member of the Search Quality group at Google and a highly-regarded person in the SEO community, described this as one of his &quot;what to expect in 2010&quot; bullet points. He went on to explain that the company wanted search to be &quot;real fast, as if you are flipping through a magazine.&quot;</p>
<p>What all of this should tell us is that if you wish your site to be user-friendly and well-positioned within the ranks of the major search engines, then you should be looking at ways to improve  your <a href="http://sixrevisions.com/web-development/10-ways-to-improve-your-web-page-performance/" title="10 Ways to Improve Your Web Page Performance - sixrevisions.com">web page performance</a>. Apart from the myriad of options displayed in Google <a href="https://www.google.com/webmasters/tools/home?hl=en">Webmaster Tools</a>, including consolidating and compression of external files, and <a href="http://sixrevisions.com/website-management/find-remove-broken-links/" title="How to Find and Remove Broken Links in Your Website - sixrevisions.com">checking for broken links on your website</a>, I would recommend looking at the way you use images. One of the best <a href="http://www.freshegg.com/web-design.htm" title="Web Design | Web Development | SEO Website Designers - www.freshegg.com">web design</a> techniques out there is the use of CSS sprites.</p>
<h3>What are CSS Sprites?</h3>
<p>It may be a common misconception that a sprite implies a series of small images. The opposite, in fact, is the truth — a <a href="http://css-tricks.com/css-sprites/">CSS sprite</a> is one large image.</p>
<p>You may be aware of the CSS technique of displaying an &quot;on/off&quot; state for a button which is contained within a single image and positioned using the <code>background-position</code> CSS attribute on <code>:hover</code> (see the tutorial on a <a href="http://sixrevisions.com/tutorials/web-development-tutorials/create-an-animated-call-to-action-button/" title="Create an Animated “Call to Action” Button - sixrevisions.com">button that uses CSS sprites</a>). CSS sprites are basically the same concept: The image is displayed on the page using the coordinates specified in your CSS, and only this area will be visible.</p>
<p>It is easy to believe that a number of small images are likely to be  less heavy in total file size than one containing all of the images positioned together. But even if you may have images that are only a few bytes in size,  each one is giving your web server unnecessary work to do by sending an HTTP request. Each request contains a portion of overhead information that uses valuable site bandwidth.</p>
<p>Using CSS sprites can reduce the number HTTP requests and can make the web page seem more responsive because all interface elements are already downloaded before the user handles them. This technique can be very effective for improving site performance, particularly in situations where many small images, such as menu icons, are used.</p>
<h3>Building a Basic CSS Image Background Sprite</h3>
<p>Let&#8217;s discuss this topic using an example. Using Photoshop, I created a document with a series of images (logos of companies) and divided the area into chunks of 100 pixels (see the images below). I saved the file and named it <code>logos.jpg</code>.</p>
<p>I used 100-pixel measurements between logos for the purposes of illustrating the concept in this article and because this was a convenient distance to move the position of the CSS background image each time when manipulating the coordinates in my CSS (you should be more accurate when actually applying CSS sprites to reduce its file size further).</p>
<p>The CSS background image  is focused on displaying only the first logo as defined by the green border — the coordinates of which are y = 0 and x = 0.</p>
<p><img src="http://images.sixrevisions.com/2010/06/28-02_css_sprite_01.jpg" width="550" height="64" alt="What are CSS Sprites?" /></p>
<p>To position them, we use the <code>background-position</code> attribute.</p>
<p><img src="http://images.sixrevisions.com/2010/06/28-03_css_sprite_02.png" width="550" height="116" alt="What are CSS Sprites?" /></p>
<p>To display the second image alongside the first, all that is necessary is to adjust the coordinates on the x-axis.</p>
<p>Because of the way we have constructed the image (at 100-pixel intervals), all we need do is add a line of CSS advancing the x-axis by 100 pixels to display each logo.</p>
<p><img src="http://images.sixrevisions.com/2010/06/28-04_css_sprite_03.png" width="550" height="116" alt="" /></p>
<h4>CSS for the CSS Background Sprite</h4>
<pre>
#logos {height: 64px; margin: 0; padding: 0; position: relative;}

#logos li {background: url(/logos.jpg) no-repeat top left; margin: 0; padding: 0; list-style: none; position: absolute; top: 0;}

#logos a {height: 64px; display: block;}
<strong>// First logo</strong>
#logos li a.jaz {background-position: 0 0}
<strong>// Second logo</strong>
#logos li a.iberotel {background-position: 0 -100px;}
<strong>// Third logo</strong>
#logos li a.solymar {background-position: 0 -200px;}
<strong>// Fourth logo</strong>
#logos li a.travcotels {background-position: 0 -300px;}
<strong>// Fifth logo</strong>
#logos li a.intercity {background-position: 0 -400px;}</pre>
<h3>The Results of Using CSS Sprites</h3>
<p><img src="http://images.sixrevisions.com/2010/06/28-05_css_sprite_result.jpg" width="550" height="91" alt="The Results" /></p>
<p>In the example above, it was possible to reduce the file size from 52kb to 22kb and the number of HTTP requests from 5 to 1. This represents a good saving, and is only one small section of a web page!</p>
<p>Our new CSS sprite method tests well in most modern browsers.</p>
<h3>Further Reading on CSS Sprites</h3>
<p>Here is a list of suggested reading resources about CSS sprites.</p>
<ul>
<li><a href="http://www.alistapart.com/articles/sprites">CSS Sprites: Image Slicing’s Kiss of Death</a></li>
<li><a href="http://css-tricks.com/css-sprites/">CSS Sprites: What They Are, Why They’re Cool, and How To Use Them</a></li>
<li><a href="http://www.smashingmagazine.com/2009/04/27/the-mystery-of-css-sprites-techniques-tools-and-tutorials/">The Mystery Of CSS Sprites: Techniques, Tools And Tutorials &#8211; Smashing Magazine</a></li>
</ul>
<h3>References</h3>
<ol>
<li id="reference-01"><a href="http://en.wikipedia.org/wiki/Usage_share_of_web_browsers">Usage share of web browsers</a> (May 2010)</li>
</ol>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/web-development/10-ways-to-improve-your-web-page-performance/">10 Ways to Improve Your Web Page Performance</a></li>
<li><a href="http://sixrevisions.com/web-development/five-ways-to-speed-up-page-response-times/">Five Ways to Speed Up Page Response Times</a></li>
<li><a href="http://sixrevisions.com/css/30-exceptional-css-navigation-techniques/">30 Exceptional CSS Navigation Techniques</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/web-development/">Web Development</a> and <a href="http://sixrevisions.com/category/web_design/">Web Design</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/peter_richards_small.jpg" alt="" width="80" height="80" /><strong>Peter Richards</strong> is a SEO engineer based near Brighton in the UK. He has also spent time as web designer and front-end developer (HTML, CSS, JavaScript). If you wish to connect with him, you can follow Peter on Twitter as <strong>@<a href="http://twitter.com/pgrichards">pgrichards</a>.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/css-sprites-site-speed/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Sexy Tooltips with Just CSS</title>
		<link>http://sixrevisions.com/css/css-only-tooltips/</link>
		<comments>http://sixrevisions.com/css/css-only-tooltips/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 10:48:38 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3439</guid>
		<description><![CDATA[
Providing supplementary information about potentially complex elements of a user interface is a central part of any website designer or developer&#8217;s workflow in creating usable and accessible websites.
One of the most common mechanisms for providing extra details beyond what you can see on the page is the tooltip (a design pattern for showing tips about [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/css-only-tooltips/"><img src="http://images.sixrevisions.com/2010/06/08-01_css_tooltip.png" width="550" height="200" alt="Sexy Tooltips with Just CSS" /></a></p>
<p>Providing supplementary information about potentially complex elements of a user interface is a central part of any website designer or developer&#8217;s workflow in creating usable and accessible websites.</p>
<p>One of the most common mechanisms for providing extra details beyond what you can see on the page is the <a href="http://en.wikipedia.org/wiki/Tooltip">tooltip</a> (a design pattern for showing tips about a particular element on a screen).</p>
<p><span id="more-3439"></span></p>
<p>While many innovative solutions exist using CSS and <a href="http://sixrevisions.com/tutorials/javascript_tutorial/create_lightweight_javascript_tooltip/">JavaScript</a> (with and without JavaScript frameworks like jQuery), it&#8217;s sometimes useful to look towards new technologies to examine the impact they may have on our current techniques.</p>
<p>Thus, we&#8217;re going to look at how using the <strong>evolving CSS standard</strong> can enhance some lovely cross-browser tooltips.</p>
<h3>Demonstration of the Sexy Tooltips</h3>
<p>Check out the <a href="http://downloads.sixrevisions.com/css-tooltips/index.html">demo page</a> of the pure CSS tooltip we&#8217;ll be creating.</p>
<ul>
<li><a href="http://downloads.sixrevisions.com/css-tooltips/index.html">Live demo</a></li>
</ul>
<h3>Download the Sexy Tootips Source Files</h3>
<p>If you&#8217;d like the source code to use and follow along, <a href="http://downloads.sixrevisions.com/css-tooltips/css-tooltips.zip">download it</a> below.</p>
<ul>
<li><a href="http://downloads.sixrevisions.com/css-tooltips/css-tooltips.zip">css-tooltips</a> (ZIP, 18.8 KB)</li>
</ul>
<h3>Tooltips are Terrific!</h3>
<p>Whether you need to explain an abbreviation or acronym, to define a word or if you simply want to give additional details based on what someone hovers over, tooltips provide a <strong>simple but effective solution.</strong></p>
<p>From the little yellow block of text that appears over elements such as images with a <code>title</code> attribute (or the <code>alt</code> attribute if you&#8217;re unfortunate enough to use Internet Explorer), right down to the CSS and script-powered solutions that exist, they&#8217;re fantastic devices that unfortunately seem to get little interest from the design community.</p>
<p><img src="http://images.sixrevisions.com/2010/06/08-02_wikipedia_tooltip.png" width="550" height="200" alt="Wikipedia" /><span class="figure-caption">Most browsers have a default style of tooltip, though it&#8217;s not very pretty.</span></p>
<h3>Leveraging Progressive Enhancement in Tooltips</h3>
<p>As standards rapidly evolve and support for new techniques appear within browsers on a more consistent basis, the advances of CSS allow us to produce tooltips (which serve as a replacement for the somewhat boring browser defaults as shown in the image above) to a brand new level of detail and beauty.</p>
<p>If you already use a jQuery-powered example — fear not! — there are still many things JavaScript can accomplish which CSS cannot (like adding a delay on when tooltips disappear), but highlighting the ways we can use CSS to better equip our designs may inspire you to create some beautiful solutions of your own, outside of tooltips.</p>
<p><img src="http://images.sixrevisions.com/2010/06/08-03_tooltip_smorgashborg.png" width="550" height="300" alt="There are many existing solutions for tooltips you can choose between." /><span class="figure-caption">There are many existing solutions for tooltips you can choose from.</span></p>
<h3>What We&#8217;re Going to Make</h3>
<p>In this example, we are going to be producing a <strong>pure CSS tooltip</strong> mechanism that is aesthetically enhanced using <a href="http://sixrevisions.com/css/css3-techniques-you-should-know/" title="CSS3 Techniques You Should Know">CSS3</a> (rather than using it to achieve some higher purpose).</p>
<p>What this means is that <strong>it will work on browsers that don&#8217;t support CSS3</strong> (such as Internet Explorer 8 and below) — it just will not look as pretty. This concept is known as <a href="http://en.wikipedia.org/wiki/Progressive_enhancement" title="Progressive Enhancement - en.wikipedia.org">progressive enhancement</a>.</p>
<p>Subtle effects such as the colors, fonts, imagery and border you give your tooltip may differ depending on the end user&#8217;s machine (such as their browser, installed fonts or monitor contrast).</p>
<h4>CSS3 Extras</h4>
<p>Using simple yet effective extras like the now well-established <code>border-radius</code> property and the <code>box-shadow</code> property will give what used to be a generic-looking &quot;boxy&quot; popups a new and more sophisticated visual appearance.</p>
<h3>Under the Hood</h3>
<p>As always, it makes sense to get some basic code down in your chosen source code editor and we shall begin with the HTML source code for our examples.</p>
<h4>Different Types of Tooltips</h4>
<p>For the benefit of giving you enough ideas to build upon or implement directly into your own work, we shall produce <strong>five different tooltips.</strong></p>
<p>Each will look very similar in order to maintain a standardised appearance, but you should feel free to experiment further and continue evolving these techniques.</p>
<p><img src="http://images.sixrevisions.com/2010/06/08-04_five_tooltips.png" width="550" height="275" alt="You can see how pretty a tooltip can actually be, much better than the default!" /><span class="figure-caption">You can see how pretty a tooltip can actually be, much better than the default at least!</span></p>
<h4>Cross-Browser Compatibility</h4>
<p>This mechanism should work across all browsers, however, if you feel the need, you can tweak it to better suit your own requirements.</p>
<h3>Basic Markup</h3>
<p>On the code block below, we have a generic XHTML 1.0 template with the usual <code>&lt;head&gt;</code> elements that are required.</p>
<p>As we add the CSS into the design, it&#8217;s worth pointing out right now that for the purpose of this tutorial, the CSS will be embedded into the document using the <code>&lt;style&gt;</code> tag.</p>
<p>Separating structure from style is (of course) important, <strong>I highly recommend putting your CSS into a separate stylesheet in production usage.</strong></p>
<p>For ease of discussion, I decided to place the styles inside the HTML document.</p>
<p>I also highly recommend that if you feel that adding jQuery or other JavaScript enhancements may assist the usability of this lovely eye candy, feel free to do so!</p>
<h4>HTML Markup</h4>
<pre>
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
  &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
  &lt;title&gt;ToolTips Example&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;Examples of CSS ToolTips!&lt;/h1&gt;
&lt;p&gt;Here are some examples of a <strong>&lt;a class=&quot;tooltip&quot; href=&quot;#&quot;&gt;Classic&lt;span class=&quot;classic&quot;&gt;</strong>This is just an example of what you can do using a CSS tooltip, feel free to get creative and produce your own!&lt;/span&gt;&lt;/a&gt;, &lt;a class=&quot;tooltip&quot; href=&quot;#&quot;&gt;Critical&lt;span class=&quot;custom critical&quot;&gt;&lt;img src=&quot;Critical.png&quot; alt=&quot;Error&quot; height=&quot;48&quot; width=&quot;48&quot; /&gt;&lt;em&gt;Critical&lt;/em&gt;This is just an example of what you can do using a CSS tooltip, feel free to get creative and produce your own!&lt;/span&gt;&lt;/a&gt;, &lt;a class=&quot;tooltip&quot; href=&quot;#&quot;&gt;Help&lt;span class=&quot;custom help&quot;&gt;&lt;img src=&quot;Help.png&quot; alt=&quot;Help&quot; height=&quot;48&quot; width=&quot;48&quot; /&gt;&lt;em&gt;Help&lt;/em&gt;This is just an example of what you can do using a CSS tooltip, feel free to get creative and produce your own!&lt;/span&gt;&lt;/a&gt;, &lt;a class=&quot;tooltip&quot; href=&quot;#&quot;&gt;Information&lt;span class=&quot;custom info&quot;&gt;&lt;img src=&quot;Info.png&quot; alt=&quot;Information&quot; height=&quot;48&quot; width=&quot;48&quot; /&gt;&lt;em&gt;Information&lt;/em&gt;This is just an example of what you can do using a CSS tooltip, feel free to get creative and produce your own!&lt;/span&gt;&lt;/a&gt; and &lt;a class=&quot;tooltip&quot; href=&quot;#&quot;&gt;Warning&lt;span class=&quot;custom warning&quot;&gt;&lt;img src=&quot;Warning.png&quot; alt=&quot;Warning&quot; height=&quot;48&quot; width=&quot;48&quot; /&gt;&lt;em&gt;Warning&lt;/em&gt;This is just an example of what you can do using a CSS tooltip, feel free to get creative and produce your own!&lt;/span&gt;&lt;/a&gt; CSS powered tooltip. This is just an example of what you can do so feel free to get creative and produce your own!&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Within the above code, you will notice that we have a heading (<code>&lt;h1&gt;</code>) element (nothing special so far) and a paragraph (<code>&lt;p&gt;</code>) of text which contains some anchor  (<code>&lt;a&gt;</code>) elements (with a class value of tooltip).</p>
<h4>Why Use Anchor Tags for Tooltips?</h4>
<p>The reason why anchors rather than <code>abbr</code>, <code>dfn</code> or another element like <code>span</code> is used at this level is due to IE6&#8217;s total lack of support for the <code>:hover</code> pseudo-selector beyond anchor elements.</p>
<p>Therefore, for <a href="http://sixrevisions.com/web-development/definitive-guide-to-taming-the-ie6-beast/" title="Definitive Guide to Taming the IE6 Beast - sixrevisions.com">compatibility reasons</a> I recommend using <code>&lt;a&gt;</code>, though if you don&#8217;t like IE6, you can change it.</p>
<p>Each anchor also contains a <code>span</code> with the content of the tooltip.</p>
<p><img src="http://images.sixrevisions.com/2010/06/08-05_plain_html.png" width="550" height="188" alt="With some basic HTML code, things don't look or function as they will end up." /><span class="figure-caption">With some basic HTML code, things don&#8217;t look or function as they will end up.</span></p>
<p>The anchor effectively acts as a point of reference for the hover effect to occur within, and as we add style into the document, the content of the <code>span</code>s will be hidden off-screen until they&#8217;re required.</p>
<p>Each <code>span</code> in this example either has a class value of <code>classic</code> (denoting a general tooltip) or <code>custom</code> (with <code>critical</code>, <code>help</code>, <code>info</code> or <code>warning</code> to match denoting the color scheme to use).</p>
<p>Those using the custom style also have a couple of bonus features like the <code>em</code> element (denoting the overview text) and an image proceeding it (which acts as the icon for the tooltip, you can even use your own images).</p>
<h3>Basic CSS</h3>
<p>As you will now have the HTML on the page, it&#8217;s time we make these tooltips do their job (rather than spanning the page as normal linked text).</p>
<p>By adding in the code block below into your <code>&lt;head&gt;</code> element, you will give each link containing a tooltip a nice <strong>dotted underline</strong> (differentiating it from normal links which typically have a standard solid underline) and a <strong>help cursor</strong> (again for visual differentiation).</p>
<p>It&#8217;ll also remove the outline and set the color (so it feels less like a link and more like a general hover element).</p>
<p>The second bit of code simply hides the tooltips off-screen until their needed.</p>
<p>Easy as pie!</p>
<h4>Basic CSS Styles for .tooltip Class</h4>
<pre>&lt;style type=&quot;text/css&quot;&gt;
.tooltip {
  border-bottom: 1px dotted #000000;
  color: #000000; outline: none;
  cursor: help; text-decoration: none;
  position: relative;
}
.tooltip span {
  margin-left: -999em;
  position: absolute;
}
&lt;/style&gt;</pre>
<h4>Web Accessibility Considerations</h4>
<p>On a note about maintaining <strong>accessibility:</strong> the outline is removed visually as the link is effectively redundant — it&#8217;s only included for the purpose of compatibility with old versions of IE.</p>
<p>Therefore, the outline itself isn&#8217;t needed to show that the tooltip is a clickable link unless you want it to be, in which case I advise removing that bit of code.</p>
<p>Also for the benefit of screen readers, the tooltip contents are being moved using a negative margin rather than using <code>display: none</code> or <code>visibility: hidden</code> as some screen readers may ignore the content – which would be bad news for screen reader users.</p>
<p><img src="http://images.sixrevisions.com/2010/06/08-06_css_abit.png" width="550" height="81" alt="It's amazing what a bit of CSS can do; now the page appears ready to host the tooltips." /><span class="figure-caption">It&#8217;s amazing what a bit of CSS can do; now the page appears ready to host the tooltips.</span></p>
<h3>CSS for Displaying the Tooltips</h3>
<p>At this stage, hovering over the links will do nothing.</p>
<p>Soon we will have a functioning tooltip that will look about the same through whichever browser you prefer to use, but for now, it&#8217;s time to place the next lines of CSS code in below what you already have.</p>
<p>By adding in the code block that follows, you should have a mechanism that works and displays the tooltips, though it will look very bland and will have little to no appeal (visually) apart from the fact that everything is contained within a box-like shape (which sets the standard for future code to customise further).</p>
<h4>CSS for Showing the Tooltips</h4>
<pre>.tooltip:hover span {
  font-family: Calibri, Tahoma, Geneva, sans-serif;
  position: absolute;
  left: 1em;
  top: 2em;
  z-index: 99;
  margin-left: 0;
  width: 250px;
}
.tooltip:hover img {
  border: 0;
  margin: -10px 0 0 -55px;
  float: left;
  position: absolute;
}
.tooltip:hover em {
  font-family: Candara, Tahoma, Geneva, sans-serif;
  font-size: 1.2em;
  font-weight: bold;
  display: block;
  padding: 0.2em 0 0.6em 0;
}
.classic { padding: 0.8em 1em; }
.custom { padding: 0.5em 0.8em 0.8em 2em; }
<strong>* html</strong> a:hover { background: transparent; }</pre>
<h4>Star HTML Hack Necessity</h4>
<p>You may have noticed that the very last line of code above uses the <a href="http://css-discuss.incutio.com/wiki/Star_Html_Hack">HTML star hack</a> to apply a transparent background to IE6. Why was this included?</p>
<p>Well, while testing the tooltip, I encountered a strange quirk where the hover pseudo was not obeyed unless a background reference existed!</p>
<p><img src="http://images.sixrevisions.com/2010/06/08-07_getting_there.png" width="550" height="150" alt="A lot of CSS later, we have something that functions generally as a tooltip!" /><span class="figure-caption">A lot of CSS later, we have something that functions generally as a tooltip!</span></p>
<p>With the above code in place, everything works and is visible on the page. But it&#8217;s hard to read because there&#8217;s no color scheme that pulls the contrast out from the page and that&#8217;s something we need to <strong>fix right now</strong> to make them usable.</p>
<h3>CSS for Giving the Tooltips Some Color</h3>
<p>The below code will give each of the five styles of tooltip a color scheme which fits the icon (if one exists).</p>
<p>Upon giving your page a quick refresh and hovering over one of the links, you&#8217;ll see a pretty tooltip that looks and works equally across the various web browsers.</p>
<p>Though as you will soon discover, there&#8217;s a bit more to the story still to come!</p>
<h4>CSS for Color Scheme</h4>
<pre>.classic { background: #FFFFAA; border: 1px solid #FFAD33; }
.critical { background: #FFCCAA; border: 1px solid #FF3334; }
.help { background: #9FDAEE; border: 1px solid #2BB0D7; }
.info { background: #9FDAEE; border: 1px solid #2BB0D7; }
.warning { background: #FFFFAA; border: 1px solid #FFAD33; }</pre>
<p>With what you already have (as mentioned above), you&#8217;ll have something a bit basic, but that looks good and does its job in giving you a colourful tooltip that you can give your website design.</p>
<h3>CSS3 for Progressive Enhancement of Sexiness</h3>
<p> Before we leave the example, it&#8217;s worth bringing up CSS3 as we can (literally) take the edge off our tooltips, making it feel a bit less boxy using <code>border-radius</code> and give it a bit of extra depth using the <code>box-shadow</code> property.</p>
<p>Because neither of these elements is globally supported, it won&#8217;t work for every browser, but for those that it does work within, they&#8217;ll look a lot sleeker and sexier!</p>
<p><img src="http://images.sixrevisions.com/2010/06/08-08_css3xy.png" width="550" height="156" alt="Much better! A little style gives the tooltip a visually unique appearance." /><span class="figure-caption">Much better! A little CSS3 gives the tooltip a visually unique appearance.</span></p>
<p>Add the below code into the <code>.tooltip:hover span</code> selector and refresh the page.</p>
<p>The visual effect of the border, shadow and opacity will help lift the tooltips from the page, and that may well make the information and contrast a bit easier to read.</p>
<p>You&#8217;ll see that not only are the official CSS3 properties provided but the Mozilla and WebKit proprietary extensions too.</p>
<p>It&#8217;s worth pointing out that this means your code may not validate (even though it&#8217;s an acceptable bending-of-the-rules scenario), but the experience benefit your visitors will get may well be <a href="http://sixrevisions.com/web-standards/problems-with-using-website-validation-services/">worth the lack of validation</a>.</p>
<h4>Additional CSS for Modern Browsers</h4>
<pre>border-radius: 5px 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.1);
-webkit-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 5px 5px rgba(0, 0, 0, 0.1);</pre>
<p><img src="http://images.sixrevisions.com/2010/06/08-09_rbgacss3.png" width="550" height="160" alt="Using some CSS3 properties, we can improve upon the existing CSS code." /><span class="figure-caption">Using some CSS3 properties, we can improve upon the existing CSS code.</span></p>
<h3>Food for Thought</h3>
<p>As this tutorial shows, it doesn&#8217;t take much in the way of visual eye candy to give our readers a better experience.</p>
<p>While this style of tooltip may have been done before, adding flourishes like image-based icons, CSS3 effects and perhaps the odd bit of opacity (and typography) can help you go beyond a boxy (and rather ugly or limited) tooltip to have something a bit more elegant and pretty.</p>
<p>When using CSS, the key to any successful implementation is ensuring the <strong>experience degrades gracefully</strong> and what you do implement is done tastefully and with subtle enhancements.</p>
<p>Giving your website a few useful tooltips to notify users of the meanings of certain terms or words, explaining a general concept you talk about, or even to provide some meaningful alternative details can not only give your content some added context but it may well help your readers get more from the experience you offer them.</p>
<p>Perhaps the greatest thing the future of CSS offers us is a <strong>fresh opportunity to restudy and rethink our craft to better meet our users&#8217; needs.</strong> I certainly recommend taking this example&#8217;s opportunity to look for other ways to give your content an added layer of interactivity.</p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/tutorials/javascript_tutorial/create_lightweight_javascript_tooltip/">Create a Nice, Lightweight JavaScript Tooltip</a></li>
<li><a href="http://sixrevisions.com/css/30-exceptional-css-navigation-techniques/">30 Exceptional CSS Navigation Techniques</a></li>
<li><a href="http://sixrevisions.com/javascript/10-easy-jquery-tricks-for-designers/">10 Easy jQuery Tricks for Designers</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/alexander_dawson_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Alexander Dawson</strong> is a freelance web designer, author and recreational software developer specializing in web standards, accessibility and UX design. As well as running a business called <strong><a href="http://www.hitechy.com/">HiTechy</a></strong> and writing, he spends time on <strong><a href="http://twitter.com/AlexDawsonUK">Twitter</a></strong>, SitePoint&#8217;s forums and other places, helping those in need.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/css-only-tooltips/feed/</wfw:commentRss>
		<slash:comments>50</slash:comments>
		</item>
		<item>
		<title>The Essential Guide to @font-face</title>
		<link>http://sixrevisions.com/css/font-face-guide/</link>
		<comments>http://sixrevisions.com/css/font-face-guide/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 10:00:46 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3408</guid>
		<description><![CDATA[
Fonts on the Web
The days of being limited to a handful of fonts on the web are very close to being a thing of the past. The problem is no longer a lack of viable solutions, but rather, an abundance of them.
Technologies like Cufon, sIFR, FLIR and @font-face all represent different groups of developers placing [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/font-face-guide/"><img src="http://images.sixrevisions.com/2010/06/02-01_font-face_ld_img.png" width="550" height="200" alt="The Essential Guide to @font-face" /></a></p>
<h3>Fonts on the Web</h3>
<p>The days of being limited to a handful of fonts on the web are very close to being a thing of the past. The problem is no longer a lack of viable solutions, but rather, an abundance of them.</p>
<p>Technologies like Cufon, sIFR, FLIR and <code>@font-face</code> all represent different groups of developers placing bets on what they believe to be the future of web typography.</p>
<p>There is, as of yet, no consensus in this ever-evolving game. All of these methods have perfectly valid arguments both for and against their use.</p>
<p>Further, even the most popular browsers support each of these technologies in widely varying degrees.</p>
<p>		<span id="more-3408"></span></p>
<p>However, the <code>@font-face</code> CSS method is among the strongest, simplest and most flexible competitors in this game. It seems to be the current rockstar of the bunch, garnering all the attention and causing a number of sites to pop up offering both free and premium fonts in support of it.</p>
<p>This guide will teach you how to implement <code>@font-face</code> with <strong>cross-browser compatibility</strong> and will also look at a number of the supporting services that have arisen, making it even easier to use custom fonts in your web designs.</p>
<h3>Licensing and Free Fonts</h3>
<p>Font licensing presents one of the <strong>largest headaches</strong> and stumbling blocks to great typography on the web.</p>
<p>Naturally, font foundries would like to be paid for their work and therefore place strict restrictions on the use of their fonts.</p>
<p>These foundries have teamed up with various premium <code>@font-face</code> solutions that we&#8217;ll discuss later in the article, but for now, we&#8217;ll just dodge the licensing problem completely by using a free font.</p>
<p>The web font licensing problem has caused a major rise in the popularity of sites offering quality free fonts. Among these, the two that I like the best are <a href="http://www.fontsquirrel.com/">Font Squirrel</a> and <a href="http://www.fontex.org/">Fontex</a>. These sites both provide <strong>tons of great resources absolutely free</strong> and even share many of the same font choices. </p>
<h3>The Basic Syntax</h3>
<p><strong>@font-face only requires a few lines of CSS</strong> and is therefore very easy to use without any third party tools.</p>
<p>To get started, stop by one of the free font sites mentioned above and download <a href="http://www.fontex.org/download/Chunkfive.otf">Chunkfive</a> (or any other font you like). </p>
<p>Once you&#8217;ve downloaded the font, place the font file in the root directory of your web page.</p>
<p>Now, go into your stylesheet and insert the following code: </p>
<pre>
@font-face {
	font-family: Chunkfive;
	src: url('Chunkfive.otf');
}</pre>
<p>This snippet gives the custom font an identifier for the rest of your CSS and then points to the font file to use when this identifier is mentioned.</p>
<p>The first line in my code sets an identifier of &#8220;Chunkfive&#8221; to the font. It&#8217;s best to keep things simple by always using the font name, but  you can ultimately use any name you want. &#8220;MyReallyCoolFont&#8221; would work just as well as long as you refer to the font elsewhere using the same name.</p>
<p>The second line tells the browser that when &#8220;Chunkfive&#8221; is called, it should load the font <code>Chunkfive.otf</code> file from the url mentioned. This url is simply wherever you choose to place your fonts file. If you had placed Chunkfive in a  folder called Fonts, this attribute would&#8217;ve read <code>url(Fonts/'Chunkfive.otf')</code>.</p>
<p> When you want to use that font anywhere in your site, <strong>simply build a font stack like you would normally</strong>, using your custom font identifier at the beginning.</p>
<pre>
font-family: <strong>Chunkfive</strong>, Georgia, Palatino, Times New Roman, serif;
</pre>
<p>It&#8217;s important to set up these fallbacks in case the custom font doesn&#8217;t work for some reason.</p>
<p>Make sure to <strong>test your design in at least one of your fallback fonts</strong> to ensure that it doesn&#8217;t cause your layout to break. </p>
<p>Depending on your browser, this should give you a page with a working custom font.</p>
<p>The text should load immediately, is fully selectable and should work  with copy/paste computing functions (a limitation of of other font replacement techniques).</p>
<p><a href="http://images.sixrevisions.com/2010/06/02-02_font-face_example.jpg"><img src="http://images.sixrevisions.com/2010/06/02-02_font-face_example.jpg" width="550" height="157" alt="screenshot" /></a><span class="figure-caption">A screenshot of using Chunkfive on a block of HTML text.</span></p>
<h3>Cross-Browser Compatibility</h3>
<p>It would be nice if using custom fonts online were that easy, but it isn&#8217;t.</p>
<p>Of course, <strong>we can&#8217;t possibly expect all the browsers to play nice and agree on a given solution!</strong> That would just be unreasonable.</p>
<p>Instead, all the major browsers have decided to go their own way with font formats that they choose to support<sup>[<a href="#source-1">1</a>]</sup>.</p>
<ul>
<li>Internet Explorer only supports <strong>EOT</strong></li>
<li>Mozilla browsers support <strong>OTF and TTF</strong></li>
<li>Safari and Opera support <strong>OTF, TTF and SVG</strong></li>
<li>Chrome supports <strong>TTF and SVG.</strong></li>
</ul>
<p>Further, mobile browsers like Safari on the iPad and iPhone require <strong>SVG</strong>.</p>
<p>Confused yet? You should be. Fortunately, <strong>there are brilliant developers that have worked this all out for you</strong> by developing simple systems to follow.</p>
<p>The most popular method of utilizing <code>@font-face</code> across multiple browsers seems to be Paul Irish&#8217;s <a href="http://paulirish.com/2009/bulletproof-font-face-implementation-syntax/">Bulletproof @font-face syntax.</a></p>
<p>Using Irish&#8217;s method, you <strong>include multiple versions of the font</strong> so that it works on all browsers.</p>
<p>In addition, the code contains a little trick that ignores locally-installed fonts with the same name. Though it is much faster to load a local font, it&#8217;s been largely agreed upon that doing so can often have messy results<sup>[<a href="#source-2">2</a>]</sup>. </p>
<p>Let&#8217;s take a look at the Bulletproof Syntax using Chunkfive:</p>
<pre>
@font-face {
	font-family: 'ChunkFiveRegular;
	src: url('Chunkfive-webfont.eot);
	src: local(&#8218;&#242;&#8747;'),
			 url('Chunkfive-webfont.woff') format('woff'),
			 url('Chunkfive-webfont.ttf') format('truetype'),
			 url('Chunkfive-webfont.svg#webfont') format('svg');
font-weight: normal;
font-style: normal;
}</pre>
<p>As before, we first declare an identifier for the rest of our code.</p>
<p>Next, we refer to the EOT version of the font for IE. If the browser is not IE, it will ignore this and move down the line until it finds a font type it can actually use.</p>
<p>The <code>src:local</code> bit is the local font trick I mentioned above. It essentially tells the browser to use a fictional font name that won&#8217;t be present on your machine so there is no mess from the wrong font being displayed. </p>
<p>Finally, setting the <code>font-weight</code> and <code>font-style</code> to normal here will ensure that all browsers default to the same values. This makes it so that you can apply a faux bold or italic style later in the CSS. <strong>Without this snippet, Webkit browsers will ignore any weight or style commands.</strong></p>
<p>Keep in mind that <strong>font rendering can vary widely across browsers and operating systems</strong>. Many developers have experienced such poor results from Windows and Internet Explorer that they avoid using custom fonts altogether. Always be sure to examine your results closely on all the browsers that you can to decide if the quality is acceptable.</p>
<h3>Where Do I Get All Those Font Types?</h3>
<p>You&#8217;ve probably noticed that the method above requires you to have at least four different versions of every custom font that you use. Many font sources, such as <a href="http://www.fontex.org/">Fontex</a>, will frequently only provide one file type in a download. <strong>So what do you do when you only have a single font file?</strong></p>
<h4>Font Squirrel</h4>
<p>The answer is to add <a href="http://www.fontsquirrel.com/">Font Squirrel</a> to your list of new favorite sites. Font Squirrel offers tons of <a href="http://www.fontsquirrel.com/fontface">free @font-face kits</a> that are essentially <strong>a one-click download for everything you need</strong> to get going with custom, cross-browser compatible fonts.</p>
<p>Each kit includes all the font types you need as well as demo HTML and CSS files to get you started.</p>
<p>All you need to do is download the kit, grab the font files and CSS snippet, and you&#8217;re ready to go! <strong>The CSS used by Font Squirrel is based on Paul Irish&#8217;s bulletproof @font-face syntax</strong> shown above so you can be confident that it&#8217;s the best method currently available for ensuring compliance for as many users as possible.</p>
<h4>@font-face Kit Generator</h4>
<p>What if FontSquirrel doesn&#8217;t have the kit you need? No problem. If you have a font that you obtained from another source, simply stop by the Font Squirrel <a href="http://www.fontsquirrel.com/fontface/generator">@font-face kit generator</a>. All you do is upload your font file and <strong>this amazing tool will automatically convert it to all the necessary file types</strong> and generate a kit for you to download.</p>
<p>Note that using the <code>@font-face</code> Kit Generator  means that you&#8217;re guaranteeing that you have the rights/license to convert and embed the font files you upload to the site.</p>
<p>This service is completely free and you can use it with zero sign up.</p>
<p><img src="http://images.sixrevisions.com/2010/06/02-03_font-face_generator.jpg" width="550" height="319" alt="screenshot" /></p>
<h3>Popular @font-face Services</h3>
<p>As I mentioned at the beginning of this article, several services have popped up offering both free and premium solutions for simplifying the <code>@font-face</code> process.</p>
<p>Below is a list of some of the most popular services currently available.</p>
<h4>Google Font API</h4>
<p><a href="http://sixrevisions.com/web_design/google-font-api-guide/"><img src="http://images.sixrevisions.com/2010/06/02-04_google_font_api.jpg" width="550" height="172" alt="screenshot" /></a></p>
<p>The <a href="http://sixrevisions.com/web_design/google-font-api-guide/" title="A Guide to Google Font API - sixrevisions.com">Google Font API</a> is one of the easiest and newest solutions for inserting custom fonts into your designs.</p>
<p>Using this API, you simply choose a font from the <a href="http://code.google.com/webfonts">Google Font Directory</a> and grab a snippet of code to insert into the <code>&lt;head&gt;</code> tag of your HTML documents. Afterwards, you can refer to the font in your CSS just like any other font you use normally, no <code>@font-face</code> CSS required (it takes care of all this behind the scenes).</p>
<p>All of the fonts in the Google Font Directory are free and open-source. The downside is that there are currently less than twenty options available. The Google Fonts API also neglects to include an SVG version so there is currently no support for mobile devices.</p>
<p>Read the <a href="http://sixrevisions.com/web_design/google-font-api-guide/" title="A Guide to Google Font API - sixrevisions.com">Six Revisions guide on using Google Font API</a>.</p>
<h4>TypeKit</h4>
<p><a href="http://typekit.com/"><img src="http://images.sixrevisions.com/2010/06/02-05_typekit.png" width="550" height="238" alt="screenshot" /></a></p>
<p><a href="http://typekit.com/">TypeKit</a> was one of the first services to launch dedicated to making <code>@font-face</code> easier to implement. The TypeKit team has partnered up with font foundries from all over the world to provide hundreds of excellent fonts with zero licensing complications for as long as you use the service.</p>
<p>There is a free trial plan that allows you to use a limited number of fonts on a single website.</p>
<p>Paid plans range from $24.99 per year for two sites all the way to $99.99 per year for an unlimited number of sites.</p>
<h4>Typotheque</h4>
<p><a href="http://www.typotheque.com/webfonts"><img src="http://images.sixrevisions.com/2010/06/02-06_typotheque.png" width="550" height="269" alt="screenshot" /></a></p>
<p><a href="http://www.typotheque.com/webfonts">Typotheque</a> allows you to purchase any of their fonts for web use. The nice thing about this service is that instead of a yearly plan, there&#8217;s only a one-time fee for purchasing the font. Once you purchase the font you want, just copy and paste the provided CSS and you&#8217;re done!</p>
<h4>Fonts Live</h4>
<p><img src="http://images.sixrevisions.com/2010/06/02-07_fontdeck.jpg" width="550" height="287" alt="screenshot" /></p>
<p><a href="http://www.fontslive.com/">Fonts Live</a> is yet another service that takes care of the complicated licensing hassles while bringing you hundreds of high-quality fonts from the best designers and foundries.</p>
<p>With Fonts Live, you purchase each font individually and pay a yearly subscription fee for the use of the font. Once you purchase the font,  you are provided with the simple code snippets necessary to embed the fonts into your site.</p>
<h4>Kernest</h4>
<p><img src="http://images.sixrevisions.com/2010/06/02-08_kernest.jpg" width="550" height="269" alt="screenshot" /></p>
<p>The <a href="http://kernest.com/">Kernest</a> system is nearly identical to that of the Google Font API. Simply find a font you like, grab the link to embed into the <code>&lt;head&gt;</code> tag of your HTML documents and you&#8217;re all set to start using the font in your CSS.</p>
<p>Kernest has lots of both free and premium fonts available. Unfortunately, the browsing system on Kernest.com attempts to load lots of these fonts simultaneously and can therefore be painfully slow and difficult to use. Prepare for a browser crash if you stumble onto a page with too many font previews.</p>
<h3>Wrapping Up @font-face</h3>
<p>You should now be fully armed to begin using beautiful custom fonts in your web designs. Using just a few lines of CSS and a free web service (or host your own files as outlined above), you can generate your own <code>@font-face</code> kits that work on most major browsers and won&#8217;t cost you a dime to implement. </p>
<p>If the free solutions don&#8217;t provide enough options and thinking about font licensing gives you a headache, check out the services above that take care of the complicated legal stuff, and even most of the code, making it extremely simple for you to use premium fonts online.</p>
<h3>References</h3>
<ol>
<li id="source-1"><a href="http://blog.themeforest.net/tutorials/how-to-achieve-cross-browser-font-face-support/">How to Achieve Cross-Browser @font-face Support</a></li>
<li id="source-2"><a href="http://paulirish.com/2010/font-face-gotchas/#smiley">@font-face gotchas</a></li>
</ol>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/web_design/a-basic-look-at-typography-in-web-design/">A  Basic Look at Typography in Web Design</a></li>
<li><a href="http://sixrevisions.com/css/examples-of-css3-in-the-wild/">Examples of  CSS3 in the Wild</a></li>
<li><a href="http://sixrevisions.com/web_design/20-websites-with-beautiful-typography/">20  Websites with Beautiful Typography</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web_design/">Web Design</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/joshua_johnson_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Joshua Johnson</strong> is a Graphic Designer/Web Designer with over six years of experience working with a major international marketing agency. He is also the Editor of <a href="http://designshack.co.uk/"><strong>Design Shack</strong></a>, a web design and development blog. Check out his <a href="http://www.krop.com/joshuajohnson/"><strong>recent work</strong></a> and follow him on Twitter: <strong>@<a href="http://twitter.com/secondfret">secondfret</a></strong>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/font-face-guide/feed/</wfw:commentRss>
		<slash:comments>48</slash:comments>
		</item>
		<item>
		<title>Semantic CSS3 Lightboxes</title>
		<link>http://sixrevisions.com/css/semantic-css3-lightboxes/</link>
		<comments>http://sixrevisions.com/css/semantic-css3-lightboxes/#comments</comments>
		<pubDate>Wed, 26 May 2010 11:00:28 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3345</guid>
		<description><![CDATA[
The rise of jQuery, MooTools, and JavaScript frameworks has given many web designers a new lease on life, adding more unique functionality into their sites.
Most notably among the various cool and interesting features you can find being injected into a design is the humble lightbox (modal window).

If you&#8217;ve ever come across a link or image [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/semantic-css3-lightboxes/"><img src="http://images.sixrevisions.com/2010/05/23-01_css_lightbox_ld_img.jpg" width="550" height="200" alt="Semantic CSS Lightboxes" /></a></p>
<p>The rise of jQuery, MooTools, and JavaScript frameworks has given many web designers a new lease on life, adding more unique functionality into their sites.</p>
<p>Most notably among the various cool and interesting features you can find being injected into a design is the humble <strong>lightbox</strong> (<a href="http://en.wikipedia.org/wiki/Modal_window">modal window</a>).</p>
<p><span id="more-3345"></span></p>
<p>If you&#8217;ve ever come across a link or image which — upon clicking — increases in size and where the rest of the screen gets &quot;shaded&quot; to focus on the content, you&#8217;ll know what I&#8217;m talking about.</p>
<p>This tutorial aims to showcase a   method of displaying content based on the lightbox, which is web accessible and (excluding Internet Explorer) will require no scripting at all. Sound like fun? Well, let&#8217;s explore the subject further!</p>
<h3>Demonstration</h3>
<p>Click the preview image below to see a <a href="http://downloads.sixrevisions.com/css-light-box/source.html">live demonstration</a>.</p>
<p><a href="http://downloads.sixrevisions.com/css-light-box/source.html"><img src="http://images.sixrevisions.com/2010/05/23-02_css_lightbox_finished.png" width="550" height="256" alt="Demonstration" /></a></p>
<h3>What About Scripting?</h3>
<p>There&#8217;s a lot to be said about the benefits of using client-side scripting for this. While we are certainly not in the cut-and-paste era that leads to the kind of crimes against JavaScript many coders would like   to see punished, we do, to this day, still have an uncomfortable reliance on scripts and frameworks in order for our websites to function.</p>
<p>Perhaps it seems a little hypocritical in this instance for me to critique the use of scripting (as Internet Explorer users will require scripting enabled to use this functionality), but like all things, we sometimes need to compromise our code to ensure compatibility (especially with <em>that</em> browser)!</p>
<h3>Why Not Just Use JavaScript?</h3>
<p>In the sense of the current scripting frameworks, I&#8217;m not going to say that they are inherently bad because the likes of jQuery often gracefully degrade with good levels of success — you guys can put away the knives and flame-lit torches now!</p>
<p>However, the sad facts are that, due to security issues, widespread abuse and the intrusive potential of client-side scripting, it&#8217;s quite easy to understand why a large number of people do not (or cannot) make use of scripting.</p>
<p>Therefore, a solution is required. And hopefully for you CSS3 fans, you&#8217;ll find this simple, easy-to-use code to be a welcome improvement.</p>
<h3>Browser Support of this CSS Lightbox</h3>
<p>To give you a quick introduction before we begin producing the code itself, it&#8217;s worth mentioning that I&#8217;ve tried the code in a variety of browsers and can say for sure that it works in all recent versions of Mozilla Firefox, Google Chrome, Apple Safari and Opera (which is all great news).</p>
<p>With a little bit of unobtrusive scripting that replicates the CSS3 techniques, it&#8217;ll also run smoothly within IE 6, 7 and 8.</p>
<p>The other fantastic news is that  current test versions of <a href="http://sixrevisions.com/web-development/five-things-ie9-is-actually-doing-right/">IE9</a> support CSS3, so this may very well be the best JavaScript-free solution there is in the near future.</p>
<p><img src="http://images.sixrevisions.com/2010/05/23-03_css_lightbox_internet_explorer.png" width="550" height="104" alt="Browser Support of this CSS Lightbox" /><span class="figure-caption">Internet Explorer is the usual culprit when it comes to lacking in standards support.</span></p>
<h3>Magic Markup!</h3>
<p>To begin our quest for a much more compatible lightbox, the first thing we need is some general HTML markup.</p>
<p>Much of the below won&#8217;t surprise you in the slightest as it&#8217;s pretty standard. However, for this example, and to showcase how durable this cool method is, we&#8217;ll produce <strong>three individual lightboxes</strong>.</p>
<p>One will be for an image, one will be for a block of scrollable content and the final one will hold a YouTube video. What more could you ask for?</p>
<p>To begin, let&#8217;s create the basics and have three fragment links which will go to the correct lightbox (you&#8217;ll learn how a bit later on).</p>
<pre>&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;CSS Lightbox&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;h1&gt;CSS Lightbox&lt;/h1&gt;
&lt;p&gt;You can use this fantastic solution to create lightboxes for not just <strong>&lt;a href=&quot;#image&quot; title=&quot;Image Lightbox&quot;&gt;</strong>images<strong>&lt;/a&gt;</strong> but rich, semantic <strong>&lt;a href=&quot;#content&quot; title=&quot;Content Lightbox&quot;&gt;</strong>content<strong>&lt;/a&gt;</strong> and <strong>&lt;a href=&quot;#video&quot; title=&quot;Video Lightbox&quot;&gt;</strong>video's<strong>&lt;/a&gt;</strong> as well!&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p><img src="http://images.sixrevisions.com/2010/05/23-04_css_lightbox_markup.png" width="550" height="256" alt="Magic Markup!" /><span class="figure-caption">Not much going on at this stage, a simple HTML document with extra links.</span></p>
<p>So far, things are pretty simple; you have a heading and paragraph with some links that, upon clicking, will currently do nothing.</p>
<p>The next stage in the process, however, is all important.</p>
<p>We need to add the container for each lightbox to appear within and give them their appropriate values.</p>
<p>To give you an idea as to how each of the three lightboxes work, you&#8217;ll need to examine (and add) the  code into your source code editor.</p>
<p>To better understand how it works, let&#8217;s talk about each item individually.</p>
<pre>&lt;div class=&quot;<strong>lightbox</strong>&quot; id=&quot;image&quot;&gt;
&lt;div class=&quot;w300 h60&quot;&gt;
&lt;img alt=&quot;Six Revisions&quot; height=&quot;98&quot; width=&quot;255&quot; src=&quot;logo.jpg /&gt;
&lt;/div&gt;
&lt;p class=&quot;close&quot;&gt;&lt;a href=&quot;#&quot; title=&quot;Close This Image Lightbox&quot;&gt;Close &lt;span&gt;X&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;</pre>
<p>Each lightbox you wish to provide will require a <code>div</code> element container that contains the <code>id</code> attribute you wish to link too. That <code>id</code> will reference what you&#8217;ll need to attach to the  <code>href</code> anchor to start the navigation process, not forgetting you&#8217;ll also need the <code>lightbox</code> class value on each you include.</p>
<p>Are you with me so far? Good!</p>
<p>Once you have the container that references the lightbox, you&#8217;ll need to include both a <code>div</code> (which will hold the lightbox content and will have the width and height declared through class values like in the above) and a paragraph with an anchor to act as the &quot;shader&quot;.</p>
<p>Using the above source code,  you should find yourself with a working lightbox that contains an image. In this example, I used the Six Revisions logo.</p>
<p>You can indeed link to any image of any size, taking into account the viewport space available.</p>
<h3>A Little Bit More About the &quot;Shader&quot;</h3>
<p>To better understand how this gets its visual appearance, the secondary <code>div</code> layer works independently from the close anchor which filters in the background. It&#8217;s essentially a cascading/tiling effect at work.</p>
<p><img src="http://images.sixrevisions.com/2010/05/23-05_css_lightbox_image.png" width="550" height="256" alt="The first lightbox has appeared, and it contains an image." /><span class="figure-caption">The first lightbox has appeared, and it contains an image.</span></p>
<p>If you look at any modern lightbox, the most common characteristic you will see is that you have a semi-transparent layer which covers over the rest of the page drawing focus to the lightbox content. Upon clicking on this layer, it will return you to the page. This is the very reason why each lightbox requires a closing anchor.</p>
<h3>What Should the href Value Be?</h3>
<p>The great thing is that you could even link the <code>href</code> to another lightbox if you wanted it to do something other than close (using the <code>null</code> fragment link).</p>
<h3>What Can the divs Contain?</h3>
<p>As for what&#8217;s inside the <code>div</code>, it&#8217;s entirely up to you. You can use any block or inline elements (the lightbox will house any HTML element).</p>
<p>In the first example, we had an image; let&#8217;s add some content within the code:</p>
<pre>&lt;div class=&quot;lightbox&quot; id=&quot;content&quot;&gt;
&lt;div class=&quot;w60p h400 scroll&quot;&gt;
&lt;h2&gt;Your Content Goes Here!&lt;/h2&gt;
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent quis felis suscipit tellus euismod varius quis ut nibh. Curabitur in ante nunc, vitae venenatis dui. Phasellus egestas ipsum in ipsum suscipit volutpat. Etiam eu nibh eros. Sed dolor ligula, tincidunt vitae elementum vitae, pharetra vitae eros. Cras risus lectus, aliquam vitae condimentum id, feugiat eu nisi. Cras eu sem erat, eget ultrices enim. Suspendisse feugiat fringilla massa at convallis. Quisque tincidunt, diam quis facilisis volutpat, purus orci rutrum leo, id dapibus tellus ante vel mauris. Quisque posuere, tortor in laoreet hendrerit, ipsum sem molestie nunc, et ultrices erat nulla sed dui. Donec sit amet mi sapien. Maecenas fermentum nulla eu ligula dictum id elementum nisi commodo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In ac massa quam. Suspendisse nibh nibh, condimentum a porttitor a, placerat in lorem. Sed sit amet elit eget magna condimentum posuere volutpat a neque.&lt;/p&gt;
&lt;p&gt;Sed dignissim viverra neque, sit amet lobortis elit luctus ac. Proin placerat varius quam eu molestie. Pellentesque vel ante quis metus auctor convallis. Duis mattis risus ac tortor luctus in semper sem fringilla. Vestibulum consectetur iaculis risus vel rutrum. Nam scelerisque gravida felis quis egestas. Mauris vehicula nisl quis felis bibendum nec placerat neque dictum. Donec erat tortor, venenatis id consequat ut, dictum nec enim. Ut ultrices eros vel diam pulvinar aliquam. Phasellus non nisi vitae ligula imperdiet dapibus eleifend sed neque. Morbi gravida dignissim turpis eu auctor. Morbi pellentesque urna vitae nunc dictum elementum. Aliquam erat volutpat. Aenean urna nibh, pretium ut accumsan ut, luctus eget nibh. Nulla sollicitudin fermentum turpis eget rutrum. Integer dignissim dui turpis. Morbi metus libero, suscipit blandit dignissim aliquam, sodales non mi. Proin id augue odio, sit amet gravida mauris.&lt;/p&gt;
&lt;p&gt;Proin a dignissim orci. Nam nec urna nisi, in blandit lorem. Nulla cursus ornare rhoncus. Nunc lectus orci, tristique et aliquet sed, venenatis et felis. Nullam sodales orci at est pharetra nec aliquam risus scelerisque. Nullam varius, nisi ut sagittis scelerisque, nulla mauris tempus magna, quis pellentesque sem erat a diam. Cras lectus est, dictum ut consequat ut, adipiscing sit amet sapien. Curabitur tincidunt varius gravida. Quisque augue sem, commodo sed molestie venenatis, cursus vehicula lorem. Praesent scelerisque, tortor a euismod malesuada, ipsum ligula semper odio, ultricies molestie sapien metus condimentum felis. Vivamus hendrerit gravida interdum. Fusce at purus eu orci laoreet lobortis. Aliquam cursus mi at tellus fringilla dictum. Sed nec libero dolor. Integer nec neque at mi malesuada tincidunt.&lt;/p&gt;
&lt;/div&gt;
&lt;p class=&quot;close&quot;&gt;&lt;a href=&quot;#&quot; title=&quot;Close This Content Lightbox&quot;&gt;Close &lt;span&gt;X&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;</pre>
<p><img src="http://images.sixrevisions.com/2010/05/23-06_css_lightbox_lipsum.png" width="550" height="256" alt="For all whom understand the value of dummies, some Lipsum content is added." /><span class="figure-caption">For all whom understand the value of dummies, some Lipsum content is added.</span></p>
<h3>Add a YouTube Video</h3>
<p>And to round things off even further, let&#8217;s add a YouTube video into the mix:</p>
<pre>&lt;div class=&quot;lightbox&quot; id=&quot;video&quot;&gt;
&lt;div class=&quot;w640 h386&quot;&gt;
&lt;object type=&quot;application/x-shockwave-flash&quot; width=&quot;640&quot; height=&quot;385&quot; data=&quot;http://www.youtube.com/v/bsGEWHNJ3s8&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/bsGEWHNJ3s8&quot; /&gt;&lt;/object&gt;
&lt;/div&gt;
&lt;p class=&quot;close&quot;&gt;&lt;a href=&quot;#&quot; title=&quot;Close This Video Lightbox&quot;&gt;Close &lt;span&gt;X&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;</pre>
<p><img src="http://images.sixrevisions.com/2010/05/23-07_css_lightbox_youtube.png" width="550" height="256" alt="Video on demand, that'll work in the lightbox too! Pretty cool isn't it?" /><span class="figure-caption">Video on demand, that&#8217;ll work in the lightbox too! Pretty cool isn&#8217;t it?</span></p>
<p>At this stage, we have completed the entire HTML file that this demonstration will use.</p>
<p>If you want to preview the results in your web browser, you&#8217;ll notice that as well as the heading and paragraph, there will now be the three pieces of information on the page (the image, the content block and the video), each with a &quot;Close&quot; link right below it.</p>
<h3>Right on :target</h3>
<p>At this stage, you&#8217;re probably wondering how we&#8217;re going to ensure that only the right content appears when it&#8217;s needed. And that&#8217;s a good question! We are going to use a cool CSS3 pseudo-selector called <code>:target</code> (which styles based on the anchor).</p>
<p>Perhaps you&#8217;ve come across the <code>:target</code> selector before, perhaps not. Basically, it cleverly allows you to apply specific style to an element if its <code>id</code> matches the fragment identifier, which is the hash (#) symbol followed by text usually found in page bookmarks. For example: <code>index.html#content</code> (you&#8217;ll see it in the address bar).</p>
<p>So, without any further ado, it&#8217;s time we began formatting our lightbox to perform the required task whenever this fantastic selector is activated.</p>
<p>You now know why we give the three links in the first piece of code those unique URLs (and gave each <code>div</code> a matching <code>id</code>).</p>
<p><img src="http://images.sixrevisions.com/2010/05/23-08_css_lightbox_fragment_links.png" width="550" height="71" alt="Fragment links are best indicated by the # (hash) character at the end of a URL." /><span class="figure-caption">Fragment links are best indicated by the # (hash) character at the end of a URL.</span></p>
<p>For the following piece of code, I&#8217;ll provide everything you need using a <code>style</code> element within the <code>&lt;head&gt;</code> of the document.</p>
<p>Generally, this is <strong>considered bad practice</strong> because all CSS styles should be separated from the structure. However, as this is simply an example and it works unobtrusively, you can easily place all of the stylistic code in an external file. For simplicity, I&#8217;ll keep it in-line.</p>
<p>To begin, we&#8217;ll start by adding in the easy-to-follow snippets of code such as removing the padding and margins from the document. Also, we&#8217;ll hide the lightboxes off-screen until they&#8217;re required using some absolute positioning and negative margins.</p>
<pre>
&lt;style type=&quot;text/css&quot;&gt;
html, body {
  height: 100%;
  overflow: hidden;
  width: 100%;
  margin: 0;
  padding: 0;
}
body { overflow-y: auto; }
.lightbox {
  left: -999em;
  position: absolute;
}
&lt;/style&gt;</pre>
<p><strong>Note:</strong> It is entirely possible for you to hide your three lightboxes when they&#8217;re not in use using the property <code>display: none</code>. However, as this can affect how some screen reading software will interact with your page, I&#8217;ve used negative positioning to get the same effect.</p>
<p><img src="http://images.sixrevisions.com/2010/05/23-09_css_lightbox_offset.png" width="550" height="256" alt="With lightboxes offset, things disappear." /><span class="figure-caption">With lightboxes offset, things disappear.</span></p>
<p>Upon refreshing your browser at this stage, you&#8217;ll notice that the three previously visible lightboxes will be hidden, which is great.</p>
<p>However, when you click on the links, nothing happens! Don&#8217;t worry, your lightbox isn&#8217;t broken.</p>
<p>All we need to do is add in the code to activate the two layers (the &#8220;close this&#8221; lightbox anchor, that gives the fade effect and the lightbox content itself).</p>
<pre>.lightbox:target { bottom: 0; left: 0; right: 0; top: 0; position: absolute; }
.lightbox:target .close a { background: rgba(0, 0, 0, 0.75); bottom: 0; left: 0; right: 0; top: 0; position: absolute; z-index: 1; }
.close span { color: #FFFFFF; font-size: 2em; text-indent: 0; position: absolute; right: 0.5em; top: 0.5em; }
.close {text-indent: -999em;}</pre>
<p>Keeping things simple, the above code will span the lightbox to every corner of the browser viewport using absolute positioning.</p>
<p>The second line of code will reinforce this code on the anchor itself and will give it a <code>z-index</code> (for priority over the other stuff on the page) and a background which makes use of opacity in browsers that natively support CSS3 alpha transparency.</p>
<p>The third line will use the <code>span</code> element on the &quot;close&quot; button to give it some emphasis for people to know that clicking in the anchor closes the lightbox.</p>
<p>The last line will hide the text in the faded section (for full effect).</p>
<p><strong>Note:</strong> It&#8217;s worth pointing out that if your content scrolls and you wish the lightbox to follow the scroll action, you can replace <code>position: absolute</code> with <code>position: fixed</code>, however IE6 will not support it. For the example, I&#8217;ve used absolute positioning for simplicity and to showcase its potential usage.</p>
<p><img src="http://images.sixrevisions.com/2010/05/23-10_css_lightbox_transparency.png" width="550" height="256" alt="Now when you click on a lightbox link, the transparency effect flourishes." /><span class="figure-caption">Now when you click on a lightbox link, the transparency effect flourishes.</span></p>
<p>If you refresh your browser with the above code, you&#8217;ll notice upon clicking any element that you get that amazing faded effect which will span the entire content. And you should also  have a neat little &quot;X&quot; button in the top-right corner just to help reinforce the effect upon clicking outside of the lightbox.</p>
<p>The problem now is we need to get the lightbox contents itself positioned correctly and looking great on the screen.</p>
<p>So below, you&#8217;ll find the last bits of CSS to align the content and offset it based on the width of the contents specified.</p>
<pre>.lightbox:target div { background: #FFFFFF; position: absolute; left: 50%; top: 50%; z-index: 99; }
.w60p { margin-left: -30%; width: 60%; } .w300 { margin-left: -150px; width: 300px; } .w640 { margin-left: -320px; width: 640px; }
.h60 { height: 60px; margin-top: -30px; } .h400 { height: 400px; margin-top: -200px; } .h386 { height: 386px; margin-top: -193px; }
.scroll { overflow-y: scroll; padding: 0 1em; }</pre>
<p>If you refer back to the HTML code, you&#8217;ll see that each lightbox container has class values such as <code>w300</code> (for width 300px) or <code>h400</code> (for height 400px) or <code>w60p</code> (for width 60%).</p>
<p>The values for each lightbox were simply calculated by measuring the width and height of the contents required and then setting the container width and height to match the dimensions.</p>
<p>Take for example the image we used: As that had specific width and height needs, a specific width and height was applied to the lightbox container, and for each, a negative margin for half that value was given to give it accurate centering.</p>
<p><strong>Note:</strong> You may have noticed that a <code>scroll</code> class was also added to match the width and height classes for each lightbox.</p>
<p>Simply put, if you have lots of content within the container and you give it a fixed width and height, the scroll mechanism will allow it to overflow with scroll bars attached. Lovely!</p>
<p><img src="http://images.sixrevisions.com/2010/05/23-11_css_lightbox_content.png" width="550" height="256" alt="Adding the next bundle of code will properly align the lightboxes content." /><span class="figure-caption">Adding the next bundle of code will properly align the lightboxes content.</span></p>
<p>Now try refreshing the page again and — Voila! — just like magic, whenever you click one of the links, its content will load in a container, in the center of the screen.</p>
<p>And the fantastic thing is, it will look and function like any other lightbox. Clicking inside the lightbox will act normally, but clicking outside of it will restore the main screen (and thereby hide the lightbox contents as they&#8217;re not the fragment).</p>
<p>If you use <strong>Firefox, Chrome, Safari or Opera</strong>, this code will work perfectly and is a 100% pure CSS way of implementing a lightbox.</p>
<p>But for <strong>Internet Explorer</strong>, we (as usual) have compatibility issues to deal with!</p>
<p><strong>Tip:</strong> Just imagine what you can do with these target lightboxes: You could have anything from the content shown above, right through to setting the width and height of the container to 100% and have a literal different &quot;page&quot; appear with overflow enabled on a single page web design. Woot!</p>
<h3>Compatibility Crisis</h3>
<p>Without going into a great deal of detail, the below JavaScript code has been produced to deal with Internet Explorer&#8217;s lack of support for  <code>:target</code>  (this could well be the first effective and simple solution for this issue).</p>
<p>As with the style, I&#8217;ve attached the content inline using <code>&lt;script&gt;</code> tags in the header, but it&#8217;s entirely graceful and can appear in an external file.</p>
<p>As long as the script is placed <strong>below</strong> the <code>&lt;style&gt;</code> element, you shouldn&#8217;t encounter any issues in regards to the emulation of the code.</p>
<pre>&lt;script type=&quot;text/javascript&quot;&gt;
&lt;!--
 	/*@cc_on @if (@_jscript_version &gt; 5.6)
 	function bootup(){
 	var tds = document.getElementsByTagName(&quot;a&quot;); lightbox();
 	for( var x=0; x &lt; tds.length; x++ ){tds[x].onclick = function(){setTimeout(lightbox, 1);};}
 	}
 	function lightbox(){
 	var counted = document.getElementsByTagName(&quot;div&quot;);
 	for( var x=0; x &lt; counted.length; x++ ){ if ( counted[x].className == &quot;boxfocus&quot; ) { counted[x].className = &quot;lightbox&quot;; } }
 	if (location.hash.substr(1) == &quot;&quot;) {} else { document.getElementById(location.hash.substr(1)).className = &quot;boxfocus&quot;; }
 	}
 	window.onload=bootup;
 	@end @*/
 	// --&gt;
&lt;/script&gt;</pre>
<p>Keeping the above code as simple as possible, it makes use of conditional comments (for JavaScript) to ensure you are using Internet Explorer (hence why it references Jscript) thereby ensuring the code will not interfere with good browsers which render correctly.</p>
<p>When IE is verified, and the page loads, the <code>bootup</code> function monitors whenever an anchor is clicked.</p>
<p>When this event is triggered, the <code>lightbox</code> function is activated and it simply applies a set of classes to the <code>div</code> that matches the hash (#) in the address bar (fragment link), while restoring all other lightbox instances back to the default.</p>
<p>Essentially it says &quot;You&#8217;re using IE? OK. You clicked a link or loaded a page? OK. The link clicked references a lightbox? OK, let&#8217;s set that in motion and reset any others which may be active&quot;.</p>
<p>If you&#8217;re not too JavaScript-savvy, it may not make a lot of sense, but the code requires no user maintenance and if you use the code, you&#8217;ll just have to trust me that it&#8217;ll do the job. Except for those classes to be applied, which have the alternative to the <code>:target</code> stuff, we&#8217;ll need to add these into the style in the header.</p>
<p>And to overcome IE&#8217;s lack of opacity support, we&#8217;ll add a transparent repeating PNG image in its place.</p>
<pre>.boxfocus { bottom: 0; left: 0; right: 0; top: 0; position: absolute; }
.boxfocus div {background: #FFFFFF; position: absolute; left: 50%; top: 50%; z-index: 99; }
.boxfocus .close a { background-image: url('trans.png'); bottom: 0; left: 0; right: 0; top: 0; position: absolute; z-index: 1; }</pre>
<p>Those of you with eagle eyes may have noticed that the properties of the <code>boxfocus</code> classes, which sit in place of those using the <code>:target</code> pseudo, contain mostly the same properties and values as their counterparts. So you may well ask: Why not group them together?</p>
<p>While it may seem like a smart idea to reduce repeating code, unfortunately the default behaviour for IE and other browsers is that unknown or invalid code (as it would appear to IE) should be totally ignored and deleted. Which means, if grouped, it wouldn&#8217;t work, so we need the repeated CSS as a separate entity.</p>
<p><img src="http://images.sixrevisions.com/2010/05/23-12_css_lightbox_script.png" width="550" height="375" alt="With a bit of caring JavaScript, Internet Explorer will work like any other browser." /><span class="figure-caption">With a bit of caring JavaScript, Internet Explorer will work like any other browser.</span></p>
<p>If you now refresh the page again and open it in Internet Explorer, you will find that the lightbox should now work properly in that browser.</p>
<p>It may not be a perfect solution to require extra CSS and some conditional JavaScript to work the mojo, but alas, this isn&#8217;t a perfect world, so we must use it to keep things as compatible as possible.</p>
<p>On the bright side of things, <a href="http://sixrevisions.com/web-development/five-things-ie9-is-actually-doing-right/">Internet Explorer 9 has full support for target</a> so in the future, none of that extra code will be needed.</p>
<h3>Setting Standards</h3>
<p>And on that note, the example is complete.</p>
<ul>
<li>It&#8217;s <strong>totally semantic</strong>: with <code>div</code> containers and the use of any HTML elements you wish within the container</li>
<li>It&#8217;s <strong>accessible: </strong>it&#8217;ll work with screen readers</li>
<li>It&#8217;s not as <strong>dependent on scripting</strong> as the jQuery solutions and you can bookmark their behaviour</li>
<li>And — all things considered — it&#8217;s <strong>more graceful</strong> in that the future looks good for the selectors&#8217; widespread browser support without the need of any scripting</li>
</ul>
<h3>Get Involved with CSS3. Please.</h3>
<p>Hopefully this tutorial will inspire you to get involved in testing modern standards like CSS3 because many of these elements already have basic native support.</p>
<p>While there is a real need at this time to make things gracefully degrade (and this option certainly can achieve that), it&#8217;s worth highlighting that the potential for the <code>:target</code> pseudo-class goes far beyond lightboxes: It could remove the future need for JavaScript in single-page websites, content swapping, and other process-intensive functions.</p>
<p>While the need for workarounds (like the JavaScript we needed to use) won&#8217;t disappear overnight, the future of web standards is pretty bright!</p>
<h3>Download</h3>
<ul>
<li><a href="http://downloads.sixrevisions.com/css-light-box/css-light-box.zip">css-light-box</a> (ZIP, 0.007 MB)</li>
</ul>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/css/css3-techniques-you-should-know/">CSS3 Techniques You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/examples-of-css3-in-the-wild/">Examples of CSS3 in the Wild</a></li>
<li><a href="http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/">How to Create Inset Typography with CSS3</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/alexander_dawson_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Alexander Dawson</strong> is a freelance web designer, author and recreational software developer specializing in web standards, accessibility and UX design. As well as running a business called <strong><a href="http://www.hitechy.com/">HiTechy</a></strong> and writing, he spends time on <strong><a href="http://twitter.com/AlexDawsonUK">Twitter</a></strong>, SitePoint&#8217;s forums and other places, helping those in need.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/semantic-css3-lightboxes/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
		<item>
		<title>Examples of CSS3 in the Wild</title>
		<link>http://sixrevisions.com/css/examples-of-css3-in-the-wild/</link>
		<comments>http://sixrevisions.com/css/examples-of-css3-in-the-wild/#comments</comments>
		<pubDate>Thu, 20 May 2010 15:27:34 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3340</guid>
		<description><![CDATA[Some examples of CSS3 in the wild.]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/examples-of-css3-in-the-wild/"><img src="http://images.sixrevisions.com/2010/05/22-01_css3_wild_ld_img.jpg" width="550" height="200" alt="Examples of CSS3 in the Wild" /></a></p>
<p><strong>Seeing CSS3</strong> on actual functioning websites is a lot like spotting a Himalayan Snow Leopard or a Giant Panda. Because roughly <a href="http://en.wikipedia.org/wiki/Usage_share_of_web_browsers" title="Usage share of web browsers - en.wikipedia.org">53 percent of browsers in use</a> don&#8217;t support CSS3 (ahem, IE, ahem), most web designers just don&#8217;t use it on a regular basis. At least they don&#8217;t use it on sites they design for work. As such, most people don&#8217;t see it regularly, and if they do, it&#8217;s just a fleeting glimpse.</p>
<p><span id="more-3340"></span></p>
<p>That&#8217;s not to say it&#8217;s not out there – again, like with snow leopards and pandas, to see CSS3 in the wild, you need to be stealthy, smart, and patient. </p>
<p>So, with out further ado, here are some examples of CSS3 in the wild. But please – make sure to avoid big, sudden movements. You don&#8217;t want to scare it off.</p>
<p>To learn more about CSS3, you should also check out these articles and tutorials:</p>
<ul>
<li><a href="http://sixrevisions.com/css/css3-techniques-you-should-know/">CSS3 Techniques You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/basic-css3-techniques-that-you-should-know/">Basic CSS3 Techniques That You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/">How to Create Inset Typography with CSS3</a></li>
<li><a href="http://sixrevisions.com/css/20-useful-resources-for-learning-about-css3/">20 Useful Resources for Learning about CSS3</a></li>
</ul>
<h3>Rounded Corners</h3>
<h4>How We Did Rounded Corners Before</h4>
<p>By creating separate images for the corners of a box, or by using JavaScript to mask sharp edges.</p>
<h4>How We Do Rounded Corners with CSS3</h4>
<pre>border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;</pre>
<h4>Examples of CSS3 Rounded Corners</h4>
<p>The rounded corners on these following sites are pretty obvious and fairly simple looking, but as any web designer knows, they weren&#8217;t so simple to create without CSS3.</p>
<p><a href="http://twitter.com/WHHG_InMotion">Twitter</a></p>
<p><img src="http://images.sixrevisions.com/2010/05/22-02_css3_wild_twitter.jpg" width="550" height="250" alt="Twitter" /></p>
<p><a href="http://emberapp.com/">Ember</a></p>
<p><img src="http://images.sixrevisions.com/2010/05/22-03_css3_wild_ember.jpg" width="550" height="250" alt="Ember" /></p>
<p><a href="http://www.zurb.com/blog">ZURB</a></p>
<p><img src="http://images.sixrevisions.com/2010/05/22-04_css3_wild_zurb.jpg" width="550" height="250" alt="ZURB" /></p>
<h3>Text Shadow</h3>
<h4>How We Did Text Shadow Before</h4>
<p>By creating two elements with the same text, giving one of them the shadow color, offsetting it one or two pixels, and placing it behind the main text using the <code>z-index</code> CSS property.</p>
<h4>How We Do Text Shadow with CSS3</h4>
<pre>text-shadow: 2px 2px 4px #000;</pre>
<h4>Examples of CSS3 Text Shadow</h4>
<p>The sites below each use text shadow in a different way.</p>
<p><a href="http://www.jolicloud.com/">Jolicloud</a></p>
<p>Jolicloud uses CSS3 Text Shadow throughout the site.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-05_css3_wild_jolicloud.jpg" width="550" height="250" alt="Jolicloud" /></p>
<p><a href="http://adifferentdesign.be/">A Different Design</a></p>
<p>A Different Design uses a white text shadow in the site&#8217;s name to give the text that cool &quot;embossed&quot; look.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-06_css3_wild_different_design.jpg" width="550" height="250" alt="A Different Design" /></p>
<p><a href="http://www.time2project.com/">Time2Project</a></p>
<p>Over at Time2Project, the &quot;who,&quot; &quot;what,&quot; and &quot;where&quot; menu links use text shadow to highlight themselves when you hover over them – very cool.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-07_css3_wild_time2project.jpg" width="550" height="250" alt="Time2Project" /></p>
<h3>Box Shadow</h3>
<h4>How We Did Box Shadow Before</h4>
<p>By creating an image of the box with a shadow or by using a JavaScript plugin.</p>
<h4>How We Do Box Shadow with CSS3</h4>
<pre>box-shadow: 2px 2px 4px black;
-moz-box-shadow: 2px 2px 4px black;&nbsp;
-webkit-box-shadow: 2px 2px 4px black;&nbsp;</pre>
<h4>Examples of CSS3 Box Shadow</h4>
<p>Again, with the two sites below, we can see two very different ways of using the same CSS3 technique.</p>
<p><a href="http://camendesign.com/">camen design</a></p>
<p>At camen design, the footer stays in the same place, and box shadow is used to give the illusion of the main content area sliding underneath the footer.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-08_css3_wild_camen_design.jpg" width="550" height="250" alt="camen design" /></p>
<p><a href="http://css-tricks.com/">CSS-Tricks</a>&nbsp;</p>
<p>Over at CSS-Tricks, the box shadow effect is used on pretty much every box on the site, highlighting whichever box you hover your mouse on.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-09_css3_wild_css-tricks.jpg" width="550" height="250" alt="CSS-Tricks " /></p>
<h3>RGBA Colors</h3>
<h4>How We Did RGBA Colors Before</h4>
<p>By calling a PHP script within CSS, thereby tricking the browser into overlaying colors in RGBA format. In no way could this be thought of as a good way of doing things, as it leads to lots of extra code in the PHP file that you&#8217;ll never use again.</p>
<h4>How We Do RGBA Colors with CSS3</h4>
<pre>background: rgba(150, 25, 150, 0.5);</pre>
<h4>Examples of CSS3 RGBA Colors</h4>
<p><a href="http://www.igcp.org/">International Gorilla Conservation Programme</a> (IGCP)</p>
<p>Check out the awesome translucent gorilla on the IGCP site. Now look slightly to the right. That box around the video player uses RGBA as a way to layer a semi-transparent container on top of the banner behind it.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-10_css3_wild_igp.jpg" width="550" height="250" alt="International Gorilla Conservation Programme" /></p>
<p><a href="http://24ways.org/">24 ways</a></p>
<p>24Ways uses the effect throughout the site, but it&#8217;s most noticeable on the top, where hovering over the headline banner uses RGBA to increase the opacity.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-11_css3_wild_24ways.jpg" width="550" height="250" alt="24 ways" /></p>
<h3>Opacity Level</h3>
<h4>How We Did Opacity Levels Before</h4>
<p>By creating PNGs with transparency, or by using CSS filters for IE.</p>
<h4>How We Do Opacity Levels with CSS3</h4>
<pre>opacity: 0.5;</pre>
<h4>Examples of CSS3 Opacity Levels</h4>
<p>Changing the opacity level with CSS3 is one of the coolest ways to add to the user&#8217;s interface experience and also one of the simplest, as it takes very little code.</p>
<p><a href="http://bunton.com.au/">Bunton</a></p>
<p>At Bunton, each individual box uses opacity to show the designer&#8217;s comments about his portfolio – all that info is there all the time, it&#8217;s just got an opacity of 0 before you hover over it.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-12_css3_wild_bunton.jpg" width="550" height="250" alt="Bunton" /></p>
<p><a href="http://www.peaxl.com/">Peaxl</a></p>
<p>Peaxl uses it even more subtly in the &quot;subscribe&quot; box, making the existing text fade away slowly when you click it.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-13_css3_wild_peaxl.jpg" width="550" height="250" alt="Peaxl" /></p>
<p><a href="http://www.31three.com/">31Three</a></p>
<p>31Three uses it on its portfolio examples as well, making each circle light up ever so slightly with your hovering mouse. Nice.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-14_css3_wild_31styles.jpg" width="550" height="250" alt="31Three" /></p>
<h3>Gradients</h3>
<h4>How We Did Gradients Before</h4>
<p>Image slice of gradient repeated as a background image.</p>
<h4>How We Do Gradients with CSS3</h4>
<pre>background: -moz-linear-gradient(100% 100% 90deg, #1a1a1a, #808080)
background: -webkit-gradient(linear, 0 0, 0 100%, from(#1a1a1a), to(#808080));</pre>
<h4>Example of CSS3 Gradients</h4>
<p><a href="http://www.philadelphiafirst.org/">Philadelphia FIRST</a></p>
<p>While this example isn&#8217;t the most beautiful or breathtaking example of CSS3, it might be the most practical. By making the blue banner on top fade into a lighter blue by using CSS3 instead of an image, the site isn&#8217;t required to serve that image every time. Little things like that make a difference for a heavily-traffic site, and it shows what can be accomplished with CSS3 once it becomes the standard.</p>
<p><img src="http://images.sixrevisions.com/2010/05/22-15_css3_wild_philadelphia.jpg" width="550" height="250" alt="Philadelphia FIRST" /></p>
<h3>@Font-face, Text Shadow, RGBA, Rounded Corner</h3>
<p>(aka The Holy Grail of websites that currently use CSS3<a href="#footnote-fontface">*</a>)</p>
<h4>How We Made Sites Like This Before</h4>
<p>We didn&#8217;t.</p>
<h4>How We Make Them Now</h4>
<p>With CSS3. Lots of CSS3.</p>
<h4>Examples of CSS3 Sites</h4>
<p>The following sites are examples of what one can do with CSS3.</p>
<p>Of course, because CSS3 isn&#8217;t implemented in all browsers yet, and implementation of browsers that do use CSS3 can vary, not all of these will render correctly on every browser.</p>
<p>However, it&#8217;s an interesting look on what&#8217;s soon going to be possible in the world of web design.&nbsp;</p>
<p><a href="http://thefella.com/">TheFella</a></p>
<p><img src="http://images.sixrevisions.com/2010/05/22-16_css3_wild_thefella.jpg" width="550" height="250" alt="TheFella" /></p>
<p><a href="https://jetpack.mozillalabs.com/">Mozilla Labs Jetpack</a></p>
<p><img src="http://images.sixrevisions.com/2010/05/22-17_css3_wild_jetpack.jpg" width="550" height="250" alt="Mozilla Labs Jetpack" /></p>
<h3 id="footnote-fontface">Footnote</h3>
<p><em>*@font-face was implemented in IE5 and is part of CSS2, so it was actually modern browsers like Firefox that lagged behind in implementation.</em></p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/css/css3-techniques-you-should-know/">CSS3 Techniques You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/basic-css3-techniques-that-you-should-know/">Basic CSS3 Techniques That You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/">How to Create Inset Typography with CSS3</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/blue_derkin_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Blue Derkin</strong> is a project and social media lead at <strong><a href="http://www.inmotionhosting.com/">InMotion Hosting</a></strong> in Marina del Rey, California. He also writes as <strong><a href="http://www.webhostinghelpguy.inmotionhosting.com" target="_blank">Web Hosting Help Guy</a></strong>, InMotion Hosting&#8217;s blog dedicated to all things design, development, and <a href="http://www.inmotionhosting.com" target="_blank">web hosting</a>. You can follow him on Twitter <strong>@<a href="http://twitter.com/whhg_inmotion">WHHG_InMotion</a></strong> and <strong>@<a href="http://twitter.com/BlueDerkin">BlueDerkin</a></strong>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/examples-of-css3-in-the-wild/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Snazzy Hover Effects Using CSS</title>
		<link>http://sixrevisions.com/css/snazzy-hover-effects-using-css/</link>
		<comments>http://sixrevisions.com/css/snazzy-hover-effects-using-css/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 09:00:17 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=3004</guid>
		<description><![CDATA[Creating flexible advanced hover techniques using CSS2.1 properties.]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/snazzy-hover-effects-using-css/"><img src="http://images.sixrevisions.com/2010/04/13-09_snazzy_hover_css_leadimg.jpg" width="550" height="200" alt="Snazzy Hover Effects Using CSS" /></a></p>
<p>With all these CSS3 effects and tutorials popping up every day that show all the new and wonderful things we can make happen, we sometimes forget about poor little old CSS2.1 and the great potential it still has.</p>
<p>With very good browser support, we can do lots of cool things that we know will work in all major browsers.</p>
<p>In this tutorial, I will be going over creating flexible advanced hover techniques using CSS2.1 properties.</p>
<p>Here is a <a href="http://www.thecssninja.com/demo/css_hover2/" target="_blank"><strong>live demonstration</strong></a> of the effect we will be creating.</p>
<p><span id="more-3004"></span></p>
<h3>Advanced hover states are quite simple</h3>
<p>When I first started learning CSS, the <code>:hover</code> pseudo-element was no more than a way to remove the underline on a text link.</p>
<p>Since then, through experimentation, I have learnt that it is so much more powerful and it can create some really cool effects when used in conjunction with other CSS properties.</p>
<p>One of these effects is creating caption text to appear over the top of images, creating some nice visual feedback for the user and giving them some information about the image they&#8217;ve moused over or focused on.</p>
<p>The astute reader will see that this technique has great potential outside of what we discuss here, such as showing CSS tool tips when hovering over a hyperlink.</p>
<p>We&#8217;ll be using these key CSS property, pseudo-classes, and pseudo-element to accomplish our technique:</p>
<ul>
<li><code><strong>content</strong></code> Rather than create unnecessary mark-up to display our caption, we&#8217;ll use CSS generated content to add the caption.</li>
<li><code><strong>:hover</strong></code>, <code><strong>:focus</strong></code> Lets us show/hide the caption overlay with our mouse/keyboard.</li>
<li><code><strong>:after</strong></code> Used in conjunction with the content property to dynamically append our caption content and layout.</li>
</ul>
<h3>Generated content is king</h3>
<p>CSS-generated content allows us to append (<code>:after</code>) or prepend (<code>:before</code>) content to an element that can display hard-coded content, dynamic content (<code>attr()</code>), images (<code>url()</code>) and counters (<code>counter()</code>).</p>
<p>In this example, we&#8217;ll utilise the <code>attr()</code> function to extract the title attribute from the anchor (<code>&lt;a&gt;</code>) tag.</p>
<pre>
&lt;li&gt;
    &lt;a href="#" <strong>title="Sunrise on the farm"</strong>&gt;
        &lt;img src="img01.jpg" width="200" height="206" alt="Beautiful sunrise" /&gt;
    &lt;/a&gt;
&lt;/li&gt;
</pre>
<pre name="code" class="css">
ul a:hover:after
{
    content: <strong>attr(title)</strong>;
}</pre>
<p><img src="http://images.sixrevisions.com/2010/04/13-01_basic_hover.jpg" width="220" height="184" alt="Basic image caption using generated content" /></p>
<p>As you can see from above, the mark-up is very simple and the use of the content property allows us to create some great behaviour without the bloat. All it&#8217;s doing here is getting the anchor&#8217;s <code>title</code> attribute value and appending the <code>content</code> <code>:after</code> the anchor.</p>
<h3>Make it sit nice</h3>
<p>Now that we have some simple mark-up and  are now displaying our caption on hover/focus after the image, we&#8217;ll add some extra CSS to pretty up the caption and make it sit over the image, rather than beneath it.</p>
<p>We first do some simple styling to the containing list item. The only style required here is the relative position. Using a relative position allows us to absolutely-position elements inside the list item.</p>
<p>The  other styles are decorative.</p>
<pre>
ul > li {
    <strong>position: relative;</strong>
    float: left;
    list-style: none;
    margin: 0 20px 20px 0;
    font-size: 10px;
}</pre>
<p>Adding some more styles to our <code>:hover</code> pseudo-class, we absolutely position the CSS-generated content and give it a height, background, line height (this is the same as the height, so we can vertically-centre the text).</p>
<p>We also do the same for the <code>:focus</code> pseudo-class so someone who can&#8217;t use a mouse still gets the full experience.</p>
<pre>
ul a<strong>:hover</strong>:after,
ul a<strong>:focus</strong>:after
{
    <strong>background: rgb(255,255,255);</strong>
    bottom: 2px;
    content: attr(title);
    color: #000;
    display: block;
    font-weight: bold;
    <strong>height: 30px;</strong>
    <strong>line-height: 30px;</strong>
    position: absolute;
    text-align: center;
    width: 100%;
}</pre>
<p>We&#8217;ll also add an outline around the image to create a nice border effect when the user focuses or hovers on it.</p>
<p>The reason we don&#8217;t use the <code>border</code> property is because <code>outline</code> doesn&#8217;t affect the area it &quot;outlines&quot;, whereas <code>border</code> will affect the element.</p>
<pre>
ul a:hover img, ul a:focus img { <strong>outline</strong>: 3px solid #ccc; }
</pre>
<p><img src="http://images.sixrevisions.com/2010/04/13-02_basic_styled_hover.jpg" width="226" height="187" alt="Basic styled caption using generated content" /></p>
<p>We now have a simple and effective caption overlay, which has very lean mark-up and some simple CSS to create an effective technique.</p>
<h3>Let&#8217;s extend it further</h3>
<p>We have a simple caption overlay that works nicely, but how about we add some additional styles so we can change the position of the caption very easily by adding a couple lines of CSS?</p>
<p>We will create a <code>.reverse</code> class that we can assign to  any  of our anchor elements that will reposition our caption to appear at the top of the image rather than the bottom.</p>
<pre>
ul a<strong>.reverse</strong>:hover:after,
ul a<strong>.reverse</strong>:focus:after { top: 0px; }</pre>
<p><img src="http://images.sixrevisions.com/2010/04/13-03_basic_styled_extended_hover.jpg" width="159" height="222" alt="Change caption position using minimal CSS" /></p>
<p>We can also create an <code>.offset</code> class to position the caption in the middle or offset it by any value. The negative margin is used to pull it into the middle.</p>
<pre>
ul a.offset:hover:after,
ul a.offset:focus:after { top: 50%; margin-top: -15px; }</pre>
<p><img src="http://images.sixrevisions.com/2010/04/13-04_basic_styled_extended_hover.jpg" width="226" height="170" alt="Another example of changing caption position using minimal CSS" /></p>
<h3>A sprinkle of CSS3</h3>
<p>Of course, I couldn&#8217;t resist using some CSS3 goodness to make it that little bit nicer. At this point, we&#8217;re just using the principles of Progressive Enhancement where browsers that are CSS3-capable will have a slightly better experience. Our effect will still work on CSS2-capable browsers (such as Internet Explorer) even after we&#8217;ve spruced it up with CSS3.</p>
<p>On the anchor I&#8217;ve added the CSS3 <code>box-shadow</code> property to create a nice drop shadow effect when the image is hover/focused on. The outline is set to <code>none</code> so that the dotted outline won&#8217;t appear when it&#8217;s focused on.</p>
<p>(Check out <a href="http://sixrevisions.com/css/css3-techniques-you-should-know/" title="CSS3 Techniques You Should Know"><strong>more CSS3 techniques</strong></a>.)</p>
<p>Normally this would be frowned upon, but since we are adequately showing that the image has focus by showing the caption, outlining the image and applying the drop shadow, it&#8217;s still obvious that the element in question has focus.</p>
<p><strong>Note:</strong> It should be said that the <code>box-shadow</code> property has officially been removed from the W3C CSS3 draft specification for further discussion, however browser vendors appear to have no plans of removing it any time soon, if ever.</p>
<pre>
ul a:hover, ul a:focus
{
    display: block;
    outline: none;
<strong>    -moz-box-shadow: 3px 3px 5px #000;
    -webkit-box-shadow: 3px 3px 5px #000;
    box-shadow: 3px 3px 5px #000; </strong>
}</pre>
<p><img src="http://images.sixrevisions.com/2010/04/13-05_css3_styled_extended_hover.jpg" width="226" height="187" alt="Using CSS3 we can improve the look for the better browsers" /></p>
<p>Using the CSS3 <code>rgba()</code> property, we can make the background slightly opaque so that the image can be seen beneath our caption. Setting <code>rgb</code> before our <code>rgba</code> value ensures that browsers such as IE8 still show a background.</p>
<pre>
ul a:hover:after,
ul a:focus:after
{
    background: <strong>rgb</strong>(255,255,255);
    background: <strong>rgba</strong>(255,255,255,0.7);
}</pre>
<p>We can also add a CSS gradient in Firefox 3.6, Safari 4 and Chrome 4. (See another tutorial on using <a href="http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/"><strong>CSS gradients on your web typography</strong></a>.)</p>
<p>In the gradient, we also use <code>rgba</code> so that we can have an opaque gradient that blends between two colours.</p>
<pre>

background: <strong>-moz-linear-gradient</strong>(top, rgba(255,255,255,0.7), rgba(204,204,204,0.7)); /* Firefox 3.6+ */
background: <strong>-webkit-gradient</strong>(linear, 0% 0%, 0% 100%, from(rgba(255,255,255,0.7)), to(rgba(204,204,204,0.7))); /* Safari/Chrome */
</pre>
<p>To make the caption text pop out a little more, I&#8217;ve added the <code>text-shadow</code> property to give it a subtle drop-shadow on the text.</p>
<pre>
text-shadow: 1px 1px 1px #fff;
</pre>
<p><img src="http://images.sixrevisions.com/2010/04/13-06_css3_styled_extended_hover.jpg" width="452" height="187" alt="Using more CSS3 to add transparency, gradients and text shadows" /></p>
<p>Another CSS3 property that is quite useful is <code>box-sizing</code>, which lets us adjust how the box model works.</p>
<pre>
ul a.alternate01:hover:after,
ul a.alternate01:focus:after
{
    top: 0;
    width: 50%;
    height: 100%;
    line-height: normal;
    text-align: left;
    padding: 4px;
    font-size: 12px;
    <strong>-moz-box-sizing: border-box;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;</strong>
}</pre>
<p>By adjusting the box model, the technique can further extend the caption by utilising box-sizing to our advantage, and so we can keep this technique as flexible as possible by making the overlay cover half the image and have the content run down the side.</p>
<p>With a few adjustments, it&#8217;s quite simple using this technique.</p>
<p><img src="http://images.sixrevisions.com/2010/04/13-07_css3_styled_extended_hover.jpg" width="226" height="187" alt="Using more CSS3 we can adjust the box model and have vertical captions" /></p>
<p>The box model—by default—adds padding and borders on top of the height that is set, and since we are setting our height to a 100%, this will essentially push out our overlay by a few pixels.</p>
<p>To change that behaviour, we utilise the CSS3 <code>box-sizing</code> property and set it to <code>border-box</code>. This allows us to set our percentage value and have any padding and borders calculated in conjunction with our height, so as not to push it out like it naturally does.</p>
<p>By default box-sizing is set to content-box. IE8 obviously doesn&#8217;t support this property, however IE&#8217;s box model naturally behaves like it was set to <code>box-sizing: border-box</code> and therefore doesn&#8217;t need any special treatment to work.</p>
<p>Mozilla and WebKit based browsers require their specific prefixes, whereas Opera supports it without any need for a prefix.</p>
<pre>
ul a.reverse:hover:after,
ul a.reverse:focus:after { top: 0; right: 0; }</pre>
<p><img src="http://images.sixrevisions.com/2010/04/13-08_css3_styled_extended_hover.jpg" width="226" height="187" alt="We can also reverse the position of the vertical caption" /></p>
<p>With a small addition to our original reverse class, adding <code>right: 0</code>, we can create some reusable CSS to reverse it either horizontally or vertically without affecting either of the anchors that have the <code>.reverse</code> class. Depending on the caption type— horizontal or vertical—the <code>.reverse</code> class will handle either situation correctly.</p>
<h3>It wouldn&#8217;t be CSS if IE didn&#8217;t do something funky</h3>
<p>Of course, IE8—ironically, the first IE browser to support the full CSS2.1 spec—has got an issue with generated content.</p>
<p>Upon initial testing, I thought IE8 didn&#8217;t actually support generated content as when I hovered over the image, nothing was showing up.</p>
<p>After some testing and using a text colour that contrasted with the image, I noticed that the background colour wasn&#8217;t showing up, but the text was.</p>
<p>So then, I thought at least it still works, just not with a background. Not content with that, I investigated further and discovered that the background colour was appearing behind the image. Don&#8217;t ask me how or why this is happening.</p>
<p>I came up with a solution that fixes this issue and allows the CSS-generated content and its background to appear over the image like it does in the other browsers.</p>
<p>Basically, we give the image a relative position and set the <code>z-index</code> to <code>-1</code> to force it under the generated content.</p>
<p>We then have to reset the position back to <code>static</code> for the better browsers as position relative causes havoc with the caption overlay. I utilised the CSS3 <code>not()</code> pseudo-selector—which IE8 doesn&#8217;t support—and set the position back to its default behaviour of <code>static</code>.</p>
<pre>
ul li img { position: relative; z-index: -1; } /* For IE8 */
ul li:not(#foo) img { position: static; } /* Reset position for better browsers */</pre>
<h3>Putting it all together</h3>
<p> Let&#8217;s put it all together into a fully working version.</p>
<p>You can see a demonstration of the <a href="http://www.thecssninja.com/demo/css_hover2/">snazzy hover effects</a> using various images sizes to show its flexibility.</p>
<p>Here&#8217;s the full markup required to create a single image with caption overlays. The demo page has more images on it, as well as demonstrating changing colours and shifting the overlaying caption into different positions as explained earlier in the article, just to show various potential tweaks and use cases.</p>
<pre>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;

&lt;head&gt;
    &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
    &lt;link rel="stylesheet" type="text/css" href="_styles.css" media="screen" /&gt;
    &lt;title&gt;Snazzy hover effects using CSS demo&lt;/title&gt;

&lt;/head&gt;
&lt;body&gt;
    &lt;ul&gt;
        &lt;li&gt;
            &lt;a href="#" title="Sunrise on the farm"&gt;
                &lt;img src="img_sunrise.jpg" width="300" height="200" alt="Beautiful sunrise" /&gt;
            &lt;/a&gt;

        &lt;/li&gt;
    &lt;/ul&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>And the CSS to transform the simple markup into a snazzy hover/focus effect.</p>
<pre>
ul { overflow: hidden; padding: 5px; }
ul > li {
    position: relative;
    float: left;
    list-style: none;
    margin: 0 20px 20px 0;
    font-size: 10px;
}
ul a { text-decoration: none; display: block; }

ul li img { display: block; position: relative; z-index: -1; } /* IE8 fix, background colour appears behind img for uknown reason set negative z-index */
ul li:not([class=na]) img { position: static; } /* Reset relative position, as this plays havoc with good browsers */

ul a:hover, ul a:focus
{
    display: block;
    outline: none;
    -moz-box-shadow: 3px 3px 5px #000;
    -webkit-box-shadow: 3px 3px 5px #000;
    box-shadow: 3px 3px 5px #000;
}
ul a:hover img, ul a:focus img { outline: 3px solid #ccc; }

ul a:hover:after,
ul a:focus:after
{
    content: attr(title);
    color: #000;
    position: absolute;
    bottom: 0;
    height: 30px;
    line-height: 30px;
    text-align: center;
    font-weight: bold;
    width: 100%;
    background: rgb(255,255,255);
    background: rgba(255,255,255,0.7);
    background: -moz-linear-gradient(top, rgba(255,255,255,0.7), rgba(204,204,204,0.7)); /* Firefox 3.6+ */
    background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgba(255,255,255,0.7)), to(rgba(204,204,204,0.7))); /* Safari */
    display: block;
    text-shadow: 1px 1px 1px #fff;
}
</pre>
<h3>Wrap up</h3>
<p>We now have a simple technique that&#8217;s very  capable using only CSS2.1. Of course, I also showed how to spruce it up with some additional—but not critical—CSS3 to make it a little nicer in more modern browsers.</p>
<p>We have good browser support; it works in all the latest release browsers.</p>
<p>And we made sure the technique was keyboard-accessible so that if you don&#8217;t  or can&#8217;t use a mouse, the technique still works.</p>
<p><strong><em>What do you think? Will you be using any of the techniques I&#8217;ve mentioned above? Why or why not?</em></strong> Share your thoughts and questions in the comments.</p>
<h3>Download Source Files</h3>
<ul>
<li><a href="http://sixrevisions.com/demo/snazzy_hover_css/snazzy_hover_css.zip">snazzy_hover_css</a> (ZIP, 44.0 KB)</li>
</ul>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/css/30-exceptional-css-navigation-techniques/">30 Exceptional CSS Navigation Techniques</a></li>
<li><a href="http://sixrevisions.com/css/30_css_techniques_examples/">30 Exceptional CSS Techniques and Examples</a></li>
<li><a href="http://sixrevisions.com/resources/14-jquery-plugins-for-working-with-images/">14 jQuery Plugins for Working with Images</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web-development/">Web Development</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/ryan_seddon_small.jpg" alt="" width="80" height="80" /><span class="author-bio-text"><strong>Ryan Seddon</strong> is  front-end developer  based in Melbourne,   Australia. He  loves to tinker with CSS, JavaScript and coming up with new techniques. You can  find his discoveries and articles at his  blog, <strong><a href="http://www.thecssninja.com/">The CSS Ninja</a></strong>. You can  also connect with him through Twitter: <strong>@<a href="http://twitter.com/thecssninja">thecssninja</a></strong>.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/snazzy-hover-effects-using-css/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>How to Create Inset Typography with CSS3</title>
		<link>http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/</link>
		<comments>http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/#comments</comments>
		<pubDate>Sun, 21 Mar 2010 12:57:31 +0000</pubDate>
		<dc:creator>Jacob Gube</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://sixrevisions.com/?p=2828</guid>
		<description><![CDATA[In this tutorial, we'll create inset type, a popular text treatment, using CSS. We'll do all of this in less than ten lines of CSS.]]></description>
			<content:encoded><![CDATA[<p><a href="http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/"><img src="http://images.sixrevisions.com/2010/03/22-01_inset_type_heading.jpg" width="550" height="200" alt="Create Inset Typography with CSS3" /></a></p>
<p>In this tutorial, we&#8217;ll create inset type, a <a href="http://sixrevisions.com/design-showcase-inspiration/beautiful-examples-of-inset-typography-in-web-design/">popular  text treatment</a>, using CSS. If you follow Six Revisions closely, you&#8217;re probably thinking: &quot;Jacob already wrote a <a href="http://sixrevisions.com/tutorials/photoshop-tutorials/how-to-create-inset-typography-in-photoshop/">Photoshop tutorial</a> on how to do that.&quot;</p>
<p>That is correct, but this time we are going to do it using only CSS.</p>
<p><span id="more-2828"></span></p>
<p>I set out to  recreate the <a href="http://sixrevisions.com/tutorials/photoshop-tutorials/how-to-create-inset-typography-in-photoshop/">How to Create Inset Typography in Photoshop</a> tutorial, and after experimenting with some fresh and new CSS3 properties, I was able to make a similar type treatment.</p>
<p>We&#8217;ll do all of this in less than ten lines of CSS.</p>
<h3>Step 1: The HTML markup</h3>
<p>Let&#8217;s first set up the HTML, which is super simple. The typography will be an <code>h1</code> element, wrapped around a <code>div</code> for its background.</p>
<pre>
&lt;div id="insetBgd"&gt;
	&lt;h1 class="insetType"&gt;Inset Typography&lt;/h1&gt;
&lt;/div&gt;
</pre>
<h3>Step 2: The background</h3>
<p>The first bit of CSS we want to do is the background. We are going to create it similar to the background in the Photoshop tutorial mentioned above. We&#8217;ll set the width to <code>550px</code> and height to <code>100px</code>.</p>
<p>Next, we are going to use CSS3 gradients. If you&#8217;ve never used the required browser extensions for CSS3, hop on over to my  previous article called <a href="http://sixrevisions.com/css/css3-techniques-you-should-know/">CSS3 techniques you should know</a> first, to catch up.</p>
<p>We want the background to have a gradient going top to bottom, from <span class="color1"><code>#003471</code></span> to <span class="color2"><code>#448CCB</code></span>.</p>
<p>The code to do this is:</p>
<pre>
#insetBgd {
 width: 550px;
 height: 100px;
 background: -moz-linear-gradient(-90deg, #003471, #448CCB);
 background: -webkit-gradient(linear, left top, left bottom, from(#003471), to(#448CCB));
}</pre>
<p><img src="http://images.sixrevisions.com/2010/03/22-02_css_background.jpg" width="550" height="100" alt="22-02_css_background" /></p>
<h3>Step 3: Define the font stack and styles</h3>
<p>Next, we want to define our preferred font. The Photoshop tutorial used Rockwell STD, but we are going to just use the normal Rockwell. Neither are considered acceptable web-safe fonts, but more users will have the plain, old Rockwell than the Rockwell STD variant.</p>
<p>However, in  case the user doesn&#8217;t have Rockwell, we&#8217;ll define a few web-safe fonts to render in its place.</p>
<p>In the example, I set the <code>font-size</code> to <code>50px</code>, and the font <code>color</code> to <span class="color3"><code>#0D4383</code></span>. Here&#8217;s what we have:</p>
<pre>
h1.insetType {
  font-family: Rockwell, Georgia, "Times New Roman", Times, serif;
  font-size: 50px;
  color: #0D4383;
}</pre>
<p><img src="http://images.sixrevisions.com/2010/03/22-03_font_stack.jpg" width="550" height="100" alt="Define Font stack" /></p>
<h3>Step 4: The inset styles</h3>
<p>The next and final step is the most important part. We&#8217;ll style the font and give it the &#8220;inset&#8221; look we&#8217;re trying to achieve. We&#8217;ll do this by using the <code>text-shadow</code> style.</p>
<p>You&#8217;ll notice Jacob used &#8220;inner shadow&#8221; in Photoshop to get this effect. Unfortunately for us, <code>text-shadow</code> doesn&#8217;t have an &#8220;inset&#8221; value. So what we&#8217;ll have to do is create multiple instances of RGBA black and white 1px shadows, some being negative pixels, as well as adding different levels of opacity to each.</p>
<p>I messed around with a bunch of different variations, and settled on this:</p>
<pre>
  text-shadow: rgba(0,0,0,0.5) -1px 0, rgba(0,0,0,0.3) 0 -1px, rgba(255,255,255,0.5) 0 1px, rgba(0,0,0,0.3) -1px -2px;
</pre>
<p>Add the <code>text-shadow</code> style to the <code>h1.insetType</code> class above, and our final CSS code looks like the following:</p>
<pre>
#insetBgd {
  width: 550px;
  height: 100px;
  background: -moz-linear-gradient(-90deg,#003471,#448CCB);
  background: -webkit-gradient(linear, left top, left bottom, from(#003471), to(#448CCB));
}

h1.insetType {
  padding-left: 50px; /* The padding is just there to move the h1 element to the center of the div */
  padding-top: 17px;
  font-family: Rockwell, Georgia, "Times New Roman", Times, serif;
  font-size: 50px;
  color: #0D4383;
  text-shadow: rgba(0,0,0,0.5) -1px 0, rgba(0,0,0,0.3) 0 -1px, rgba(255,255,255,0.5) 0 1px, rgba(0,0,0,0.3) -1px -2px;
}
</pre>
<h3>CSS3 Inset Typography Demo:</h3>
<p>Below, you&#8217;ll see the final result. Note that you&#8217;ll only be able to see it if your browser supports current CSS3 specs for the attributes that we used in this tutorial.</p>
<p><iframe src="http://downloads.sixrevisions.com/create_inset_iypography_with_CSS3.html" width="100%" height="120" frameBorder="0" scrolling="no"></p>
<p>Your browser does not support iframes, you will not be able to view this demo.</p>
<p></iframe></p>
<h3>What It Looks like in Firefox 3.6 (without Rockwell)</h3>
<p>Below is a screen shot of what this effect should look like, taken through a Windows OS machine, Firefox 3.6 and without Rockwell installed.</p>
<p><img src="http://images.sixrevisions.com/2010/03/22-04_firefox_inset_typography_screenshot.png" width="550" height="100" alt="Your browser does not support iframes, you will not be able to view this demo." /></p>
<h3>Conclusion</h3>
<p>So there you have it. Pretty simple, right? It may not look quite as good as it would in Photoshop, but it will take up less load time, it&#8217;s more flexible than a static image, and it&#8217;s all done without any special software.</p>
<p>I want to give credit to <a href="http://stylizedweb.com/2009/10/22/how-to-create-inset-text-with-css3/">StylizedWeb</a> for giving me an idea of how to go about doing this. Thanks for reading!</p>
<h3>Related Content</h3>
<ul>
<li><a href="http://sixrevisions.com/css/20-useful-resources-for-learning-about-css3/">20 Useful Resources for Learning about CSS3</a></li>
<li><a href="http://sixrevisions.com/css/css3-techniques-you-should-know/">CSS3 Techniques You Should Know</a></li>
<li><a href="http://sixrevisions.com/css/basic-css3-techniques-that-you-should-know/">Basic CSS3 Techniques That You Should Know</a></li>
<li><em>Related categories</em>: <a href="http://sixrevisions.com/category/css/">CSS</a> and <a href="http://sixrevisions.com/category/web_design/">Web Design</a></li>
</ul>
<h3>About the Author</h3>
<p class="about-author"><img src="http://images.sixrevisions.com/authors/andrew_roberts_small.jpg" alt="" width="80" height="80" /><strong>Andrew Roberts</strong> is a Christian with a passion for  web design and development. His web interests focus mostly on HTML/CSS, JavaScript, &amp; PHP/MySQL. When he&#8217;s not glued to the computer,  he&#8217;s  spending time with his girlfriend Kaitlynn, <a href="http://www.flickr.com/photos/zoonino">photographing  animals</a>, or reading. His  goal is to attend graduate school for  Biblical studies  &amp; ministry.</p>
]]></content:encoded>
			<wfw:commentRss>http://sixrevisions.com/css/how-to-create-inset-typography-with-css3/feed/</wfw:commentRss>
		<slash:comments>33</slash:comments>
		</item>
	</channel>
</rss>
