<?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>The CSS Ninja &#187; css</title>
	<atom:link href="http://www.thecssninja.com/category/css/feed" rel="self" type="application/rss+xml" />
	<link>http://www.thecssninja.com</link>
	<description>All things CSS, Javascript &#38; xhtml</description>
	<lastBuildDate>Mon, 30 Aug 2010 10:21:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Pure CSS collapsible tree menu</title>
		<link>http://www.thecssninja.com/css/css-tree-menu</link>
		<comments>http://www.thecssninja.com/css/css-tree-menu#comments</comments>
		<pubDate>Wed, 14 Jul 2010 11:52:53 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[pure css]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=653</guid>
		<description><![CDATA[The classic tree view, we all know it, it&#8217;s used everywhere and it definitely can be useful in the right context. I&#8217;ve seen various examples about doing it with CSS and they&#8217;ve all required JavaScript. Not content with any of those solutions I investigated doing it with pure CSS, I got a good head start [...]]]></description>
			<content:encoded><![CDATA[<p>The classic tree view, we all know it, it&#8217;s used everywhere and it definitely can be useful in the right context. I&#8217;ve seen various examples about doing it with CSS and they&#8217;ve all required JavaScript. Not content with any of those solutions I investigated doing it with pure CSS, I got a good head start from my <a href="http://www.thecssninja.com/css/custom-inputs-using-css">Custom Radio and Checkbox inputs</a> article. From there I&#8217;ve come up with a solution that works pretty well.<span id="more-653"></span></p>
<div class="clear">&nbsp;</div>
<h2 class="subtitle02">Another demo, another bug</h2>
<p>Everything I seem to investigate lately seems to present itself with an annoying bug/feature in various browsers. Last time it was the inconsistency between browsers and generated content on form elements. This time it is WebKit not being able to apply styles using the checked pseudo-class in conjunction with a general sibling combinator (<code>E ~ F</code>) or chained adjacent sibling combinator (<code>E + F + F</code>). Making it very hard, and probably the reason I haven&#8217;t seen a CSS solution that works in WebKit browsers. I did come across this <a href="http://bradclicks.com/CSSplay/foldingList.html">demo</a> but due to the bug mentioned above doesn&#8217;t work in WebKit browsers.</p>
<p>So I soldiered on and came up with a pretty decent attempt, and remember folks I&#8217;m not a designer so be kinder this time with design critiques all I&#8217;m doing is showing you how to do the technique <img src='http://www.thecssninja.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> . With that out of the way let&#8217;s dig into the inner workings and road blocks I faced.</p>
<h2 class="subtitle02">General sibling combinators are flaky</h2>
<p>The CSS3 selector module has a very useful addition to compliment the CSS2.1 adjacent sibling combinator. Unlike the adjacent selector the general selector gives us some flexibility in that it will match a sibling that isn&#8217;t immediately preceded by our first element.</p>
<p>Great, I have 3 elements an &lt;input&gt;, &lt;label&gt; &#038; &lt;ol&gt; the general sibling combinator is the perfect tool to do things like <code>input:checked ~ ol</code>. Check Firefox, awesome works, Opera too! Woo! Surely WebKit will have this&#8230;nope nothing. Let me try <code>input ~ ol</code>, yep works across the board, *face palm*.</p>
<p>So I dug into <a href="https://bugs.WebKit.org/">WebKits bug tracker</a> and came out with <a href="https://bugs.WebKit.org/show_bug.cgi?id=12520">this bug</a> which has been around since 2007. Stating that general sibling combinators in combination with dynamic CSS, ala <code>:checked</code>, won&#8217;t reflect changes. Nor will it do chained adjacent combinator which was going to be my next solution.</p>
<p>However doing <code>:checked</code> with a single adjacent sibling combinator works fine in post 2008 WebKit browsers. So using this information I went about and built a working demo that has good browser support.</p>
<div class="resources01"><a target="_blank" class="demo" title="Pure CSS collapsible tree menu demonstration" href="http://www.thecssninja.com/demo/css_tree/">View live demo</a> <a target="_blank" class="demo source" title="Download the source of the Pure CSS collapsible tree menu" href="http://www.thecssninja.com/demo/css_tree/css_tree.zip">Download the source files</a></div>
<p>The demo is built using an ordered list (ol) nested with further ordered lists to naturally represent a basic folder structure.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ol</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;document.pdf&quot;</span>&gt;</span>File 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;subfolder1&quot;</span>&gt;</span>Subfolder 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;subfolder1&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ol</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>File 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>File 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;file&quot;</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;&quot;</span>&gt;</span>File 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ol</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ol</span>&gt;</span></pre></div></div>

<p>As you can see, in order to get around the general combinator issue in WebKit based browsers I have switched the label to come first then the input so the &#8220;folders&#8221; could be expanded/collapsed by checking/unchecking the checkbox.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">li input
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>;
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> 0;
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> 0;
    opacity<span style="color: #00AA00;">:</span> 0;
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">2</span>;
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span>;
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span>;
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span>;
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> 0;
<span style="color: #00AA00;">&#125;</span>
li label
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>img<span style="color: #00AA00;">&#41;</span> <span style="color: #933;">15px</span> <span style="color: #933;">1px</span> <span style="color: #993333;">no-repeat</span>;
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span>;
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
    <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">37px</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>To sit the input and label in the right visual order I absolutely positioned the input and applied a left padding to the label to push it out. That way changing the styles of the child ol, when the input is checked, can be done using the adjacent sibling combinator. I&#8217;ve also set the cursor to pointer when hovered over the input or label to visual show they&#8217;re clickable.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">li input <span style="color: #00AA00;">+</span> ol
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">toggle-small-expand.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">40px</span> 0 <span style="color: #993333;">no-repeat</span>;
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-0.938em</span> 0 0 <span style="color: #933;">-44px</span>; <span style="color: #808080; font-style: italic;">/* 15px */</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1em</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Unlike my custom radio and checkbox article where I added the background image on the label, this time I had to do some trickery and apply it to the direct sibling ol of an input. Applying a sprite image to the ol wouldn&#8217;t be possible in this situation due to it being applied to the ol which would make it difficult to effectively hide other images within the sprite image.</p>
<p>To position the ol correctly I use a negative margin to pull it into the right location so it will sit next to the label and underneath the invisible checkbox.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">li input <span style="color: #00AA00;">+</span> ol <span style="color: #00AA00;">&gt;</span> li
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> 0;
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span>;
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-14px</span> !important;
    <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>To hide the sub folders so they don&#8217;t appear when the parent folder is collapsed I target the child list items and set them to a zero height and hide any overflow.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">li label
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">folder.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;">15px</span> <span style="color: #933;">1px</span> <span style="color: #993333;">no-repeat</span>;
<span style="color: #00AA00;">&#125;</span>
li<span style="color: #6666ff;">.file</span> a
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">document.png</span><span style="color: #00AA00;">&#41;</span> 0 <span style="color: #933;">-1px</span> <span style="color: #993333;">no-repeat</span>;
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span>;
    <span style="color: #000000; font-weight: bold;">padding-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">21px</span>;
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>To differentiate between folders and files I applied a background image to either the label or to an anchor within a list item for files.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">li
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span>;
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-15px</span>;
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
<span style="color: #00AA00;">&#125;</span>
li<span style="color: #6666ff;">.file</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-1px</span> !important;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>To pull out the folder list items I apply a larger negative margin so the folder will line up with any of the file icons, and for file based list items I reset the left margin so they sit flush.</p>
<h2 class="subtitle02">Change icon based on file extension</h2>
<p>With some CSS3 attribute selectors we can determine an anchor links file format and change the icon accordingly.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">li<span style="color: #6666ff;">.file</span> a<span style="color: #00AA00;">&#91;</span>href $<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">'.pdf'</span><span style="color: #00AA00;">&#93;</span>     <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-16px</span> <span style="color: #933;">-1px</span>; <span style="color: #00AA00;">&#125;</span>
li<span style="color: #6666ff;">.file</span> a<span style="color: #00AA00;">&#91;</span>href $<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">'.html'</span><span style="color: #00AA00;">&#93;</span>   <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-32px</span> <span style="color: #933;">-1px</span>; <span style="color: #00AA00;">&#125;</span>
li<span style="color: #6666ff;">.file</span> a<span style="color: #00AA00;">&#91;</span>href $<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">'.css'</span><span style="color: #00AA00;">&#93;</span>    <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-48px</span> <span style="color: #933;">-1px</span>; <span style="color: #00AA00;">&#125;</span>
li<span style="color: #6666ff;">.file</span> a<span style="color: #00AA00;">&#91;</span>href $<span style="color: #00AA00;">=</span> <span style="color: #ff0000;">'.js'</span><span style="color: #00AA00;">&#93;</span>      <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-64px</span> <span style="color: #933;">-1px</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Using the <code>$=</code> CSS attribute selector allows us to check the end of an attribute exactly ends in .pdf, .html etc.</p>
<p>If for some reason you attribute doesn&#8217;t end with your file extension, your anchor may have a query string on the end. We can still match file types.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">li<span style="color: #6666ff;">.file</span> a<span style="color: #00AA00;">&#91;</span>href <span style="color: #00AA00;">*=</span> <span style="color: #ff0000;">'.pdf'</span><span style="color: #00AA00;">&#93;</span>   <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-16px</span> <span style="color: #933;">-1px</span>; <span style="color: #00AA00;">&#125;</span>
li<span style="color: #6666ff;">.file</span> a<span style="color: #00AA00;">&#91;</span>href <span style="color: #00AA00;">*=</span> <span style="color: #ff0000;">'.html'</span><span style="color: #00AA00;">&#93;</span>  <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-32px</span> <span style="color: #933;">-1px</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The <code>*=</code> will match a substring that contains .pdf or .html anywhere within the attribute and if a href has a query string we can still match our file extension without issue. This does have the slight disadvantage that it will match it anywhere e.g. if you have a file called file.html.pdf it will match both file types and the one with the higher CSS specificity will be applied or incase of the example above their CSS specificity is the same so the html background will be applied.</p>
<h2 class="subtitle02">Checkbox attributes</h2>
<p>In the demo by default the first folder is open, this is done by adding the checked attribute to the checkbox which will trigger our styles thanks to the checked pseudo-class and reveal its sub files and folders.</p>
<p>We can also add the disabled attribute to the checkbox to stop a user from opening a folder as the input can neither be checked or unchecked.</p>
<p>Lastly using a combination of both disabled and checked will allow us to reveal the sub files and folders but not allow the user to close the top level folder.</p>
<h2 class="subtitle02">Browser support</h2>
<p>Based on testing this will work in any CSS3 selector supporting browser. The following have been tested and known to work</p>
<ul>
<li>Firefox 1+</li>
<li>Opera 9.6+</li>
<li>Safari 4+</li>
<li>iPhone/iPod Safari</li>
<li>Chrome 1+</li>
<li>Android</li>
<li>IE9+</li>
</ul>
<p>This could very well work in IE8 but would require some JavaScript to get IE8 to interpret the checked pseudo-class, which I won&#8217;t be going into.</p>
<p>Right now I use conditional comments to hide the stylesheet from all versions of IE and another conditional comment to load the stylesheet for IE9 and greater.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--[if gte IE 9 ]&gt;</span>
<span style="color: #808080; font-style: italic;">    &lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;_styles.css&quot; media=&quot;screen&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if !IE]&gt;--&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;_styles.css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--&lt;![endif]--&gt;</span></pre></div></div>

<h2 class="subtitle02">Highly scalable</h2>
<p>This technique will cater for a large amount of sub folders and files. It&#8217;s governed by your screen real estate and even then it&#8217;ll apply scroll bars to the document when the tree structure gets too long or wide.</p>
<p>Any questions/comments/suggestions leave a comment.</p>
<p class="shorty01">Short URL: <a href="http://cssn.in/ja/026">http://cssn.in/ja/026</a></p>
<div class="clear">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/css/css-tree-menu/feed</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Futurebox, lightbox without the javascript and target pseudo-class</title>
		<link>http://www.thecssninja.com/css/futurebox3</link>
		<comments>http://www.thecssninja.com/css/futurebox3#comments</comments>
		<pubDate>Sat, 10 Apr 2010 02:05:14 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[futurebox]]></category>
		<category><![CDATA[modals]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=633</guid>
		<description><![CDATA[So I recently released a revised version of Futurebox which added a lot of functionality. But one thing was nagging me, the fact that it utilised the target pseudo-class to hijack in page anchors which has a few side effects that can create some major drawbacks to the technique. One being that if you click [...]]]></description>
			<content:encoded><![CDATA[<p>So I recently released a <a href="http://www.thecssninja.com/xhtml/futurebox">revised version of Futurebox</a> which added a lot of functionality. But one thing was nagging me, the fact that it utilised the <a href="http://www.w3.org/TR/css3-selectors/#target-pseudo">target pseudo-class</a> to hijack in page anchors which has a few side effects that can create some major drawbacks to the technique. One being that if you click multiple futurebox links and then click the browser back button it will go through all the previous overlays that were activated due to the natural behaviour of in page anchors. The other drawback, clicking an in page anchor can cause the page to abruptly jump as it tries to bring the anchor location to the top of the page.<span id="more-633"></span></p>
<p>But you’re thinking I&#8217;m mad, there can&#8217;t possibly be any other way to trigger a pure CSS overlay.</p>
<div class="resources01"><a target="_blank" class="demo" title="Futurebox, lightbox without the javascript and target pseudo-class" href="http://www.thecssninja.com/demo/futurebox/v3">View a live demo</a> <a target="_blank" class="demo source" title="Download the source of the Futurebox demo" href="http://www.thecssninja.com/demo/futurebox/v3/futurebox3.zip">Download the source files</a></div>
<h2 class="subtitle02">Radio buttons?!</h2>
<p>Yep this technique uses radio inputs along with the checked CSS3 pseudo-class, which I described in my <a href="http://www.thecssninja.com/css/custom-inputs-using-css">custom checkbox/radio inputs</a> article, to show/hide the futurebox modals.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;futurebox01&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image.gif&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;102&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;The CSS Ninja&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;futurebox01&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gallery&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;overlay&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;close&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Close futurebox&quot;</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image.png&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;The Css Ninja&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;469&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;500&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<p>The mark-up differs from the <a href="http://www.thecssninja.com/demo/futurebox/">original futurebox</a>. The overlay now needs to appear directly below the image, the images are wrapped in a label as well as the overlay, we set the &#8220;for&#8221; attribute on the label so we can check the radio without having to actually click the radio. We also use that to our advantage so we can actually close the modal once it&#8217;s been opened by having the large image wrapped in a label with a &#8220;for&#8221; attribute to a hidden radio button.</p>
<p>Having the same name value on all the inputs makes sure only one of the radio buttons can be checked at any one time.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">ul li input <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>; <span style="color: #00AA00;">&#125;</span>
ul li input<span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> <span style="color: #6666ff;">.overlay</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> table; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Since we don&#8217;t actually want or need to see the radio button we hide it. As mentioned before the &#8220;for&#8221; attribute controls the checking and unchecking of the input.</p>
<p>Unfortunately due to a <a href="http://connect.microsoft.com/IE/feedback/details/542479/label-wont-trigger-input-focus-if-i-use-anything-other-than-text-inside-a-label">bug in IE</a> (you&#8217;ll need to login to view it, or just change your UA string to googlebot <img src='http://www.thecssninja.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) only labels with text trigger the input. Since IE9 is the first IE to support the checked pseudo-class if this bug is fixed this technique will work, until then it won&#8217;t. Let&#8217;s hope a fix makes it into IE9 final release.</p>
<p>The second line uses the checked pseudo-class to apply display: table to the inputs direct sibling with a class of overlay.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.overlay</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span>;
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span>;
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>;
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> 0;
    <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> 0;
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
    <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">999</span>;
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">rgb</span><span style="color: #00AA00;">&#40;</span>0<span style="color: #00AA00;">,</span>0<span style="color: #00AA00;">,</span>0<span style="color: #00AA00;">&#41;</span>;
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> rgba<span style="color: #00AA00;">&#40;</span>0<span style="color: #00AA00;">,</span>0<span style="color: #00AA00;">,</span>0<span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0.7</span><span style="color: #00AA00;">&#41;</span>;
<span style="color: #00AA00;">&#125;</span>
    <span style="color: #6666ff;">.overlay</span> label
    <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">table-cell</span>;
        <span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">middle</span>;
        <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span>;
    <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The overlay styles don&#8217;t differ at all to the original demo, except that instead of an anchor tag wrapping the image it&#8217;s now a label. When the input is checked the overlay sibling of that input becomes visible, by setting it to display: table, as shown in the previous CSS block. The label has display: table-cell applied to it so it&#8217;ll act like a table cell and naturally fill all height and width available to it. Applying vertical-align: middle will make the image vertically center and to horizontally center the image we take advantage of the fact that images are inline elements and just set the label to have text-align: center.</p>
<h2 class="subtitle02">Not just for images</h2>
<p>Since futurebox was only ever originally meant for loading images I thought I would extend this new version to also load static and dynamic content (iframes). In the demo the second listing shows 2 examples of static content and 2 examples of loading an iframe.</p>
<h2 class="subtitle02">Static content</h2>
<p>In order to show static content within a futurebox overlay the mark-up differs slightly.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;futurebox01&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;image.gif&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;102&quot;</span> <span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;The CSS Ninja&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;futurebox01&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gallery&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;overlay&quot;</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;close&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Close futurebox&quot;</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content01&quot;</span>&gt;</span>
                    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;inner_content&quot;</span>&gt;</span>
                        // content goes here
                    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<p>Rather than have the image we have 2 spans, although 1 is fine I used 2 to make the scrolling look nicer.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.content01</span>
<span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
        <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">460px</span>;
        <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span>;
        <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span>;
        <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span>;
        <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 0 <span style="color: #993333;">auto</span>;
        <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
        <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span>;
        -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
        -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
        border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
<span style="color: #00AA00;">&#125;</span>
    <span style="color: #6666ff;">.content01</span> <span style="color: #6666ff;">.inner_content</span>
    <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
        <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span>;
        overflow-y<span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span>;
    <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The content span I apply a base width and some padding along with applying some CSS3 to give the modal some nice rounded corners.</p>
<p>The inner content span I set a fixed height and apply overflow-y to auto so any content that extends further will show a vertical scrollbar otherwise if the content fits it will hide the scrollbar.</p>
<p>The reason I use spans and not divs is because a label is a inline element and putting divs inside it is not only invalid but will also cause render issues in some browsers. So using a span and setting it to display: block handles that dilemma.</p>
<h2 class="subtitle02">Change the height of individual modals</h2>
<p>Since the base height of the static content container is quite high putting in a small amount of content will create alot of empty white space. You can get around it by targeting specific futurebox modals and set the height to something else.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #cc00cc;">#futurebox07</span> <span style="color: #00AA00;">+</span> <span style="color: #6666ff;">.overlay</span> <span style="color: #6666ff;">.inner_content</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">265px</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Each input has their own id so the &#8220;for&#8221; attribute will work on the labels, we can then use that id to target specific modals and change their height.</p>
<h2 class="subtitle02">It&#8217;s an iframe</h2>
<p>Loading static content has a lot of great uses but sometimes only an iframe can handle some situations such as submitting a form within a modal or loading an external resource.</p>
<p>The first iframe example loads up my contact page, feel free contact me, so you can submit a form without affecting the modal or causing a post back on the parent page.</p>
<p>The second iframe loads a Google search for futurebox.</p>
<p>Since iframes are naturally inline placing it inside a label isn&#8217;t invalid and won&#8217;t cause any browser issues.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.overlay</span> iframe
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span>;
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
    -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
    -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
    border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>To give the iframe the same padding and rounded corners as the images and static content modals, we add a few styles to reset the iframes border, add some padding, set the background and apply some border-radius values to give it rounded corners.</p>
<h2 class="subtitle02">Close buttons</h2>
<p>I&#8217;ve also added close buttons on the static and iframe modals, these are purely for show and don&#8217;t technically close the modal since clicking anywhere on the overlay will close the modal. It&#8217;s purely there to give the user the feeling they are actually closing something by clicking a button, rather than the background.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;close&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Close futurebox&quot;</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content01 content02&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">strong</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;closebutton&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Close futurebox&quot;</span>&gt;</span>X<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">strong</span>&gt;</span>
        // content
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span></pre></div></div>

<p>To add the close button I&#8217;ve added a strong tag within the content container. I&#8217;ve just added an X inside to represent the close action and added a title attribute so it makes sense.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.closebutton</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#606061</span>;
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#FFFFFF</span>;
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span>;
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">24px</span>;
    <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">24px</span>;
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span>;
    <span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>;
    <span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-12px</span>;
    <span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span>;
    <span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-12px</span>;
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">24px</span>;
    -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span>;
    -moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span>;
    border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span>;
    -moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#000</span>;
    -webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#000</span>;
    box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#000</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Since we have fixed width content it makes it possible to position it correctly while still keeping the futurebox horizontally centred, that&#8217;s the reason there is no close on the image based modals as the width can vary from image to image. To sit the button to the right of the futurebox I absolutely position it and set top and right to -12px so it will sit slightly offset from the container.</p>
<p>To create the circle effect I set the width and height to 24px and apply a border-radius of 12px for either side which will create our circle.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.closebutton</span><span style="color: #3333ff;"><span style="color: #00AA00;">:</span>hover
</span><span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#318DF2</span>;
        <span style="color: #000000; font-weight: bold;">text-shadow</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #cc00cc;">#ccc</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>When the user hovers over the close button I change the background-color and give the X a light drop shadow.</p>
<h2 class="subtitle02">Mix it up</h2>
<p>We can mix up the styles of the futurebox by adding a class to the parent ul, in the last list example I&#8217;ve added a class to do just that.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.theme01</span> <span style="color: #6666ff;">.overlay</span>
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
<span style="color: #00AA00;">&#125;</span>
    <span style="color: #6666ff;">.theme01</span> <span style="color: #6666ff;">.overlay</span> label <span style="color: #00AA00;">&gt;</span> img<span style="color: #00AA00;">,</span>
    <span style="color: #6666ff;">.theme01</span> <span style="color: #6666ff;">.overlay</span> iframe<span style="color: #00AA00;">,</span>
    theme01 <span style="color: #6666ff;">.content01</span>
    <span style="color: #00AA00;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ccc</span>;
        -moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">,</span> <span style="color: #933;">-5px</span> <span style="color: #933;">-5px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span>;
        -webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">,</span> <span style="color: #933;">-5px</span> <span style="color: #933;">-5px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span>;
        box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span> <span style="color: #933;">5px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">,</span> <span style="color: #933;">-5px</span> <span style="color: #933;">-5px</span> <span style="color: #933;">10px</span> <span style="color: #cc00cc;">#000</span>;
    <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Instead of a semi transparent rgba background, I&#8217;ve reset the background to none and applied a dual box shadow to the overlay items.</p>
<h2 class="subtitle02">Love it, hate it?</h2>
<p>Think it&#8217;s awesome, think it&#8217;s an abomination? Let me know what you think or if you have any suggestions on how you think it could work better make sure to leave a comment.</p>
<p class="shorty01">Short URL: <a href="http://cssn.in/ja/025">http://cssn.in/ja/025</a></p>
<div class="clear">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/css/futurebox3/feed</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Is that a Speedo in your pocket?</title>
		<link>http://www.thecssninja.com/javascript/pocket-speedo</link>
		<comments>http://www.thecssninja.com/javascript/pocket-speedo#comments</comments>
		<pubDate>Sat, 13 Mar 2010 04:11:25 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=623</guid>
		<description><![CDATA[Why yes it is&#8230; I&#8217;ve been sitting on this little idea for a while and as a bit of fun I finally got around to putting it together and properly testing it. Basically on an iPhone with geolocation support (3.0+), I have set up a little web app that will get the speed from the [...]]]></description>
			<content:encoded><![CDATA[<p>Why yes it is&#8230;</p>
<p>I&#8217;ve been sitting on this little idea for a while and as a bit of fun I finally got around to putting it together and properly testing it. Basically on an iPhone with geolocation support (3.0+), I have set up a little web app that will get the speed from the GPS and move the speedometer needle according to your current speed in kilometres.<span id="more-623"></span></p>
<h2 class="subtitle02">But speed returns null?</h2>
<p>When I originally played around with the <a href="http://www.thecssninja.com/javascript/geolocation-iphone">geolocation API on the iPhone</a> checking the speed attribute always returned null, what I failed to actually do was test this value while actually moving. The speed attribute is capable of getting speeds as low as 2km/h so walking with the phone will start to register speeds.</p>
<div class="resources01"><a target="_blank" class="demo" title="Pocket speedo web app" href="http://labs.thecssninja.com/pocket_speedo/">View a live demo</a> <a target="_blank" class="demo source" title="Download the source of the Pocket speedo web app demo" href="http://labs.thecssninja.com/pocket_speedo/pocket_speedo.zip">Download the source files</a></div>
<h2 class="subtitle02">So we can get the speed let&#8217;s use it</h2>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>navigator.<span style="color: #660066;">geolocation</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">getCurrentPosition</span><span style="color: #009900;">&#40;</span>getSpeed<span style="color: #339933;">,</span> handleError<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> getSpeed<span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    updateStats<span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span>;
&nbsp;
    <span style="color: #003366; font-weight: bold;">var</span> coordsListener <span style="color: #339933;">=</span> navigator.<span style="color: #660066;">geolocation</span>.<span style="color: #660066;">watchPosition</span><span style="color: #009900;">&#40;</span>updateStats<span style="color: #339933;">,</span> handleError<span style="color: #009900;">&#41;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Here we get the current position and upon success tell it to execute the <code>getSpeed</code> function. Inside that function I call another function which does all the hard work which I&#8217;ll explain below, next I call the watchPosition method and pass it the same updateStats function so we can get constant updates from the GPS about our speed and adjust our speedometer needle.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> updateStats<span style="color: #009900;">&#40;</span>pos<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> pos.<span style="color: #660066;">coords</span>.<span style="color: #660066;">speed</span><span style="color: #339933;">,</span>
         speedVariation <span style="color: #339933;">=</span> <span style="color: #CC0000;">3.6</span><span style="color: #339933;">,</span>
         currentSpeed <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>speed<span style="color: #339933;">*</span>speedVariation<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         angleVariation <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.8</span><span style="color: #339933;">,</span>
         initSpeedAngle <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">105</span><span style="color: #339933;">,</span>
         speedAngle <span style="color: #339933;">=</span> initSpeedAngle <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>currentSpeed <span style="color: #339933;">*</span> angleVariation<span style="color: #009900;">&#41;</span>;
&nbsp;
    needle.<span style="color: #660066;">style</span>.<span style="color: #660066;">webkitTransitionDuration</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'500ms'</span>;
    needle.<span style="color: #660066;">style</span>.<span style="color: #660066;">webkitTransform</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rotate(&quot;</span> <span style="color: #339933;">+</span> speedAngle <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;deg)&quot;</span>;
    speedVal.<span style="color: #660066;">textContent</span> <span style="color: #339933;">=</span> currentSpeed <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;km/h&quot;</span>;
<span style="color: #009900;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> speed <span style="color: #339933;">=</span> pos.<span style="color: #660066;">coords</span>.<span style="color: #660066;">speed</span><span style="color: #339933;">,</span>
     speedVariation <span style="color: #339933;">=</span> <span style="color: #CC0000;">3.6</span><span style="color: #339933;">,</span>
     currentSpeed <span style="color: #339933;">=</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>speed<span style="color: #339933;">*</span>speedVariation<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>When I get my initial position and my subsequent position updates through the watchPosition method, I access the current speed, in metres, through the coords attribute. To work out the rough speed I times the speed by the speedVariation var which is 3.6 which will give me the speed in km/h, for miles/hour the variation is 2.237. I do this calculation inside the Math.round function so I get a whole rounded number with no decimal places.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> angleVariation <span style="color: #339933;">=</span> <span style="color: #CC0000;">0.8</span><span style="color: #339933;">,</span>
     initSpeedAngle <span style="color: #339933;">=</span> <span style="color: #339933;">-</span><span style="color: #CC0000;">105</span><span style="color: #339933;">,</span>
     speedAngle <span style="color: #339933;">=</span> initSpeedAngle <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span>currentSpeed <span style="color: #339933;">*</span> angleVariation<span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>To calculate the corresponding angle to the equivalent speed we are currently getting from the GPS I had to work out the angle variation per kilometre. I knew there was 16&deg; between each 20km/h block. The angle variation then could be worked out to be 0.8&deg; per kilometre, I also needed to have the starting angle of 0km/h and that is exactly -105&deg; from our middle point. With those 2 values plus the currentSpeed I could then work out the angle so the speedometer needle could be correctly rotated to the right spot.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">needle.<span style="color: #660066;">style</span>.<span style="color: #660066;">webkitTransitionDuration</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">'500ms'</span>;
needle.<span style="color: #660066;">style</span>.<span style="color: #660066;">webkitTransform</span> <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;rotate(&quot;</span> <span style="color: #339933;">+</span> speedAngle <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;deg)&quot;</span>;
speedVal.<span style="color: #660066;">textContent</span> <span style="color: #339933;">=</span> currentSpeed <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;km/h&quot;</span>;</pre></div></div>

<p>To move the needle when the speed changes and to make that change animate between the two points I use CSS3 transforms and transitions. By setting our <code>-webkit-transition-duration</code> any changes done using the <code>-webkit-transform</code> property will be transitioned smoothly between the current angle and the new angle. The last bit is just to print out the speed so we can compare the needle position to the actual speed being read.</p>
<h2 class="subtitle02">Some CSS3</h2>
<p>I&#8217;ve added some extra CSS3 to the speedo including animations and box-shadow</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #cc00cc;">#dial</span> <span style="color: #cc00cc;">#needle</span>
<span style="color: #00AA00;">&#123;</span>
    -moz-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#ffd712</span><span style="color: #00AA00;">,</span> <span style="color: #933;">-1px</span> <span style="color: #933;">-1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#feb018</span>;
    -webkit-box-shadow<span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#ffd712</span><span style="color: #00AA00;">,</span> <span style="color: #933;">-1px</span> <span style="color: #933;">-1px</span> <span style="color: #933;">3px</span> <span style="color: #cc00cc;">#feb018</span>;
&nbsp;
    -webkit-animation-name<span style="color: #00AA00;">:</span> speedorgo;
    -webkit-animation-duration<span style="color: #00AA00;">:</span> 2s;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>To add the slight glow around speedo needle by using a dual box-shadow so it appears on both edges. The <a href="http://webkit.org/blog/324/css-animation-2/">-webkit-animation-</a> properties allows me to specify a predefined animation that can be applied to different elements.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #a1a100;">@-webkit-keyframes speedorgo {</span>
    <span style="color: #933;">0%</span>   <span style="color: #00AA00;">&#123;</span> -webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-105deg<span style="color: #00AA00;">&#41;</span>; <span style="color: #00AA00;">&#125;</span>
    <span style="color: #933;"><span style="color: #cc66cc;">20</span>%</span>  <span style="color: #00AA00;">&#123;</span> -webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>41deg<span style="color: #00AA00;">&#41;</span>; <span style="color: #00AA00;">&#125;</span>
    <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span> <span style="color: #00AA00;">&#123;</span> -webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>-105deg<span style="color: #00AA00;">&#41;</span>; <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>By using webkits @-webkit-keyframes rule and giving it a unique name which we applied to our speedo needle in the previous CSS using the -webkit-animation-name property we can do some pretty cool animations. Inside this animation rule I set up the animation to rotate any element it&#8217;s applied to to go from -105&deg; to 41&deg; then back to -105&deg; when you rotate the phone into landscape mode it&#8217;ll trigger the animation and do the animation over a 2 second period.</p>
<h2 class="subtitle02">Pfft! Who needs the internet&#8230;</h2>
<p>Well technically we initially need the internet but after we load the web app for the first time no connection is required for this to work. By taking advantage of the <a href="http://www.thecssninja.com/javascript/how-to-create-offline-webapps-on-the-iphone">application cache</a> we can store all our assets on the phone, and since the GPS can still work without a network connection the speedo will still function fine.</p>
<h2 class="subtitle02">A clear sky</h2>
<p>In order to pick up a consistent speed reading from the GPS you will need to have the phone with a good clear view of the sky. I&#8217;ve found when using it while walking the speed reading will fluctuate quite a lot, going from 0 to the actual speed your doing and back to 0 and back up etc. It becomes more reliable the faster you are moving. I&#8217;m sure with some adjustments to the code getting a more consistent speed reading will be possible.</p>
<h2 class="subtitle02">Go forth and hack</h2>
<p>We have a fun little tech demo that shows what can with some simple JavaScript and CSS3. I don&#8217;t see why this couldn&#8217;t work on an Android, Palm Pre or a Blackberry with the new webkit browser, all of these should or should very soon support the features required for the web app to work. If you get this working in any other smart phone please leave a comment.</p>
<p class="shorty01">Short URL: <a href="http://cssn.in/ja/024">http://cssn.in/ja/024</a></p>
<div class="clear">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/javascript/pocket-speedo/feed</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Custom radio and checkbox inputs using CSS</title>
		<link>http://www.thecssninja.com/css/custom-inputs-using-css</link>
		<comments>http://www.thecssninja.com/css/custom-inputs-using-css#comments</comments>
		<pubDate>Fri, 19 Feb 2010 05:13:08 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[selectors]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=598</guid>
		<description><![CDATA[In my never ending quest to find weird and wonderful ways to abuse CSS and all its little intricacies, I have come up with a pretty good way of using CSS to create custom radio and checkbox inputs without JavaScript, that are accessible, keyboard controlled, don&#8217;t use any hacks and degrade nicely in non supporting [...]]]></description>
			<content:encoded><![CDATA[<p>In my never ending quest to find weird and wonderful ways to abuse CSS and all its little intricacies, I have come up with a pretty good way of using CSS to create custom radio and checkbox inputs without JavaScript, that are accessible, keyboard controlled, don&#8217;t use any hacks and degrade nicely in non supporting browsers. The journey wasn&#8217;t easy and I was on the brink of filing it in the &#8220;to crazy&#8221; folder, never to be seen again. Luckily I had a brain wave that paid off and actually allowed this to be a very viable solution that degrades beautifully and works in 80% of the browsers. This is my story.<span id="more-598"></span></p>
<h2 class="subtitle02">It&#8217;s a bug, no it&#8217;s intended&#8230;well actually it&#8217;s still a draft</h2>
<p>So upon my initial investigation of how doing something like this would be possible, I came across what I initially thought was a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=546367">bug with Firefox</a> and IE8. Applying CSS generated content to form elements doesn&#8217;t work, turns out Firefox and IE8 are following the CSS3 draft specification as specified in the <a href="http://www.w3.org/TR/css3-content/">CSS3 Generated and Replaced Content Module</a>.</p>
<blockquote cite="http://www.w3.org/TR/css3-content/#replacedContent"><p>The box model defines different rules for the layout of replaced elements than normal elements. Replaced elements do not have &#8216;<code>::before</code>&#8216; and &#8216;<code>::after</code>&#8216; pseudo-elements;&#8230;</p>
</blockquote>
<p>Form elements fall under the &#8220;replaced elements&#8221; category and therefore don&#8217;t allow <code>:before</code> and <code>:after</code> pseudo-elements on them. However Safari, Chrome and Opera all allow generated content on form elements. Further to the odd behaviour Chrome and Safari will only apply generated content on checkboxes, radios and file inputs whereas Opera will allow it for all form elements, see <a href="http://thecssninja.com/demo/form_generated-content/">test case</a>.</p>
<p>You can see my <a href="http://thecssninja.com/demo/css_custom-forms/fail.html">initial attempt</a> at creating custom radios and checkboxes. This applied the generated content directly to the inputs themselves. Open up the demo in Safari or Chrome to see it working. This presented yet another problem this time with Opera, clicking the radio or checkbox directly would never actually check the box whereas with Chrome and Safari the box would be checked and the custom replacement would change state accordingly. But if you clicked the label, which uses the for attribute to create the relationship to the corresponding input, it would check the input in Opera and change the custom check state correctly.</p>
<p>I then thought I would see if I could fix it by using some JavaScript to check the input <code>onclick</code>, this worked for Opera but stopped it working in Chrome and Safari as it was putting it in an indefinite indeterminate state, as it was checked then quickly unchecked by the JavaScript.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">document.<span style="color: #660066;">body</span>.<span style="color: #660066;">onclick</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #003366; font-weight: bold;">var</span> node <span style="color: #339933;">=</span> evt.<span style="color: #660066;">target</span>;
&nbsp;
    <span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>node.<span style="color: #660066;">nodeName</span> <span style="color: #339933;">===</span> <span style="color: #3366CC;">&quot;INPUT&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003366; font-weight: bold;">var</span> isChecked <span style="color: #339933;">=</span> node.<span style="color: #660066;">checked</span>;
        <span style="color: #009900;">&#40;</span>isChecked<span style="color: #009900;">&#41;</span> <span style="color: #339933;">?</span>
            isChecked <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">false</span> <span style="color: #339933;">:</span>
	    isChecked <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">true</span>;
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>As there was no safe obvious way that didn&#8217;t involve browser sniffing or using bad object detection to determine if the browser behaved in this way. And the fact it was taking away from the whole point of this demo, to create a CSS only solution for custom forms, I scrapped my idea and went back to the drawing board.</p>
<h2 class="subtitle02">Selectors, pseudo-classes &amp; pseudo-elements</h2>
<div class="resources01"><a href="http://www.thecssninja.com/demo/css_custom-forms/" title="Custom radio and checkbox inputs demonstration" class="demo" target="_blank">View live demo</a> <a href="http://www.thecssninja.com/demo/css_custom-forms/css_custom-forms.zip" title="Download the source of the web custom radio and checkbox inputs demo" class="demo source" target="_blank">Download the source files</a></div>
<p>As you can see from the demo each radio and checkbox is replaced with a custom one. The difference here from my initial attempt, and to get around the fact you can&#8217;t apply generated content to form elements consistently, is to apply the generated content to the label rather than the input itself, and using some clever selectors I can determine the state of the radio/checkbox is in and adjust the custom replaced one accordingly. I also set the original input opacity to 0 so it won&#8217;t show through our custom one.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;male&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;male&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gender&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;male&quot;</span>&gt;</span>Male<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span></pre></div></div>

<p><small class="caption01">The HTML isn&#8217;t bloated and needs no extra mark-up</small></p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input <span style="color: #00AA00;">+</span> label
<span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">gr_custom-inputs.png</span><span style="color: #00AA00;">&#41;</span> 0 <span style="color: #933;">-1px</span> <span style="color: #993333;">no-repeat</span>;
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span>;
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> 0 0 0 <span style="color: #933;">18px</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Basically this selector is looking for a label that is immediately preceded by a sibling input, that is a child of a paragraph that doesn&#8217;t have an id of foo and <del datetime="2010-03-12T01:40:46+00:00">lastly it has the <code>:before</code> pseudo-element so we can add our custom radio input.</del> The reason for the not selector is to <strong>not</strong> apply these styles in IE8, I&#8217;ll explain why further down.</p>
<p><del datetime="2010-03-12T01:40:46+00:00"><strong id="sprite">Update:</strong> Thanks to <a href="#comment-1182">Lea</a> and <a href="#comment-1184">Mr.MoOx</a> for their suggestions this now uses a sprite image. Rather than insert the image in the <code>content</code> property, I apply a background and insert 3 non-breaking space characters, since the content property doesn&#8217;t accept named entities I used the unicode equivalent of <code>\00a0</code>. The reason I insert 3 is because Firefox 1.5 won&#8217;t show the full background unless I put 3 in there and using a fullstop and applying <code>color: transparent</code> doesn&#8217;t work in FF 1.5.</del></p>
<p><del datetime="2010-03-12T01:40:46+00:00">To get this working in older browsers such as Firefox 3 and down I use a negative margin to get it to sit in the right place. Support for absolutely positioned generated content was only recently added in Firefox 3.5+. I then adjust the newer browsers by offsetting the left value to be equivalent of the left margin.</del></p>
<p><strong id="nogeneratedcontent">Update 2:</strong> Thanks to <a href="#comment-1272">Marius</a> for demonstrating that the :before pseudo-element is superfluous and adding the background directly to the label itself with a few adjustments works just fine and removes the hacky need for using the content property with 3 non-breaking space.</p>
<p>I moved the previous <a href="http://www.thecssninja.com/demo/css_custom-forms/legacy/" target="_blank" title="Legacy demo that uses CSS generated content">demo</a> and it&#8217;s <a href="http://www.thecssninja.com/demo/css_custom-forms/legacy/css_custom-forms.zip" target="_blank" title="Legacy source files for demo that uses CSS generated content">source files</a> to a legacy folder so you can still get them if you want.</p>
<p>Now all the radios have been replaced by our custom versions we need to be able to tell if the radio is checked so we can adjust our custom state.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-241px</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Again this is the same as the previous selector with one difference, we add the <code>:checked</code> pseudo-class available in the <a href="http://www.w3.org/TR/css3-selectors/#checked">CSS3 selectors module</a> to determine the radios state in CSS and change it upon the user checking the radio.</p>
<p>Of course the control doesn&#8217;t end there we also utilise the <code>:hover</code>, <code>:focus</code>, <code>:active</code> &#038; <code>:disabled</code> pseudo-classes to change the radio on hover, when it has focus (for keyboard support), when the input is active (click and hold your mouse cursor to see this state change) and when it&#8217;s disabled. Mixing this with the <code>:checked</code> pseudo-class lets us control all possible states of the radio input and gives us great control and flexibility that doesn&#8217;t require a mouse nor JavaScript to control the states.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:focus </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">+</span> label<span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-181px</span>; 
<span style="color: #00AA00;">&#125;</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:hover</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:focus</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #3333ff;">:hover  </span><span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-261px</span>;
 <span style="color: #00AA00;">&#125;</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:disabled </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:hover</span><span style="color: #3333ff;">:disabled </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:focus</span><span style="color: #3333ff;">:disabled </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:disabled </span><span style="color: #00AA00;">+</span> label<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:disabled </span><span style="color: #00AA00;">+</span> label<span style="color: #3333ff;">:hover</span><span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-221px</span>; 
<span style="color: #00AA00;">&#125;</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:disabled</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:hover</span><span style="color: #3333ff;">:disabled</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:focus</span><span style="color: #3333ff;">:disabled</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:disabled</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #3333ff;">:hover</span><span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:disabled</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #3333ff;">:hover</span><span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-301px</span>; 
<span style="color: #00AA00;">&#125;</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:active </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">+</span> label<span style="color: #3333ff;">:hover</span><span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-201px</span>; 
<span style="color: #00AA00;">&#125;</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:active</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #00AA00;">,</span>
p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>radio<span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> label<span style="color: #3333ff;">:hover</span><span style="color: #3333ff;">:active </span><span style="color: #00AA00;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">background-position</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-281px</span>; 
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Another addition I have made to the CSS is also changing the input states when the user hovers, clicks or focuses on the label it will now change the input to reflect those actions. </p>
<h2 class="subtitle02">IE8 is almost there</h2>
<p>IE8 can do everything, except it doesn&#8217;t support the <code>:checked</code> pseudo-class and therefore makes this technique useless. So I use the <code>not()</code> pseudo-class, which IE8 doesn&#8217;t support, to work around this unfortunate lack of ability. Let&#8217;s hope IE9 adds the CSS3 selector module<sup>1</sup>. This of course degrades nicely in non-supporting browsers and fallback to the browser default form elements.</p>
<p><sup>1</sup> IE9 does support the CSS3 selector module so this technique has across the board support for all major browsers.</p>
<h2 class="subtitle02">Accessible and friendly</h2>
<p><del datetime="2010-03-12T01:40:46+00:00">CSS generated content doesn&#8217;t get in the way of a screen reader and they have a clear view of the form elements</del> CSS generated content is no longer used it&#8217;s now a background image on the label rather than doing it on the generated content <a href="#nogeneratedcontent" title="The need for CSS generated content is no longer needed see update for further details">see update</a> (I would appreciate any accessibility experts or screen reader users to please comment to correct or agree with me). Users, who have trouble operating a mouse or, like me, prefer navigating forms with the keyboard as it&#8217;s faster, aren&#8217;t left out. Tabbing through the inputs changes the states, pressing spacebar to check a radio or checkbox also changes the state. I also change the label colour and give it a text-shadow to give a nicer indication that the current input has focus.</p>
<p>The disabled and checked attributes work as intended with this solution and don&#8217;t require any trickery to achieve that.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">disabled</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;male&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;male&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gender&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;male&quot;</span>&gt;</span>Male<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;radio&quot;</span> <span style="color: #000066;">checked</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Female&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;female&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gender&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;female&quot;</span>&gt;</span>Female<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span></pre></div></div>

<p>As you can see from the above mark-up adding the disabled or checked attributes (disabled=&#8221;disabled&#8221; &#038; checked=&#8221;checked&#8221; also work) will allow us to target those states using the <code>:checked</code> and <code>:disabled</code> pseudo-classes. As well as change the style if we use JavaScript to disable any inputs based on users actions.</p>
<h2 class="subtitle02">Browser support and notes</h2>
<p>As of writing the following browsers have been tested and known to work with the demo:</p>
<ul>
<li>Firefox 1.5+</li>
<li>Opera 9.6+</li>
<li>Safari 3.2+*</li>
<li>iPhone/iPod Safari**</li>
<li>Chrome 4+</li>
<li>IE9+</li>
</ul>
<p>Will run this demo through browsershots and update it accordingly if the browser support works in any lower versions mentioned</p>
<p>* This would work in Safari 3.2 except due to a <a href="https://bugs.webkit.org/show_bug.cgi?id=17680">bug</a>. The checked pseudo-class will work just fine if it has the checked attribute on the input but won&#8217;t change the input state if the user checks the input with their mouse or keyboard (the actual input will check but the CSS state won&#8217;t update the custom input image).</p>
<p>* This now works in Safari 3.2 but, and a big but, the behaviour is quite bizarre. Clicking a radio or checkbox will change the custom state but clicking it again to uncheck won’t show until you have hovered away from or taken focus away from the input. If you have Safari 3.2 installed try the new demo to get a better understanding of what’s happening.</p>
<p>** <del datetime="2010-03-12T01:40:46+00:00">To get the iPhone to work with this demo I had to apply the <a href="https://developer.mozilla.org/en/CSS/pointer-events"><code>pointer-events</code></a> CSS property.</del> Since the input is actually sitting on top of the background image we no longer need to apply pointer events to the label.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">p<span style="color: #00AA00;">:</span>not<span style="color: #00AA00;">&#40;</span><span style="color: #cc00cc;">#foo</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&gt;</span> input <span style="color: #00AA00;">+</span> label
<span style="color: #00AA00;">&#123;</span>
    pointer-events<span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p><small class="caption01">Here for legacy reasons no longer needed for iPhone support</small></p>
<p><del datetime="2010-03-12T01:40:46+00:00">Since having the generated content sit over the top of the actual checkbox, iPhone Safari needed a kick up the bum with the <code>pointer-events</code> property so we could click through the custom checkbox to the actual checkbox. Desktop Safari works fine without it.</del></p>
<h2 class="subtitle02">Drawbacks</h2>
<p>Resolved <a href="#sprite">see update above</a>. <del datetime="2010-02-20T05:37:40+00:00">This technique has only 1 drawback I can think of, IE support is not a drawback for me, you can&#8217;t use a big sprite image to save all the radio and checkbox states, they need to be individual images. Using CSS generated content to insert an image doesn&#8217;t give you control of the image position like a background image does. The images are small in size and the initial load of each state shouldn&#8217;t be noticed. If however you wish to preload all the images take a look at my CSS based <a href="http://www.thecssninja.com/css/even-better-image-preloading-with-css2">image preload technique</a>. That technique will create quite a few http request depending on how many images you preload but since they&#8217;re small in size it shouldn&#8217;t be a major concern.</del></p>
<p class="shorty01">Short URL: <a href="http://cssn.in/ja/023">http://cssn.in/ja/023</a></p>
<div class="clear">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/css/custom-inputs-using-css/feed</wfw:commentRss>
		<slash:comments>67</slash:comments>
		</item>
		<item>
		<title>Even better image preloading with CSS2</title>
		<link>http://www.thecssninja.com/css/even-better-image-preloading-with-css2</link>
		<comments>http://www.thecssninja.com/css/even-better-image-preloading-with-css2#comments</comments>
		<pubDate>Tue, 05 Jan 2010 08:35:17 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=566</guid>
		<description><![CDATA[Recently I read an article on better image preloading using CSS3 which presented a clever idea using CSS3 multiple background images to preload images on one element as opposed to another method of having containers for each image. As of writing the support for multiple backgrounds is fairly sparse with webkit having the best support [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I read an article on <a href="http://perishablepress.com/press/2010/01/04/preload-images-css3/">better image preloading using CSS3</a> which presented a clever idea using CSS3 <a href="http://www.w3.org/TR/2009/CR-css3-background-20091217/#layering">multiple background images</a> to preload images on one element as opposed to another method of having containers for each image. As of writing the support for multiple backgrounds is fairly sparse with webkit having the best support (Safari 3+ &#038; Chrome 1+), Firefox is introducing this in the upcoming 3.6 release.<br />
<span id="more-566"></span></p>
<div class="clear"> </div>
<h2 class="subtitle02">There&#8217;s a better way</h2>
<p>The article instantly got me thinking on a potential alternate method to accomplish the same task, but using a widely available CSS2.1 property. Which if possible will up the browser support significantly. Thankfully the idea actually worked.</p>
<div class="resources01"><a href="http://www.thecssninja.com/demo/css_preload/" title="Preload images using CSS" class="demo" target="_blank">View a live demo</a> <a href="http://www.thecssninja.com/demo/css_preload/css_preload.zip" title="Download the source of the CSS preload demo" class="demo source" target="_blank">Download the source files</a></div>
<h2 class="subtitle02">CSS generated content</h2>
<p>In CSS2 a <a href="http://www.w3.org/TR/CSS2/generate.html#content">content property</a> was introduced, which in conjunction with the <a href="http://www.w3.org/TR/CSS2/generate.html#before-after-content"><em>:before</em> and <em>:after</em></a> pseudo-elements allows us to generate content in a document. The most interesting value that can be used with the content property is <em>url()</em> which allows us to pass an image.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>img01.jpg<span style="color: #00AA00;">&#41;</span>;</pre></div></div>

<p>That&#8217;s all great than we can add a single preloaded image using the content property but what about multiple images? That&#8217;s where the content property shows its true power, we can pass multiple url&#8217;s.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>img01.jpg<span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>img02.jpg<span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>img02.jpg<span style="color: #00AA00;">&#41;</span></pre></div></div>

<p>Brilliant, we can now preload multiple images using one line of CSS. We have all the benefits of the CSS3 method without the CSS3 and the Browser support grows exponentially.</p>
<ul>
<li>IE8+</li>
<li>FF2+</li>
<li>Safari 3+</li>
<li>Chrome 1+</li>
<li>Opera 9.62+</li>
</ul>
<h2 class="subtitle02">Putting it all together</h2>
<p>Now we know how to preload multiple images using CSS2, lets put it all together:</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">body<span style="color: #3333ff;"><span style="color: #00AA00;">:</span>after
</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>img01.jpg<span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>img02.jpg<span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>img03.jpg<span style="color: #00AA00;">&#41;</span>;
<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Instead of creating an empty div with a class on it, we can utilise the requirement of the :after (or :before) pseudo-element. This needs to be there for the content property to work. We apply it to generate the content after the body tag and then set it to <em>display: none</em>, that way the preloaded images aren&#8217;t shown but are still loaded. We know have a pure CSS solution that requires no mark-up.</p>
<h2 class="subtitle02">Almost perfect</h2>
<p>IE6 and 7 do not support CSS generated content and therefore will not preload any images, but that&#8217;s a minor trade off. Users of IE6/7 will just have to load the images when they are called rather than getting them from the cache. </p>
<p>A possible work around for their lack of support is to use <a href="http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx">conditional comments</a> to load the images. This solution will require extra mark-up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/css/even-better-image-preloading-with-css2/feed</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Futurebox, revisited</title>
		<link>http://www.thecssninja.com/css/futurebox2</link>
		<comments>http://www.thecssninja.com/css/futurebox2#comments</comments>
		<pubDate>Sat, 19 Dec 2009 05:12:01 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=523</guid>
		<description><![CDATA[Earlier this year I unleashed futurebox into the wild. It got a whole lot more attention than I anticipated and I got some great feedback. Since then, I have been slowly working on a new version of futurebox which incorporates many new features. &#160; Images are lazy loaded so they are only called when the [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this year I unleashed <a href="http://www.thecssninja.com/xhtml/futurebox">futurebox</a> into the wild. It got a whole lot more attention than I anticipated and I got some great feedback. Since then, I have been slowly working on a new version of futurebox which incorporates many new features.<span id="more-523"></span>
<div class="clear">&nbsp;</div>
<ul>
<li>Images are lazy loaded so they are only called when the futurebox overlay is activated.</li>
<li>You can scroll through using next/previous buttons</li>
<li>Use the keyboard to activate or close futurebox. Overlays can be opened in any order using the keyboard.</li>
<li>Generated content for image description and counters</li>
<li>CSS transitions for webkit browsers</li>
</ul>
<div class="cf_info failure" id="usermessagea">
<p><strong>Update:</strong> A new take on futurebox that doesn&#8217;t use the target pseudo-class. <a href="http://www.thecssninja.com/css/futurebox3">Futurebox v3</a>.</p>
</div>
<div class="resources01"><a target="_blank" class="demo" title="Futurebox, lightbox without the javascript" href="http://www.thecssninja.com/demo/futurebox/revisited/">View a live demo</a> <a target="_blank" class="demo source" title="Download the source of the Futurebox demo" href="http://www.thecssninja.com/demo/futurebox/revisited/futurebox2.zip">Download the source files</a></div>
<h2 class="subtitle02">It&#8217;s back with a vengeance</h2>
<p>The overall markup hasn&#8217;t been altered all that much compared to the original it just adds useful functionality.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ul</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;overlay_container&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;overlay&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;futurebox_img2&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#close&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Close future box&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Image description goes here&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#futurebox_img1&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prev&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Previous&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;lt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#futurebox_img3&quot;</span> <span style="color: #000066;">accesskey</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;next&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Next&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ul</span>&gt;</span></pre></div></div>

<p>The anchor tag is now empty as we load the image as a background. A paragraph tag containing our next and previous links along with a title attribute so we can give the image a small description. The rest of the markup and foundation CSS stays pretty much the same.</p>
<p>Due to the complex nature of this updated version browser support is not a great as the original version. I will run this through a <a href="http://browsershots.org/websites/2790502/">browser screenshot service</a> and confirm browser support. If you come across any weird behaviour please make a comment about it.</p>
<h2 class="subtitle02">Lazy loading images</h2>
<p>In the <a href="http://www.thecssninja.com/demo/futurebox/">original demo</a> the images were loaded in the page essentially slowing down the load time. I&#8217;ve fixed that by using a lazy load technique, rather than having an &lt;img&gt; tag I set a background on the overlay anchor tag. The image is only downloaded when the user clicks on a thumbnail.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.overlay</span><span style="color: #3333ff;">:target </span><span style="color: #00AA00;">&gt;</span> a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">gr_cssninja_lrg.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span> <span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span> <span style="color: #993333;">no-repeat</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>We use the <em>#futurebox_img2.overlay</em> selector for all other overlays to target each item so we can change the background image correspondingly.</p>
<h2 class="subtitle02">Scroll through images</h2>
<p>I have added ability to scroll forwards and backwards through the images using buttons. These form part of the markup in each overlay item essentially just applying the previous images id in the href and the same for the next button.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#futurebox_img1&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prev&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Previous&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;lt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#futurebox_img3&quot;</span> <span style="color: #000066;">accesskey</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;next&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Next&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<p>On each next/previous link we use the <em>rel</em> attribute so we can target it in CSS using attribute selectors</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.overlay</span> <span style="color: #00AA00;">&gt;</span> p a<span style="color: #00AA00;">,</span>
<span style="color: #6666ff;">.overlay</span> <span style="color: #00AA00;">&gt;</span> p a<span style="color: #00AA00;">&#91;</span>rel<span style="color: #00AA00;">=</span>next<span style="color: #00AA00;">&#93;</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/* styles here */</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.overlay</span> <span style="color: #00AA00;">&gt;</span> p a<span style="color: #00AA00;">&#91;</span>rel<span style="color: #00AA00;">=</span>prev<span style="color: #00AA00;">&#93;</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/* styles here */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2 class="subtitle02">Keyboard navigation</h2>
<p>Along with navigation buttons to scroll through the images you can use the keyboard to scroll through in any order. Closing futurebox is also possible using the keyboard. This is done using accesskeys and controls vary in different browsers and platforms.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#futurebox_img3&quot;</span> <span style="color: #000066;">accesskey</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;3&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;next&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Next&quot;</span>&gt;</span><span style="color: #ddbb00;">&amp;gt;</span><span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div>

<p>Using the numbers you can scroll through up to 10 images using the 0-9 numbers and the corresponding keyboard combination in your browser:</p>
<ul>
<li>Firefox Windows: Alt + Shift + 0-9</li>
<li>Safari/Chrome Windows: Alt + 0-9</li>
<li>Opera Windows: Shift + Esc (This brings up a menu where you press the accesskey you wish to activate)</li>
</ul>
<p>To close futurebox the access key is <strong>x</strong>. If you know of any other keyboard combinations, especially the Mac equivalents, I&#8217;ll update the article.</p>
<h2 class="subtitle02">CSS generated content</h2>
<p>It is now also possible to add a small description below each image using the CSS <a href="http://www.w3.org/TR/CSS2/generate.html#content">content property</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.overlay</span> <span style="color: #00AA00;">&gt;</span> a <span style="color: #00AA00;">+</span> p<span style="color: #3333ff;"><span style="color: #00AA00;">:</span>after
</span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">content</span><span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;No. &quot;</span> counter<span style="color: #00AA00;">&#40;</span>futurebox<span style="color: #00AA00;">&#41;</span> <span style="color: #ff0000;">&quot; &quot;</span> attr<span style="color: #00AA00;">&#40;</span>title<span style="color: #00AA00;">&#41;</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>That snippet will get the paragraph tag that is a direct sibling of the anchor tag that is a direct child of the overlay class. Using the <em>:after</em> pseudo-element is how we can append the content after the paragraph.</p>
<p>We also use generated content to do automatic numbering of each image using the <a href="http://www.w3.org/TR/CSS2/generate.html#counters">counter-reset and counter-increment</a> properties in conjunction with the <em>counter()</em> function used in the <em>content</em> property.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.overlay_container</span> 	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">counter-reset</span><span style="color: #00AA00;">:</span> futurebox; <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.overlay_container</span> <span style="color: #00AA00;">&gt;</span> li 	<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">counter-increment</span><span style="color: #00AA00;">:</span> futurebox; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>We first reset the counter so we know it will start from 1, we also give it a unique name e.g. futurebox but this can be anything. Then in the following line we increment the counter for each list item inside the <em>overlay_container</em>, we use the child selector to make sure it only counts top level list items. The counter increment idea came from this blog post about doing a <a href="http://habrahabr.ru/blogs/css/66120/">css based gallery</a> (it&#8217;s in Russian so you&#8217;ll need to run it through a translator).</p>
<h2 class="subtitle02">Animation without the JavaScript</h2>
<p>One of the most requested features for futurebox was using webkits CSS transitions property to animate scrolling between images. So in this version I have added fading between image overlays. In Chrome and Safari we animate the opacity of the image so it will fade in upon activation.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.overlay</span> a
<span style="color: #00AA00;">&#123;</span>
	opacity<span style="color: #00AA00;">:</span> 0;
	-webkit-transition<span style="color: #00AA00;">:</span> opacity 1s ease;
<span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.overlay</span><span style="color: #3333ff;">:hover </span>a <span style="color: #00AA00;">&#123;</span> opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>To setup the transition we set the opacity to 0 and tell the transition to ease the opacity over 1 second. The reason I activate the transition on <em>:hover</em> and not <em>:target</em> is that target will not transition upon activation, whether this is a bug will take some further investigation.</p>
<p>To stop issues in browsers that don’t support transitions. I wrapped the transition styles in a media query.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #a1a100;">@media (-webkit-transition) {</span>
	<span style="color: #808080; font-style: italic;">/* Styles here */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This will only target webkit browsers that support the <em>-webkit-transition</em> property. When Firefox &#038; Opera add support for transitions hopefully they will add support for this media query.</p>
<p>Another issue with transitions is hover will fail to activate if you launch futurebox using the keyboard, moving your mouse will then trigger the transition to execute. Only the initial launch is affected using the keyboard to scroll through other images will trigger the transition correctly.</p>
<h2 class="subtitle02">Some things to note</h2>
<p>While this does have good browser support it won&#8217;t work in IE and I don&#8217;t see it working without considerable use of hacks. There is however a fantastic article over at Carsonified on <a href="http://carsonified.com/blog/design/css/how-to-create-a-valid-non-javascript-lightbox/">creating a lighbox effect that works in IE</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/css/futurebox2/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create the accordion effect using CSS3</title>
		<link>http://www.thecssninja.com/css/accordian-effect-using-css</link>
		<comments>http://www.thecssninja.com/css/accordian-effect-using-css#comments</comments>
		<pubDate>Wed, 05 Aug 2009 13:26:25 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[animation]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[webkit]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=407</guid>
		<description><![CDATA[Recently I have been playing around with CSS transitions and animations as implemented in webkit based browsers such as Safari and Chrome. They have been submitted to the W3C for consideration in the CSS3 spec so hopefully we should see more browsers support this soon, Firefox 3.5 supports CSS transforms which was developed by the [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I have been playing around with <a href="http://webkit.org/blog/324/css-animation-2/">CSS transitions and animations</a> as implemented in webkit based browsers such as Safari and Chrome. They have been submitted to the W3C for consideration in the <a href="http://www.w3.org/TR/css3-transitions/">CSS3 spec</a> so hopefully we should see more browsers support this soon, Firefox 3.5 supports <a href="https://developer.mozilla.org/En/CSS/Using_CSS_transforms">CSS transforms</a> which was developed by the webkit people to work alongside CSS animations &#038; transitions.<span id="more-407"></span></p>
<p>To continue my effort to accomplish tasks in CSS that are usually reserved for JavaScript, such as my <a href="http://www.thecssninja.com/xhtml/futurebox">Futurebox</a> and <a href="http://www.thecssninja.com/css/iphone-orientation-css">CSS based iPhone orientation detection</a>. I have developed a CSS based version of the popular <a href="http://tutorialblog.org/10-javascript-accordion-scripts/">&#8220;accordion effect&#8221;</a> that utilises the webkit CSS transitions. Like the <a href="http://www.thecssninja.com/demo/futurebox/">Futurebox demo</a> I&#8217;m utilising the CSS3 <a href="http://www.w3.org/TR/css3-selectors/#target-pseudo"><em>:target</em></a> pseudo class to know which item to show based the URI fragment identifier (the # in the url).</p>
<div class="resources01"><a target="_blank" class="demo" title="Accordion effect using CSS3" href="http://www.thecssninja.com/demo/css_accordion/">View a live demo</a> <a target="_blank" class="demo source" title="Download the source of the CSS accordion demo" href="http://www.thecssninja.com/demo/css_accordion/css_accordion.zip">Download the source files</a></div>
<p>It should be noted that this works best in a webkit based browser such as Safari 3+, Chrome or iPhone. Other browsers that support the <em>:target</em> pseudo class will still function on the core level but won&#8217;t animate the showing and hiding. The following browsers have been tested and work with this demo.</p>
<ul>
<li>Firefox 1.5+</li>
<li>Opera 9.6+</li>
<li>Safari 3+</li>
<li>Chrome 1+</li>
<li>IE6+ &#8211; <a href="#ie-solution">IE solution</a></li>
</ul>
<h2 class="subtitle02">The xhtml</h2>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">dl</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">dt</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#Section1&quot;</span>&gt;</span>Section 1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">dt</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Section1&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			Lorem ipsum dolor sit amet...
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">dd</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">dt</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#Section2&quot;</span>&gt;</span>Section 2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">dt</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Section2&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			Lorem ipsum dolor sit amet...
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">dd</span>&gt;</span>
	...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">dl</span>&gt;</span></pre></div></div>

<p>We setup the accordion using a <a href="http://www.w3.org/MarkUp/html3/deflists.html">definition list</a> to create the foundation so we can show and hide the definition data (dd) tag when the user clicks the anchor link inside the definition title (dt) tag.</p>
<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">dl
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
	<span style="color: #000000; font-weight: bold;">min-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">960px</span>;
<span style="color: #00AA00;">&#125;</span>
	dl dt
	<span style="color: #00AA00;">&#123;</span>
		-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span>;
		-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">5px</span>;
		<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#cccccc</span>;
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 0;
	<span style="color: #00AA00;">&#125;</span>
		dl dt a
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span>;
			<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span>;
			<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
			<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
			<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
		<span style="color: #00AA00;">&#125;</span>
	dl dd
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 0;
		<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> 0;
		<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span>;
		-webkit-transition<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">height</span> 1s ease;
	<span style="color: #00AA00;">&#125;</span>
		dl dd p
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
			<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 0;
		<span style="color: #00AA00;">&#125;</span>
	dl dd<span style="color: #3333ff;"><span style="color: #00AA00;">:</span>target
	</span><span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span>;
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #a1a100;">@media (-webkit-transition) {</span>
	dl dd<span style="color: #3333ff;"><span style="color: #00AA00;">:</span>target
	</span><span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">6.667em</span>;
	<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Pretty simple CSS involved, the <em>dd</em> tag is hidden by setting the <em>height</em> to 0 and the <em>overflow</em> to hidden.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">-webkit-transition<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">height</span> 1s ease;</pre></div></div>

<p>This property on the <em>dd</em> tag lets webkit browsers know we wish to transition the height value over 1 second period using the <em>ease</em> timing function this transition will only happen when the <em>height</em> of the <em>dd</em> tag is changed. We can also express this in a long hand version.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">-webkit-transition-property<span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">height</span>;
-webkit-transition-duration<span style="color: #00AA00;">:</span> 1s;
-webkit-transition-timing-function<span style="color: #00AA00;">:</span> ease;</pre></div></div>

<p>To change the height we use the <em>:target</em> pseudo class to set the height of the dd tag to auto so the right content will show based the URI fragment identifier. For webkit browsers it&#8217;s a little different.</p>
<h2 class="subtitle02">Webkit media queries</h2>
<p>In webkit browsers there are additional <a href="http://webkit.org/specs/MediaQueriesExtensions.html">media queries available</a> so we can target browsers that support the extended features such as transitions and not affect other browsers. In this demo I use the <em>@media (transition)</em> media query.</p>
<p>Webkit implements this feature by using their -webkit vendor extension so the media query looks like the following</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #a1a100;">@media (-webkit-transition) {</span>
	dl dd<span style="color: #3333ff;"><span style="color: #00AA00;">:</span>target
	</span><span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">6.667em</span>;
	<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Unfortunately setting the height of the <em>dd</em> tag to <em>auto</em> will not make it animate although this would be ideal and much more capable of catering for different sized content it&#8217;s not possible at the moment. For now we have to set the height to an actual value, to keep the height in line with any text resizing I set the height using em based value so if the user has larger text the height will adjust and won&#8217;t cut of any content. The height is 80px we divide by the base font size, which is 12, and we get 6.667em.</p>
<h2 class="subtitle02" id="ie-solution">What about IE</h2>
<p>Unfortunately IE doesn&#8217;t support the <em>:target</em> pseudo class and won&#8217;t work as describe above, but that didn&#8217;t stop me! Take a look at working example that functions in IE6 and up.</p>
<div class="resources01"><a target="_blank" class="demo" title="Accordion effect using CSS that works in IE6+" href="http://www.thecssninja.com/demo/css_accordion/ie_solution.html">View a live demo</a> <a target="_blank" class="demo source" title="Download the source of the CSS IE accordion demo" href="http://www.thecssninja.com/demo/css_accordion/css_accordion_ie.zip">Download the source files</a></div>
<p>This is quite hacky and involves a bit of IE conditional comments.</p>
<h2 class="subtitle02">IE xhtml</h2>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">dl</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--[if IE]&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;a href=&quot;#Section1&quot; class=&quot;ie&quot;&gt;&lt;div&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;![endif]--&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">dt</span>&gt;</span>
		<span style="color: #808080; font-style: italic;">&lt;!--[if !IE]&gt;--&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#Section1&quot;</span>&gt;</span>
				<span style="color: #808080; font-style: italic;">&lt;!--&lt;![endif]--&gt;</span>Section 1<span style="color: #808080; font-style: italic;">&lt;!--[if !IE]&gt;--&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
		<span style="color: #808080; font-style: italic;">&lt;!--&lt;![endif]--&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">dt</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">dd</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Section1&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			Lorem ipsum dolor sit amet...
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">dd</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--[if IE]&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;/div&gt;&lt;/a&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;![endif]--&gt;</span>
	...
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">dl</span>&gt;</span></pre></div></div>

<p>As you can see there is <a href="http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx">conditional comments</a> so I can wrap the <em>dt</em> and <em>dd</em> tag in an anchor so we can get it functioning in IE using the following CSS. I also use the conditional comments to hide the anchor that appears in the <em>dt</em> tag only for IE browsers. IE6 was not functioning with just the anchor around the <em>dd</em> &#038; <em>dt</em> so I added a <em>div</em> inside the anchor. In IE6 the first anchor would surround all the items, the div fixes that. Demo, demo files and example code has been updated to reflect that.</p>
<h2 class="subtitle02">IE CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">dl a<span style="color: #6666ff;">.ie</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>; <span style="color: #00AA00;">&#125;</span>
	dl a<span style="color: #6666ff;">.ie</span> dd <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>; <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Fix IE6 hover bug */</span>
dl a<span style="color: #6666ff;">.ie</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#606061</span> !important; <span style="color: #00AA00;">&#125;</span>
&nbsp;
dl a<span style="color: #6666ff;">.ie</span> dt
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span>;
	<span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span>;
	<span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
dl a<span style="color: #6666ff;">.ie</span><span style="color: #3333ff;">:hover </span>dd<span style="color: #00AA00;">,</span>
dl a<span style="color: #6666ff;">.ie</span><span style="color: #3333ff;">:active </span>dd<span style="color: #00AA00;">,</span>
dl a<span style="color: #6666ff;">.ie</span><span style="color: #3333ff;">:focus </span>dd
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">auto</span>;
	<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#cccccc</span> !important;
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Pretty simple stuff, set the <em>text-decoration</em> so the content isn&#8217;t underlined. We need to hide the <em>dd</em> tag as it causes issues in IE7 and below when trying to hover over any items below the first section. Next a <em>background-color</em> is applied to the <em>:hover</em> pseudo class of the surrounding anchor to fix an issue in IE6 that won&#8217;t trigger a hover unless something like a background-color is applied it. To make it work in IE we utilise the <em>:hover</em>, <em>:focus</em> and <em>:active</em> pseudo classes. That way when the user hovers in IE the content gets revealed, we also simulate a &#8220;click&#8221; by using the <em>:active</em> pseudo class. The :focus pseudo class allows us to make it work by using keyboard navigation, tabbing to the anchor will reveal the content. All the mark-up is XHTML 1.0 Strict complaint.</p>
<p>I think this is a pretty good attempt and best of all it works in all major browser so it can be potentially be used in a production environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/css/accordian-effect-using-css/feed</wfw:commentRss>
		<slash:comments>62</slash:comments>
		</item>
		<item>
		<title>Real text rotation with CSS</title>
		<link>http://www.thecssninja.com/css/real-text-rotation-with-css</link>
		<comments>http://www.thecssninja.com/css/real-text-rotation-with-css#comments</comments>
		<pubDate>Wed, 29 Jul 2009 11:27:22 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[css3]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=388</guid>
		<description><![CDATA[Just saw a great post on Jonathan Snooks&#8217; blog about doing text rotation with CSS and how to accomplish it in IE using IE propriety filter basic image property to rotate a text block. But there is a better way using CSS3 writing-mode property that has been in IE since version 5.5. writing-mode which is [...]]]></description>
			<content:encoded><![CDATA[<p>Just saw a great post on <a href="http://snook.ca/s/952">Jonathan Snooks&#8217; blog</a> about doing text rotation with CSS and how to accomplish it in IE using IE propriety <a href="http://msdn.microsoft.com/en-us/library/ms532918%28VS.85%29.aspx"><em>filter</em> basic image</a> property to rotate a text block. But there is a better way using CSS3 <em>writing-mode</em> property that has been in IE since version 5.5.<span id="more-388"></span></p>
<p><a href="http://www.w3.org/TR/2001/WD-css3-text-20010517/#PrimaryTextAdvanceDirection"><em>writing-mode</em></a> which is currently in the CSS3 draft specification allows us to accomplish text rotation without using propriety properties, effectively future proofing the concept as more browsers adopt the CSS3 draft spec.</p>
<div class="resources01"><a href="http://www.thecssninja.com/demo/css_text-rotation/" title="Simple demo of rotating text with CSS3" class="demo" target="_blank">View a live demo</a><a href="http://www.thecssninja.com/demo/css_text-rotation/css_text-rotation.zip" title="Download the source of the CSS text rotation demo" class="demo source" target="_blank">Download the source files</a></div>
<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">p <span style="color: #00AA00;">&#123;</span> writing-mode<span style="color: #00AA00;">:</span> tb-rl; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>That&#8217;s it incredibly simple CSS technique that will eventually work with all browsers as their CSS3 support gets better. This is one of the handful of CSS3 supported properties in IE. The <em>tb-rl</em> value tells the browser to display paragraphs with the text flowing from top to bottom, right to left. Essentially rotating the text 90 degrees clockwise and aligning to the right.</p>
<p>This properties true intention is for displaying other languages in their correct &#8220;writing mode&#8221; such as Japanese right to left or Arabic &#038; Hebrew which display right to left &#038; top to bottom (<em>rl-tb</em>).</p>
<h2 class="subtitle02">Support</h2>
<p>At the moment IE is the only browser to support it starting from IE5.5 and up, IE8 adds further values through using the <em>-ms</em> extension. There are 4 values available from IE5.5+ and an additional 4 values for IE8+ through the -ms extension.</p>
<ul>
<li>lr-tb &#8211; This is the default value, left to right, top to bottom</li>
<li>rl-tb &#8211; This flows the text from right to left, top to bottom</li>
<li>tb-rl &#8211; Flows the text vertically from top to bottom, right to left</li>
<li>bt-rl &#8211; bottom to top, right to left</li>
<li>tb-lr &#8211; This and the followings value are only available in IE8+ using <em>-ms-writing-mode</em>. Text flows top to bottom, left to right</li>
<li>bt-lr &#8211; Bottom to top, left to right</li>
<li>lr-bt &#8211; Left to right, bottom to top</li>
<li>rl-bt &#8211; Right to left, bottom to top</li>
</ul>
<h2 class="subtitle02">Rotate text in other browsers?</h2>
<p>As stated in Snooks&#8217; article we can do this in Webkit based browsers and Firefox 3.5+ using the <em>transform</em> property.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">-webkit-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>90deg<span style="color: #00AA00;">&#41;</span>; 
-moz-transform<span style="color: #00AA00;">:</span> rotate<span style="color: #00AA00;">&#40;</span>90deg<span style="color: #00AA00;">&#41;</span>;</pre></div></div>

<p>For both we need to use the vendor extensions <em>-moz</em> &#038; <em>-webkit</em>. As for Opera it neither yet supports <em>transforms</em> or <em>writing-mode</em> properties but I&#8217;m sure that will change with the upcoming release of version 10.</p>
<p>In the article example we need to position the element differently for browsers that support the <em>transform</em> property compared to ones that support <em>writing-mode</em> as the elements rotated still exist as horizontal elements where as with <em>writing-mode</em> the element is truly rotated, see screenshot below.</p>
<p><img src="http://www.thecssninja.com/wp-content/uploads/2009/07/gr_css-compare.png" alt="CSS writing-mode on the left and CSS transform on the right" title="CSS writing-mode on the left and CSS transform on the right" width="608" height="156" class="article-img main-img" /><br />
<small class="caption01">Element that is rotated is outlined and highlighted, writing-mode on left transform on right</small></p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.datebox</span> span<span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #00AA00;">&#41;</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span>;
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>To target the browsers that potentially support the <em>transform</em> property we use the CSS3 <em>nth-child()</em> psuedo class.</p>
<p>A pretty cool alternative to an already great idea by <a href="http://snook.ca/">snook</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/css/real-text-rotation-with-css/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Determine iPhone orientation using CSS</title>
		<link>http://www.thecssninja.com/css/iphone-orientation-css</link>
		<comments>http://www.thecssninja.com/css/iphone-orientation-css#comments</comments>
		<pubDate>Mon, 29 Jun 2009 11:08:19 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=321</guid>
		<description><![CDATA[With the beta of Firefox 3.5 showcasing 35 new features over 35 days, the article on CSS3 media queries stuck out, the orientation detection really got my attention and immediately put my thought process to mobile devices, in my case the iPhone. I thought this is great maybe this has been snuck into the iPhone [...]]]></description>
			<content:encoded><![CDATA[<p>With the beta of Firefox 3.5 showcasing <a href="http://hacks.mozilla.org/2009/06/35-days/">35 new features over 35 days</a>, the article on <a href="http://hacks.mozilla.org/2009/06/media-queries/">CSS3 media queries</a> stuck out, the orientation detection really got my attention and immediately put my thought process to mobile devices, in my case the iPhone. I thought this is great maybe this has been snuck into the iPhone 3.0, unfortunately for us it wasn&#8217;t. That didn&#8217;t stop me and I got thinking about how it could be done if at all on the iPhone without using JavaScript.<span id="more-321"></span></p>
<p>Still using the CSS3 media queries we can accomplish orientation detection with only CSS but instead of looking at the unsupported <em>orientation</em> property we can use the <em>min-width</em> and <em>max-width</em> propertities to our advantage to detect what orientation the user is currently in. Load the below demo in your iPhone/iPod Touch to see it in action, rotating the phone will either change the text from &#8220;Portrait&#8221; to &#8220;Landscape&#8221; depending on your orientation respectively.</p>
<div class="resources01"><a href="http://www.thecssninja.com/demo/css_orientation/" title="CSS orientation demo" class="demo" target="_blank">View a live demo</a> <a href="http://www.thecssninja.com/demo/css_orientation/css_orientation.zip" title="Download the source of the css orientation demo" class="demo source" target="_blank">Download the source files</a></div>
<p>Looking in the Apple Developer documentation on <a href="http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/iPhoneWebAppHIG/MetricsLayout/MetricsLayout.html#//apple_ref/doc/uid/TP40007900-CH6-SW1">Human Interface Guidelines (HIG)</a> we can determine the min and max width we need to target to find out the user orientation. Let&#8217;s look at the CSS from the demo to better understand how it works.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">h1
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">table-cell</span>;
	<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">middle</span>;
	<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span>;
<span style="color: #00AA00;">&#125;</span>
	h1 span <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>; <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Portrait */</span>
<span style="color: #a1a100;">@media screen and (max-width: 320px)</span>
<span style="color: #00AA00;">&#123;</span>
	h1 span<span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span>; <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Landscape */</span>
<span style="color: #a1a100;">@media screen and (min-width: 321px)</span>
<span style="color: #00AA00;">&#123;</span>
	h1 span<span style="color: #3333ff;">:nth-</span>child<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">2</span><span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span>; <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>In the demo we have a <em>&lt;h1&gt;</em> set with to <em>display: table-cell</em>, this isn&#8217;t important to the demo but allows me to easily vertically centre the text. Inside the <em>&lt;h1&gt;</em> there are 2 spans which will show or hide depending on what orientation you&#8217;re in, initially we hide both spans. </p>
<p>The next few lines are where we can figure out using only CSS what span to show. To determine if the user is in portrait mode we use the media query <em>@media screen and (max-width: 320px)</em> we know from the <a href="http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/iPhoneWebAppHIG/MetricsLayout/MetricsLayout.html#//apple_ref/doc/uid/TP40007900-CH6-SW1">HIG</a> that <em>320px</em> is the <em>max-width</em> in portrait mode. We do the same for landscape but this time we use <em>min-width</em> and increase the value by 1 so viewport needs to be at least 321px wide before any styles in the media query will be applied. Inside each media query I use the CSS3 <a href="http://www.w3.org/TR/css3-selectors/#nth-child-pseudo">nth-child pseudo class</a> to target an individual span.</p>
<h2 class="subtitle02">Not without issues</h2>
<p>In order for this to work we need to add the viewport meta tag to force the iPhone Safari viewport width to be that of the device, it is usually defaulted to 980.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">meta</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;viewport&quot;</span> <span style="color: #000066;">content</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;width=device-width, minimum-scale=1.0, </span>
<span style="color: #009900;"> maximum-scale=1.0&quot;</span>&gt;</span></pre></div></div>

<p>My original idea was to use the <em>max-device-width</em> and <em>min-device-width</em> properties which would bypass the need for viewport meta tag but unfortunately this doesn&#8217;t work. It may be due to the fact that it will always return a <em>min-width</em> of 320 and a <em>max-width</em> of 480 and therefore wouldn&#8217;t be possible to do it the current way I have devised.</p>
<p>Until the iPhone adds in support for the orientation media query, this technique is quite a capable work around. Of course there are still some things it can&#8217;t do so the <a href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW16">orientation event handler</a> will still be needed for more advanced changes to happen.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/css/iphone-orientation-css/feed</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Futurebox, lightbox without the JavaScript</title>
		<link>http://www.thecssninja.com/xhtml/futurebox</link>
		<comments>http://www.thecssninja.com/xhtml/futurebox#comments</comments>
		<pubDate>Sat, 20 Jun 2009 06:42:04 +0000</pubDate>
		<dc:creator>The Css Ninja</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[css3]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=302</guid>
		<description><![CDATA[I was playing around the other day and had a bright spark. Is it possible to do the &#8220;lightbox&#8221; effect without JavaScript? The answer is yes! Thanks to the :target pseudo class. Without further ado I introduce Futurebox. &#160; View a live demo Download the source files Update: New version of futurebox has been released. [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around the other day and had a bright spark. Is it possible to do the &#8220;lightbox&#8221; effect without JavaScript? The answer is yes! Thanks to the <a href="http://www.w3.org/TR/css3-selectors/#target-pseudo">:target pseudo class</a>. Without further ado I introduce Futurebox.<span id="more-302"></span></p>
<div class="clear">&nbsp;</div>
<div class="resources01"><a href="http://www.thecssninja.com/demo/futurebox/" title="Futurebox, lightbox without the javascript" class="demo" target="_blank">View a live demo</a> <a href="http://www.thecssninja.com/demo/futurebox/futurebox.zip" title="Download the source of the Futurebox demo" class="demo source" target="_blank">Download the source files</a></div>
<div id="usermessagea" class="cf_info failure">
<p><strong>Update:</strong> <a href="http://www.thecssninja.com/css/futurebox2">New version of futurebox</a> has been released.</p>
<p>Have updated the demo so now the entire screen area is clickable to remove the Futurebox. I have also refactored the mark-up so it is a bit leaner. <a href="http://www.thecssninja.com/demo/futurebox/index.old.html">The previous demo can see here</a>. Ran it through <a href="http://browsershots.org/websites/2063258/">Browsershots</a> to see what browsers it works in.</p>
</div>
<h2 class="subtitle02">Futurebox?</h2>
<p>I&#8217;ve aptly called it Futurebox because this is only a proof of concept, it only works in the better browsers but never the less is a cool look at a useful CSS3 technique. The following browsers have been tested and will work with this example, it may also work in earlier versions of the browsers listed but I have not yet tested in them.</p>
<ul>
<li>Firefox 1.5+</li>
<li>Safari 3.2+</li>
<li>Chrome 2+</li>
<li>Opera 9.5+</li>
</ul>
<h2 class="subtitle02">How does it work?</h2>
<p>As mentioned above the whole thing is only possible due to the CSS3 <em>:target</em> pseudo class. It all works by getting the anchor link in a URI which can be referenced in your CSS using <em>:target</em>. If an element has an id that matches the URI the styles applied to it will come into effect. I&#8217;ll break down the above example so we can get a better look.</p>
<h2 class="subtitle02">The xhtml</h2>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#futurebox_img1&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gr_ninja-attack_med.gif&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;100&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;102&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;The CSS Ninja&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;futurebox01&quot;</span> </span>
<span style="color: #009900;">	<span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
&nbsp;
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;overlay&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;futurebox_img1&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#close&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Close future box&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;gr_cssninja_lrg.png&quot;</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">alt</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;The Css Ninja&quot;</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;600&quot;</span> </span>
<span style="color: #009900;">			<span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;639&quot;</span> </span>
<span style="color: #009900;">		<span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p>Pretty simple mark-up we have our thumbnail image which links to an anchor link. The overlay image has the id that we are linking to on the thumbnail. The overlay mark-up has 2 divs around the image to horizontally and vertically centre the image. We have another anchor tag around the large image this is so we can &#8220;close&#8221; the overlay.</p>
<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">html<span style="color: #00AA00;">,</span> body <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span>; <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.overlay</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span>;
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span>;
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>; 
	<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> 0; 
	<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> 0; 
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>; 
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">999</span>;
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> rgba<span style="color: #00AA00;">&#40;</span>0<span style="color: #00AA00;">,</span>0<span style="color: #00AA00;">,</span>0<span style="color: #00AA00;">,</span><span style="color: #cc66cc;">0.7</span><span style="color: #00AA00;">&#41;</span>;
<span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.overlay</span> a
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">table-cell</span>; 
		<span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">middle</span>; 
		<span style="color: #000000; font-weight: bold;">text-align</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">center</span>;
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.overlay_container</span> img
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span>;
			<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
			-webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
			-moz-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.overlay</span><span style="color: #3333ff;">:target </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> table; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The <em>overlay</em> class is <em>position: absolute</em> so it can sit over the content, it is expanded to 100% <em>width</em> and <em>height</em> and has a <em>background: rgba()</em> applied so we get that nice transparent overlay look. Not all browsers support <em>rgba</em> that work with this example, for those no background colour will appear. Initially it is set to <em>display: none</em>.</p>
<p><del datetime="2009-06-21T00:12:59+00:00"><em>overlay_container</em> class</del> The anchor tag has <em>display: table-cell</em> so it will act like a table cell, <em>vertical-align: middle</em> is applied give us the ability to vertically centre anything within this container and finally <em>text-align: center</em> so we can horizontally centre any inline elements. The entire screen is now clickable by styling the anchor this way making it more inline with how lightbox works.</p>
<p>The image has <em>padding</em>, <em>background</em> and for the supporting browsers we set rounded corners using <em>border-radius</em>. Since images are naturally inline elements, we can avoid setting <em>margin: 0 auto</em> and a <em>width</em> on the image to centre it (<em>text-align: center</em> on the previous container handles that for us) making this technique more flexible.</p>
<p>Finally the magic that allows this technique to work is very simple we target the overlay we want to display by using <em>:target</em>, the user clicks a thumbnail which has a link to <em>#futurebox_img1</em> the :target pseudo class will look for any elements with the id of <em>futurebox_img1</em> and set it to <em>display: table</em>, for a more in depth look at the <a href="http://www.thecssninja.com/xhtml/why-display-table-shouldnt-be-frowned-upon" title="Why display: table shouldn't be frowned upon">css table property check out my previous article</a>. We use <em>table</em> rather than <em>block</em> so the styles setup on the <em>overlay_container</em> class will allow us to horizontally &#038; vertically centre the image.</p>
<h2 class="subtitle02">Further reading</h2>
<p>Think Vitamin has a good write up on the <em>:target</em> pseudo class &#8211; <a href="http://thinkvitamin.com/features/css/stay-on-target/">Stay on :target</a>. </p>
<p>Arve Bersvendsen, an Opera developer, has a good proof of concept on his personal site to change the <a href="http://virtuelvis.com/archives/2003/07/target-fun">stacking order of draggable windows using <em>:target</em></a>.</p>
<p><a href="http://www.css3.info/">CSS3.info</a> has a good compatibility table showing <a href="http://www.css3.info/modules/selector-compat/">browser support for CSS3 selectors</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/xhtml/futurebox/feed</wfw:commentRss>
		<slash:comments>45</slash:comments>
		</item>
	</channel>
</rss>
