<?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; xhtml</title>
	<atom:link href="http://www.thecssninja.com/category/xhtml/feed" rel="self" type="application/rss+xml" />
	<link>http://www.thecssninja.com</link>
	<description>All things CSS, JavaScript &#38; HTML</description>
	<lastBuildDate>Sat, 21 Jan 2012 02:06:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<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>Ryan Seddon</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>50</slash:comments>
		</item>
		<item>
		<title>How to create offline webapps on the iPhone</title>
		<link>http://www.thecssninja.com/javascript/how-to-create-offline-webapps-on-the-iphone</link>
		<comments>http://www.thecssninja.com/javascript/how-to-create-offline-webapps-on-the-iphone#comments</comments>
		<pubDate>Tue, 28 Apr 2009 04:30:46 +0000</pubDate>
		<dc:creator>Ryan Seddon</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=252</guid>
		<description><![CDATA[Recently Google launched their latest mobile version of Gmail optimised for iPhone and Android based browsers. One of the features that stood out was the offline access thanks to the browsers support of html5 application cache. Documentation on the application cache feature supported in safari iPhone 2.1+ is scarce and of that documentation it doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>Recently <a href="http://googlemobile.blogspot.com/2009/04/gmail-gets-new-engine-for-iphone-and.html">Google launched their latest mobile version of Gmail</a> optimised for iPhone and Android based browsers. One of the features that stood out was the offline access thanks to the browsers support of <a href="http://www.w3.org/TR/offline-webapps/#offline">html5 application cache</a>.<span id="more-252"></span></p>
<p>Documentation on the application cache feature supported in safari iPhone 2.1+ is scarce and of that documentation it doesn&#8217;t go into great detail. The best place to learn about this is on the <a href="http://developer.apple.com/safari/mobile.php">Safari DevCenter under the mobile section</a>, there it has 2 documents introducing the user to offline webapps; the first is a <a href="http://developer.apple.com/safari/library/codinghowtos/mobile/dataManagement/index.html#LOCAL_DATA-CREATE_A_WEB_APPLICATION_THAT_WILL_FUNCTION_OFFLINE">quick rundown on just the manifest file</a> and the second article touches on a few <a href="https://developer.apple.com/safari/library/documentation/iPhone/Conceptual/SafariJSDatabaseGuide/OfflineApplicationCache/chapter_2_section_1.html#//apple_ref/doc/uid/TP40007256-CH7-DontLinkElementID_10">more features available to offline webapps</a> such as the javascript events for updating the cache when the user is online. We&#8217;ll delve into these later in the article but first let&#8217;s take a look at a working example.</p>
<div class="resources01"><a class="demo" title="Offline Webapp" href="http://www.thecssninja.com/demo/offline_webapp/">View a live demo</a> <a class="demo source" title="Download the source of the offline webapp demo" href="http://www.thecssninja.com/demo/offline_webapp/offline_webapp.zip">Download the source files</a></div>
<div class="cf_info failure" id="usermessagea"><strong>Update:</strong> Added additional information about the <a href="#event-summary">event summary</a> and the order in which events get executed. Added link to useful tool for sniffing file <a href="#web-sniffer">Content-Types</a>.</div>
<p>To see the offline webapp in action, load the <a title="Offline Webapp" href="http://www.thecssninja.com/demo/offline_webapp/">demo</a> on your iPhone, then turn Airplane Mode on, re-open Safari and reload the <a title="Offline Webapp" href="http://www.thecssninja.com/demo/offline_webapp/">demo</a>. This time it will fetch the files from the cache that was created on the initial load.</p>
<h2 class="subtitle02">How does it all work?</h2>
<p>To get a basic offline webapp up and running is incredibly simple but it does have one caveat which tends to get a lot of people frustrated quickly when for some reason the offline feature isn&#8217;t working. We&#8217;ll explain that issue shortly.</p>
<p>The first thing we need to do is create what is called a cache manifest file which has references to all the resources we want to save. Whether it be JavaScript, CSS, images or html, below we can view the manifest file used in the <a title="Offline Webapp" href="http://www.thecssninja.com/demo/offline_webapp/">demo</a>.</p>
<div class="code">
<pre style='color:#d1d1d1;background:#000000;'>CACHE MANIFEST

# Offline cache v1
# html files
article<span style='color:#00a800; '>.</span>html

# css files
assets<span style='color:#d2cd86; '>/</span><span style='color:#d2cd86; '>_</span>styles<span style='color:#00a800; '>.</span>css

# js files
assets<span style='color:#d2cd86; '>/</span><span style='color:#d2cd86; '>_</span>javascript<span style='color:#00a800; '>.</span>js

# images
assets<span style='color:#d2cd86; '>/</span>ico<span style='color:#d2cd86; '>_</span>ninja<span style='color:#d2cd86; '>-</span>star<span style='color:#00a800; '>.</span>gif
</pre>
</div>
<p>The manifest file is a simple plain text file that holds the file names you wish to cache, the paths are relevant to where you saved the manifest file which is recommended to be in the root of the site. This file will be saved as <em>filename</em>.appcache, where <em>filename</em> is anything you wish. Lines that start with a # are comments and are ignored by the cache.</p>
<h2 class="subtitle02">Referencing the cache file</h2>
<p>We now have our cache manifest file setup and named, the next thing we need to do is reference that file in the html so this offline access will function for the specified files in the manifest.</p>
<div class="code">
<pre style='color:#d1d1d1;background:#000000;'><span style='color:#ff8906; '>&lt;</span><span style='color:#e66170; font-weight:bold; '>html</span> manifest<span style='color:#d2cd86; '>=</span><span style='color:#00c4c4; '>"thecssninja.appcache"</span><span style='color:#ff8906; '>></span>
</pre>
</div>
<p>The manifest file is referenced in the html tag through the manifest attribute and just points to the filename.</p>
<p>Now the one issue that catches a lot of people when trying this out is not setting up the mime type correctly in their chosen web server. Whether it be IIS, Apache or something else, you&#8217;ll need to make sure that the <em>.appcache</em> file is fed through as <em>text/cache-manifest</em>.</p>
<p>For Apache you can add the <em>text/cache-manifest</em> to the <em>mime.types</em> file found in the <em>conf</em> folder in apache and add the following to the bottom of the file.</p>
<div class="code">
<pre style='color:#d1d1d1;background:#000000;'># html <span style='color:#00a800; '>5</span> application cache <span style='color:#d2cd86; '>-</span> offline access
text<span style='color:#d2cd86; '>/</span>cache<span style='color:#d2cd86; '>-</span>manifest    appcache
</pre>
</div>
<p>For IIS open up the IIS manager found in Control Panel > Administrative Tools > Internet Information Services double click the Mime Types icon in the manager and scroll down the list until you find the .appcache file and edit the mime type to have <em>text/cache-manifest</em>.</p>
<p><img src="http://www.thecssninja.com/wp-content/uploads/2009/04/img_iis-mimetypes1.png" alt="IIS 7.0 Manager Mime Types" title="IIS 7.0 Manager Mime Types" width="609" height="253" class="article-img main-img" /></p>
<p>That&#8217;s it, to get a basic offline webapp to work is incredibly simple all it takes is the manifest file to specify which files to cache, declare it in on the <em>&lt;html&gt;</em> tag using the manifest attribute and you have yourself a site still accessible even if the user has no network connection.</p>
<p><span  id="web-sniffer">UPDATE:</span> <a href="#comment-925">GeoNomad</a> in the comments suggested a great tool to make sure your manifest file is being fed through with the correct mime type, <a href="http://web-sniffer.net/">Web Sniffer</a>. I put my <a href="http://web-sniffer.net/?url=http%3A%2F%2Fwww.thecssninja.com%2Fdemo%2Foffline_webapp%2Fthecssninja.appcache&#038;submit=Submit&#038;http=1.1&#038;gzip=yes&#038;type=GET&#038;uak=0">manifest file</a> through the Web Sniffer tool, you can see that the <em>Content-Type</em> is set as <em>text/cache-manifest</em>.</p>
<h2 class="subtitle02">Updating the cache</h2>
<p>If you want to update the cache you either need to change/add file references to the manifest and then tell the cache to update. Updating a file that the manifest calls will not make the cache reflect the changes. The <a href="https://developer.mozilla.org/en/Offline_resources_in_Firefox#section_11">mozilla developer article on applicationCache</a> makes a good suggestion to version your manifest file as the JavaScript events described below will only fire if there is a change to the manifest file. To update the cache we have:</p>
<div class="code">
<pre style='color:#d1d1d1;background:#000000;'>window<span style='color:#d2cd86; '>.</span>applicationCache<span style='color:#b060b0; '>;</span>
</pre>
</div>
<p>This object has various stages depending on what the cache is doing which can be checked by using the <em>.status</em> method. There are 6 different stages:</p>
<ul>
<li><strong>Status 0 (UNCACHED)</strong> is returned which means that there is no cache available</li>
<li><strong>Status 1 (IDLE)</strong> is returned means the cache you have is currently the most up-to-date</li>
<li><strong>Status 2 (CHECKING)</strong> is returned means there is a change in your manifest file and it is checking it for changes</li>
<li><strong>Status 3 (DOWNLOADING)</strong> is retuned means changes have been found and they are being added to your cache</li>
<li><strong>Status 4 (UPDATEREADY)</strong> is retuned means your new cache is ready to be updated and override your current cache</li>
<li><strong>Status 5 (OBSOLETE)</strong> is returned means your cache is no longer valid meaning it has been removed</li>
</ul>
<p>These available statuses can be attached to the applicationCache object with event listeners so we can tell the web app what to do on what status. In our case we want to update the cache to reflect changes we have done.</p>
<div class="code">
<pre style='color:#d1d1d1;background:#000000;'><span style='color:#e66170; font-weight:bold; '>var</span> webappCache <span style='color:#d2cd86; '>=</span> window<span style='color:#d2cd86; '>.</span>applicationCache<span style='color:#b060b0; '>;</span>

<span style='color:#e66170; font-weight:bold; '>function</span> updateCache<span style='color:#d2cd86; '>(</span><span style='color:#d2cd86; '>)</span> <span style='color:#b060b0; '>{</span>
    webappCache<span style='color:#d2cd86; '>.</span>swapCache<span style='color:#d2cd86; '>(</span><span style='color:#d2cd86; '>)</span><span style='color:#b060b0; '>;</span>
<span style='color:#b060b0; '>}</span>

webappCache<span style='color:#d2cd86; '>.</span>addEventListener<span style='color:#d2cd86; '>(</span><span style='color:#02d045; '>"</span><span style='color:#00c4c4; '>updateready</span><span style='color:#02d045; '>"</span><span style='color:#d2cd86; '>,</span> updateCache<span style='color:#d2cd86; '>,</span> <span style='color:#0f4d75; '>false</span><span style='color:#d2cd86; '>)</span><span style='color:#b060b0; '>;</span>
</pre>
</div>
<p>In the above example we attach an event listener to the applicationCache looking for the updateready status which means there is a change to the manifest file and our cache is ready to be updated we do so by using the <em><a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#dom-appcache-swapcache">swapCache()</a></em> method.</p>
<p>There is 2 more event handlers <del datetime="2009-07-31T14:46:12+00:00">which do not appear in the <em>window.applicationCache.status</em></del> these are part of the event summary. Those are <em>error</em> &amp; <em>progress</em>. We&#8217;ll take a look at how to use the <em>error</em> event, the <em>progress</em> event is basically the same as the <em>downloading</em> event handler.</p>
<div class="code">
<pre style='color:#d1d1d1;background:#000000;'><span style='color:#e66170; font-weight:bold; '>var</span> webappCache <span style='color:#d2cd86; '>=</span> window<span style='color:#d2cd86; '>.</span>applicationCache<span style='color:#b060b0; '>;</span>

<span style='color:#e66170; font-weight:bold; '>function</span> errorCache<span style='color:#d2cd86; '>(</span><span style='color:#d2cd86; '>)</span> <span style='color:#b060b0; '>{</span>
    alert<span style='color:#d2cd86; '>(</span><span style='color:#02d045; '>"</span><span style='color:#00c4c4; '>Cache failed to update</span><span style='color:#02d045; '>"</span><span style='color:#d2cd86; '>)</span><span style='color:#b060b0; '>;</span>
<span style='color:#b060b0; '>}</span>

webappCache<span style='color:#d2cd86; '>.</span>addEventListener<span style='color:#d2cd86; '>(</span><span style='color:#02d045; '>"</span><span style='color:#00c4c4; '>error</span><span style='color:#02d045; '>"</span><span style='color:#d2cd86; '>,</span> errorCache<span style='color:#d2cd86; '>,</span> <span style='color:#0f4d75; '>false</span><span style='color:#d2cd86; '>)</span><span style='color:#b060b0; '>;</span>
</pre>
</div>
<p>All the error event handler does is return the specified function we attached in the event listener when the cache is not available or does not exist.</p>
<h2 class="subtitle02" id="event-summary">Event summary</h2>
<p>In the applicationCache we have <a href="http://www.whatwg.org/specs/web-apps/current-work/#event-summary">various events available</a> so when the cache is being updated, or as mentioned above when something goes wrong. We can attach to those events and keep the user informed on what is happening. These events will execute in specific order based on what is happening with the cache and therefore give us useful hooks to represent that back to the user.</p>
<p>Pete who <a href="#comment-309">commented below</a> and needed a way of indicating to the user that the cache was downloading prompted me to look further into the events that get fired and which ones would be useful in this scenario. I <a href="http://www.thecssninja.com/demo/offline_webapp/loader/">created a demo</a> which will indicate to the user that the cache is downloading by showing a loading icon and once the cache had finished downloading, the loader would be hidden.</p>
<p>The event order for this example was as follows:</p>
<ul>
<li><em>checking</em> &#8211; The page loads and the cache is checked for any changes.</li>
<li><em>progress</em> &#8211; The download event actually gets fired before this but we don&#8217;t need to hook into that. The <em>progress</em> event will fire for each file that is referenced in your manifest until the cache has finished downloading.</li>
<li><em>cached</em> &#8211; The cache has successfully downloaded and the cached event is fired so we utilise that to hide the loader.</li>
<li><em>updateready</em> &#8211; This event is fired so we can then swap the old cache with the newly downloaded one.</li>
</ul>
<p>In the above mentioned demo we also attached event listeners to the error and noupdate events so we can handle errors and if the cache is already up-to-date.</p>
<h2 class="subtitle02">Is the user online</h2>
<p>There is also a new method on the <em>navigator</em> object called <em>onLine</em> which returns a boolean value if there is a network connection or not.</p>
<div class="code">
<pre style='color:#d1d1d1;background:#000000;'>navigator<span style='color:#d2cd86; '>.</span>onLine
</pre>
</div>
<p>In the <a href="http://www.thecssninja.com/demo/offline_webapp/">article example</a> the onLine method is used to update the title if the user is on/offline.</p>
<h2 class="subtitle02">Only the beginning</h2>
<p>The applicationCache is not yet finalised and is of course subject to change with newer and refined features. I&#8217;m sure there will be additions in the upcoming iPhone OS 3.0 release. If there are updates unfortunately these cannot be discussed until the NDA is lifted. But of course this won&#8217;t stop us speculating.</p>
<p>Some of the features available in applicationCache on firefox 3.1 and safari 4 will inevitably be added in future releases of the iPhone OS. Such as the <a href="https://developer.mozilla.org/en/Offline_resources_in_Firefox#section_8"><em>NETWORK:</em></a> and <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html#a-sample-manifest"><em>FALLBACK:</em></a> sections in the manifest file, these allow for the developer to specify a file they wish to never cache or to have a file load if something fails with the first option.</p>
<p>Short sharp facts about the appcache: <a href="http://appcachefacts.info/">http://appcachefacts.info/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/javascript/how-to-create-offline-webapps-on-the-iphone/feed</wfw:commentRss>
		<slash:comments>290</slash:comments>
		</item>
		<item>
		<title>Advanced hover states using CSS</title>
		<link>http://www.thecssninja.com/xhtml/advanced-hover-css</link>
		<comments>http://www.thecssninja.com/xhtml/advanced-hover-css#comments</comments>
		<pubDate>Wed, 01 Apr 2009 12:30:13 +0000</pubDate>
		<dc:creator>Ryan Seddon</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=184</guid>
		<description><![CDATA[The hover pseudo-element in CSS can be a powerful tool in a front-end developers arsenal, it&#8217;s not only for changing a links colour. In good browsers the hover element can be applied to almost anything but unfortunately ie6 &#38; 7 only support the hover selector on the anchor tag, but of course that isn&#8217;t going [...]]]></description>
			<content:encoded><![CDATA[<p>The hover pseudo-element in CSS can be a powerful tool in a front-end developers arsenal, it&#8217;s not only for changing a links colour. In good browsers the hover element can be applied to almost anything but unfortunately ie6 &amp; 7 only support the hover selector on the anchor tag, but of course that isn&#8217;t going to stop us accomplishing something cool. I&#8217;ll be looking at using the hover pseudo-element to add some clever functionality when a user hovers over an image.<span id="more-184"></span></p>
<div class="resources01"><a class="demo" title="Advanced CSS hovers" href="http://www.thecssninja.com/demo/css_hover/">View a live demo</a> <a class="demo source" title="Download the source of the css hover demo" href="http://www.thecssninja.com/demo/css_hover/css_hover.zip">Download the source files</a></div>
<p>In the above example we can see all the examples of the hovers using nothing but the hover pseudo-element on the surrounding anchor tag. This example uses a few gracefully degrading elements so if the browser doesn&#8217;t support the property it will still render fine and function as expected.</p>
<h2 class="subtitle02">Cross browser support</h2>
<p>This example has been tested in and works in the following browsers</p>
<ul>
<li>IE6+</li>
<li>Firefox 1.0+</li>
<li>Opera 9.25+</li>
<li>Safari 3+</li>
<li>Chrome 1+</li>
</ul>
<p><a class="feature01" href="#"><span class="overlay01"><span class="caption01">Roll over</span></span><img src="http://www.thecssninja.com/demo/css_hover/gr_ninja-attack.gif" alt="The CSS Ninja" width="200" height="206" /></a><span class="clear"> </span></p>
<p>We&#8217;ll deconstruct the above example and see how it all comes together.</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;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;feature01&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#&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;overlay01&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;caption01&quot;</span>&gt;</span>Roll over<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: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;location/to/image&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;200&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;206&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;">a</span>&gt;</span></pre></div></div>

<p>The above code is pretty basic a simple anchor tag with a class the image that displays and the overlay and caption we want to show when the user hovers over the image.</p>
<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">a<span style="color: #6666ff;">.feature01</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;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#dfd0cb</span>;
	<span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> 0;
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span> <span style="color: #933;">20px</span> <span style="color: #933;">1em</span> <span style="color: #933;">20px</span>;
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span>;
<span style="color: #00AA00;">&#125;</span>
a<span style="color: #6666ff;">.feature01</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span>; <span style="color: #00AA00;">&#125;</span>
&nbsp;
	a<span style="color: #6666ff;">.feature01</span><span style="color: #3333ff;">:hover </span><span style="color: #6666ff;">.overlay01</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>;
		<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">3</span>;
		<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">194px</span>;
		<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span>;
		<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#fff</span>;
	<span style="color: #00AA00;">&#125;</span>
		a<span style="color: #6666ff;">.feature01</span> <span style="color: #6666ff;">.overlay01</span> <span style="color: #6666ff;">.caption01</span>
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>;
			<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span>;
			<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</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;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">3</span>;
			<span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-9999em</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;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">11px</span>;
			<span style="color: #000000; font-weight: bold;">bottom</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: #00AA00;">&#125;</span>
		a<span style="color: #6666ff;">.feature01</span><span style="color: #3333ff;">:hover </span><span style="color: #6666ff;">.caption01</span>
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</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><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">&#41;</span>;
			<span style="color: #808080; font-style: italic;">/* for browsers that know rgba */</span>
			<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> rgba<span style="color: #00AA00;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.75</span><span style="color: #00AA00;">&#41;</span>;
		<span style="color: #00AA00;">&#125;</span>
		a<span style="color: #6666ff;">.feature01</span> img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2 class="subtitle02">The break down</h2>
<p>Now the CSS is a bit more involved but is relatively straight forward with a bit of explanation.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">a<span style="color: #6666ff;">.feature01</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;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#dfd0cb</span>;
	<span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">1px</span> <span style="color: #933;">1px</span> 0;
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">20px</span> <span style="color: #933;">20px</span> <span style="color: #933;">1em</span> <span style="color: #933;">20px</span>;
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The anchor tag is converted to a block level element and has its position set to relative so we can move around the span tags inside.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">a<span style="color: #6666ff;">.feature01</span><span style="color: #3333ff;">:hover </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The border-color change applied to the hover pseudo-element is there so IE6 will actually activate the hover this is due to a weird bug in IE6 that will not activate internal items that are changed when hovered over, unless something is applied directly to the hover pseudo-element, in our case a border. This can also be fixed by using background-color: transparent which is the least destructive property if you don&#8217;t actually want to modify the anchor itself on hover.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">a<span style="color: #6666ff;">.feature01</span><span style="color: #3333ff;">:hover </span><span style="color: #6666ff;">.overlay01</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>;
	<span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">3</span>;
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">194px</span>;
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span>;
	<span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">3px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#fff</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The .overlay01 span is styled on hover as we only need it when the user hovers over the image. Its converted to a block level element, positioned absolutely and given a width and height of 6px less than the image width/height. This is because of the 3px border that sits over the top of the image. If you decrease or increase the border you will need to adjust the width/height accordingly.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">a<span style="color: #6666ff;">.feature01</span> <span style="color: #6666ff;">.overlay01</span> <span style="color: #6666ff;">.caption01</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">absolute</span>;
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span>;
	<span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</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;">z-index</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">3</span>;
	<span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-9999em</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;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">11px</span>;
	<span style="color: #000000; font-weight: bold;">bottom</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: #00AA00;">&#125;</span>
&nbsp;
a<span style="color: #6666ff;">.feature01</span><span style="color: #3333ff;">:hover </span><span style="color: #6666ff;">.caption01</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</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><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span><span style="color: #cc66cc;">255</span><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><span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">255</span><span style="color: #00AA00;">,</span> <span style="color: #cc66cc;">0.75</span><span style="color: #00AA00;">&#41;</span>; <span style="color: #808080; font-style: italic;">/* for browsers that know rgba */</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>The .caption01 span is also position absolutely to the bottom of the anchor tag so the caption will display in a useful position when it&#8217;s hovered over. line-height is set to the same value as the height so the text will sit vertically centered. We also set a negative text-indent to hide the text when the hover is inactive; on hover we set the text-indent to a positive number and set the background-color twice using rgb and rgba. This will give it a nice transparent effect, and a solid rgb color for non-supporting browsers, gracefully degrading the transparency.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">a<span style="color: #6666ff;">.feature01</span> img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Finally the image is given a display block so we don&#8217;t get a gap between the anchor tag and image.</p>
<h2 class="subtitle02">A little fun</h2>
<p>So you may have noticed that the <a href="http://www.thecssninja.com/demo/css_hover/">3 middle images in the example above</a> have an extra word appear when you hover. If you took a look at the <a href="http://www.thecssninja.com/demo/css_hover/">example page html</a> you may have noticed that the caption text is using the <a href="http://www.w3.org/TR/CSS2/generate.html#before-after-content">after psuedo-element</a> along with the <a title="CSS2 content property" href="http://www.w3.org/TR/CSS2/generate.html#content">content property</a> to dynamically add content through CSS. This is another gracefully degrading technique that will fall back to the generic text if it&#8217;s not supporting.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">a<span style="color: #6666ff;">.feature04</span> <span style="color: #6666ff;">.overlay01</span> <span style="color: #6666ff;">.caption01</span><span style="color: #3333ff;">: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;">' more!'</span>; <span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/xhtml/advanced-hover-css/feed</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
		<item>
		<title>5 clever uses of the canvas tag</title>
		<link>http://www.thecssninja.com/javascript/5-uses-canvas-tag</link>
		<comments>http://www.thecssninja.com/javascript/5-uses-canvas-tag#comments</comments>
		<pubDate>Wed, 25 Feb 2009 11:17:01 +0000</pubDate>
		<dc:creator>Ryan Seddon</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[xhtml]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[html 5]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=131</guid>
		<description><![CDATA[If there is one thing that really gets me exciting about the upcoming HTML 5 specification it&#8217;s the canvas tag. This relatively simple tag holds so much potential and power thanks to the strong well thought out JavaScript API available to manipulate what appears on the canvas. I&#8217;ll be looking at 5 really ingenious implementations [...]]]></description>
			<content:encoded><![CDATA[<p>If there is one thing that really gets me exciting about the upcoming HTML 5 specification it&#8217;s the canvas tag. This relatively simple tag holds so much potential and power thanks to the strong well thought out JavaScript API available to manipulate what appears on the canvas.<br />
<span id="more-131"></span></p>
<p>I&#8217;ll be looking at 5 really ingenious implementations that are being used today on various websites and web apps.</p>
<h2 class="subtitle02">5. Typeface.js</h2>
<p><a href="http://typeface.neocracy.org/"><img src="http://www.thecssninja.com/wp-content/uploads/2009/02/img_typefacejs.png" alt="Typeface.js, render custom fonts using canvas" title="Typeface.js, render custom fonts using canvas" width="609" height="327" class="article-img main-img" /></a></p>
<p>A great solution to use custom fonts on your websites without having to cut out the text as images. This generates JavaScript from an otf file which renders out the font using the canvas tag. <a href="http://typeface.neocracy.org/">Rendering text with Javascript, &lt;canvas&gt;, and VML</a></p>
<h2 class="subtitle02">4. Box2DJS physics engine</h2>
<p><a href="http://box2d-js.sourceforge.net/"><img src="http://www.thecssninja.com/wp-content/uploads/2009/02/img_box2djs.png" alt="Box2DJS - Physics Engine for JavaScript" title="Box2DJS - Physics Engine for JavaScript" width="609" height="327" class="article-img main-img" /></a></p>
<p>This library is for recreating elements on a canvas that obey the laws of physics such as gravity and motion. Objects can interact with each other in a realistic manner. <a href="http://box2d-js.sourceforge.net/">Physics Engine for JavaScript</a></p>
<h2 class="subtitle02">3. Wolfenstein 3D</h2>
<p><a href="http://blog.nihilogic.dk/2008/04/javascript-wolfenstein-3d.html"><img src="http://www.thecssninja.com/wp-content/uploads/2009/02/img_wolfenstein3d.jpg" alt="Nihilogic : Javascript Wolfenstein 3D" title="Nihilogic : Javascript Wolfenstein 3D" width="609" height="327" class="article-img main-img" /></a></p>
<p>A great port of the classic Wolfenstein 3D done using nothing but javascript and canvas. <a href="http://blog.nihilogic.dk/2008/04/javascript-wolfenstein-3d.html">Javascript Wolfenstein 3D</a></p>
<h2 class="subtitle02">2. Yahoo pipes</h2>
<p><a href="http://pipes.yahoo.com/pipes/"><img src="http://www.thecssninja.com/wp-content/uploads/2009/02/img_yahoopipes.png" alt="Yahoo Pipes: Rewire the web" title="Yahoo Pipes: Rewire the web" width="609" height="327" class="article-img main-img" /></a></p>
<p>Yahoo pipes is a mash up tool for the less technical to build &#8220;pipes&#8221; or mashups of data pulled from various sources. Pipes uses the canvas tag to create connecting points between data sources and controls. The blue curvy line is done using canvas and its bezier abilities to curve lines.</p>
<blockquote cite="http://pipes.yahoo.com/pipes/"><p>Pipes is a powerful composition tool to aggregate, manipulate, and mashup content from around the web.</p>
</blockquote>
<h2 class="subtitle02">1. Mozilla labs Bespin</h2>
<p><a href="https://bespin.mozilla.com/"><img src="http://www.thecssninja.com/wp-content/uploads/2009/02/img_mozillabespin.png" alt="Mozilla Bespin » Code in the Cloud" title="Mozilla Bespin » Code in the Cloud" width="609" height="327" class="article-img main-img" /></a></p>
<p>By far the best implementation of canvas so far is <a href="http://labs.mozilla.com/">Mozillas Bespin a web code editor</a> which uses canvas to create it&#8217;s slick interface, without canvas Bespin would not be as responsive as it is even with thousands of lines of code.</p>
<blockquote cite="http://labs.mozilla.com/"><p>Bespin is a Mozilla Labs experiment on how to build an extensible Web code editor using HTML 5 technology.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/javascript/5-uses-canvas-tag/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Sangraal layout: A true flexible, fluid CSS layout</title>
		<link>http://www.thecssninja.com/xhtml/sangraal-layout</link>
		<comments>http://www.thecssninja.com/xhtml/sangraal-layout#comments</comments>
		<pubDate>Tue, 10 Feb 2009 01:10:10 +0000</pubDate>
		<dc:creator>Ryan Seddon</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=70</guid>
		<description><![CDATA[The wait is over, finally a real &#8216;sangraal&#8217; layout that ticks all the boxes: 3 column, 2 column, 1 column it&#8217;s all flexible Fluid centre layout No need for negative margins. Works in ie5+, firefox 1+, opera 9.6+, safari 2+, chrome Minimal mark-up &#38; clean CSS With inspiration coming from A List Aparts&#8217; article &#8216;In [...]]]></description>
			<content:encoded><![CDATA[<p>The wait is over, finally a real &#8216;sangraal&#8217; layout that ticks all the boxes:</p>
<ul>
<li>3 column, 2 column, 1 column it&#8217;s all flexible</li>
<li>Fluid centre layout</li>
<li>No need for negative margins.</li>
<li>Works in ie5+, firefox 1+, opera 9.6+, safari 2+, chrome</li>
<li>Minimal mark-up &amp; clean CSS</li>
</ul>
<p><span id="more-70"></span>With inspiration coming from A List Aparts&#8217; article &#8216;<a title="In Search of the Holy Grail" href="http://www.alistapart.com/articles/holygrail">In Search of the Holy Grail</a>&#8216; but with a need for a better way without the use of negative margins to help pull the main content back into place. Making it a much more powerful, flexible layout with a much easier setup. Let&#8217;s take a look at an example before we delve into the inner workings.</p>
<p><a title="The ultimate fluid layout - Sangraal layout" href="http://www.thecssninja.com/demo/sangraal_layout/"><img class="article-img main-img" title="The ultimate flexible layout example" src="http://www.thecssninja.com/wp-content/uploads/2009/02/gr_sangraal-layout.png" alt="The ultimate flexible layout example" width="609" height="327" /></a></p>
<div class="resources01"><a class="demo" title="The ultimate fluid layout - Sangraal layout" href="http://www.thecssninja.com/demo/sangraal_layout/">View a live demo</a> <a class="demo source" title="Download the source of theSangraal layout demo" href="http://www.thecssninja.com/demo/sangraal_layout/sangraal_layout.zip">Download the source files</a></div>
<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;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;maincontainer&quot;</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;column01&quot;</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;restraint&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Left column<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;">div</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: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;column03&quot;</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;restraint&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Right column<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;">div</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: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;column02&quot;</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;restraint&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Middle column<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;">div</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;">div</span>&gt;</span></pre></div></div>

<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.maincontainer</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span>;
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span>;
<span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* Left column */</span>
	<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column01</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #808080; font-style: italic;">/*
		    Width is set in inner div of column to
		    avoid the use of negative margins
		*/</span>
		<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column01</span> .restraint<span style="color: #00AA00;">,</span>
		<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column03</span> <span style="color: #6666ff;">.restraint</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;">200px</span>;
		<span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* Left column */</span>
	<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column03</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span>;
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* Middle column */</span>
	<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column02</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span>;
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column02</span> <span style="color: #6666ff;">.restraint</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: #00AA00;">&#125;</span>
		<span style="color: #00AA00;">*</span> html <span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column02</span>
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #808080; font-style: italic;">/* cause hasLayout so middle column will sit between left and right */</span>
			<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span>;
		<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2 class="subtitle02">How it all works</h2>
<p>This layout is quite ingenious, it&#8217;s very simple and extremely flexible. The containing div isn&#8217;t essential for the layout to function. However, it is a good idea. Containing it will allow for easy selection in the CSS and prevent issues with inheritance. You&#8217;ll notice that the left and right column appear before the main content container, this is needed for the layout to work. In each column there is a restraint div. The magic of this layout is in the restraint div setup; columns 1 &amp; 3 are floated left and right respectively and column 2 is set with a hidden overflow. This allows for column 2 to appear between the left &amp; right columns. The restraint divs can now be used to set the widths of the columns. Columns 1 &amp; 3 have pixel widths set, column 2 is then set with 100% width so it will fill the remaining space. Having the widths set inside the columns allows for this layout to work. If you have ever floated an image near a paragraph you&#8217;ll understand how this is working, by placing the 2 floated divs before the block level element will cause it to wrap around the floated elements. This setup has 1 difference if the middle column is longer than the other columns it will not wrap but rather keep it&#8217;s width and not overflow into the left &amp; right columns this is due to the hidden overflow on the middle column, without it the middle column would behave as expected and wrap underneath the left and right columns. The * html selector is used to give column 2 <a href="http://haslayout.net/haslayout">layout</a> in IE6, this is the least destructive hasLayout property in our case. Without this, the middle column would appear below the left &amp; right columns.</p>
<p>Here we have a very flexible layout, I highly suggest you mess around with it and see the true power e.g. removing the left, right or both columns won&#8217;t break the layout, and the middle column will expand to take up the extra space. Adjusting the left and right column widths will also make the middle column adjust to the space it has to work with. I believe this to be the most powerful layout available. Have a play with <a href="http://www.thecssninja.com/demo/sangraal_layout/flexible.html">this example</a>, there are 2 input fields which dynamically adjust the left &amp; right column widths.</p>
<h2 class="subtitle02">One thing to make it perfect</h2>
<p>There&#8217;s one last thing to make this perfect, if you have been playing with the demos you may have noticed that resizing the window to a small width breaks the layout and eventually causes the middle column to behave oddly.</p>
<p><img class="article-img main-img" title="Sangraal layout plays up when it goes to small" src="http://www.thecssninja.com/wp-content/uploads/2009/02/gr_sangraal-layout02.png" alt="Sangraal layout plays up when it goes to small" width="473" height="296" /></p>
<p>What we need is a cross browser min-width and if you take a look at my last article <a href="http://www.thecssninja.com/xhtml/ie6-min-width-solutions">&quot;A look at pure CSS IE6 min-width solutions&quot;</a> we have the perfect solution using padding to accomplish just that.</p>
<div class="resources01"><a class="demo" title="The ultimate fluid layout - Sangraal layout now with min-width" href="http://www.thecssninja.com/demo/sangraal_layout/min-width_layout.html">View a live demo</a> <a class="demo source" title="Download the source of the Sangraal layout demo now with min-width" href="http://www.thecssninja.com/demo/sangraal_layout/sangraal_layout_min-width.zip">Download the source files</a></div>
<h2 class="subtitle02">The xhtml</h2>

<div class="wp_syntax"><div class="code"><pre class="html4strict html4strict" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--[if IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;div class=&quot;min_width&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;div class=&quot;min_width_inner&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">			&lt;div class=&quot;min_width_container&quot;&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;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;maincontainer&quot;</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;column01&quot;</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;restraint&quot;</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Left column<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;">div</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: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;column03&quot;</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;restraint&quot;</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Right column<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;">div</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: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;column02&quot;</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;restraint&quot;</span>&gt;</span>
				<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Middle column<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;">div</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;">div</span>&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--[if IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">			&lt;/div&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;/div&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;/div&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;![endif]--&gt;</span></pre></div></div>

<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Min -width styles */</span>
<span style="color: #6666ff;">.min_width</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">480px</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: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.min_width</span> <span style="color: #6666ff;">.min_width_inner</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: #808080; font-style: italic;">/*  gives the element hasLayout */</span>
<span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.min_width</span> <span style="color: #6666ff;">.min_width_container</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-480px</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;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Sangraal layout styles */</span>
<span style="color: #6666ff;">.maincontainer</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">relative</span>;
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</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: #808080; font-style: italic;">/* For good browsers */</span>
<span style="color: #00AA00;">&#125;</span>	
	<span style="color: #808080; font-style: italic;">/* Left column */</span>
	<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column01</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #808080; font-style: italic;">/* Width is set in inner div of column to avoid the use of negative margins */</span>
		<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column01</span> .restraint<span style="color: #00AA00;">,</span>
		<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column03</span> <span style="color: #6666ff;">.restraint</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;">200px</span>;
		<span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* Left column */</span>
	<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column03</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">right</span>;
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* Middle column */</span>
	<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column02</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span>;
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column02</span> <span style="color: #6666ff;">.restraint</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: #00AA00;">&#125;</span>
		<span style="color: #00AA00;">*</span> html <span style="color: #6666ff;">.maincontainer</span> <span style="color: #6666ff;">.column02</span>
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #808080; font-style: italic;">/* cause hasLayout so middle column will sit between left and right */</span>
			<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> inline-<span style="color: #993333;">block</span>;
		<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>If you refer back to the <a href="http://www.thecssninja.com/xhtml/ie6-min-width-solutions">&quot;A look at pure CSS IE6 min-width solutions&quot;</a> article you&#8217;ll see how the min-width works in IE6. There is only 1 slight difference with this, the actual min-width property is on the .maincontainer div and not the .min-width div. The min-width mark-up has also all been moved within the IE6 conditional comments so it will only render for IE6 and not cause any problems with the good browsers.</p>
<h2 class="subtitle02">A layout to remember&#8230;</h2>
<p>This layout isn&#8217;t perfect but it comes damn near close. It is a little heavy on the mark-up but for what it accomplishes I think that&#8217;s ok. The order of the div&#8217;s will also be a concern to some especially those using screen readers as going from the left to right to middle may disorientate some.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/xhtml/sangraal-layout/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>A look at pure CSS IE6 min-width solutions</title>
		<link>http://www.thecssninja.com/xhtml/ie6-min-width-solutions</link>
		<comments>http://www.thecssninja.com/xhtml/ie6-min-width-solutions#comments</comments>
		<pubDate>Sun, 01 Feb 2009 03:18:12 +0000</pubDate>
		<dc:creator>Ryan Seddon</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=75</guid>
		<description><![CDATA[As a large user base are still using Internet Explorer 6, with it&#8217;s extremely poor support for essential CSS, we as front-end developers need to come up with creative solutions to Internet Explorer&#8217;s limitations. One such limitation is the min-width property. In this article I will be looking at 2 pure CSS solutions each with [...]]]></description>
			<content:encoded><![CDATA[<p>As a large user base are still using Internet Explorer 6, with it&#8217;s extremely poor support for essential CSS, we as front-end developers need to come up with creative solutions to Internet Explorer&#8217;s limitations. One such limitation is the <a title="CSS 2.1 specification details on the min-width property" href="http://www.w3.org/TR/CSS21/visudet.html#propdef-min-width">min-width</a> property. In this article I will be looking at 2 pure CSS solutions each with their strengths and weaknesses.<br />
<span id="more-75"></span></p>
<div class="clear">&nbsp;</div>
<h2 class="subtitle02">1. Using borders to create min-width effect</h2>
<p>This technique was inspired by the very clever Stu Nicholls over at <a title="Stu Nicholls CSSplay website" href="http://www.cssplay.co.uk/boxes/minwidth.html">CSSplay</a>. It uses a left and right border to create the min-width effect in IE6.</p>
<div class="resources01"><a class="demo" title="View the demo of the IE6 min-width solution using borders" href="http://www.thecssninja.com/demo/ie_min-width/sample1.html">View min-width using borders demo</a> <a class="demo source" title="Download the source for the IE6 min-width borders technique" href="http://www.thecssninja.com/demo/ie_min-width/ie_min-width-borders.zip">Download the source files</a></div>
<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;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;min_width&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--[if IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;div class=&quot;ie_min-width&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">	&lt;![endif]--&gt;</span>
&nbsp;
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
			Content here
		<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
&nbsp;
	<span style="color: #808080; font-style: italic;">&lt;!--[if IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;/div&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;">div</span>&gt;</span></pre></div></div>

<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.min_width</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">min-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span>; <span style="color: #808080; font-style: italic;">/* For good browsers */</span>
<span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* for ie6 only adds borders to give min-width effect */</span>
	<span style="color: #00AA00;">*</span> html <span style="color: #6666ff;">.min_width</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;">250px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#ff0000</span>;
		<span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">250px</span>; <span style="color: #808080; font-style: italic;">/* Set this to half of you min-width (250 * 2 = 500)  */</span>
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.min_width</span> <span style="color: #6666ff;">.ie_min-width</span>
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-250px</span>; <span style="color: #808080; font-style: italic;">/* Pulls the content back over the borders */</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;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
		<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2 class="subtitle02">How it works</h2>
<p>You set up 2 containers 1 which has the min-width property for all the standard compliant browsers. You then target that same div with the * html selector and apply a border with half the value of the min-width you wish to have and apply that to the left and right of the border attribute. The second container is within <a href="http://msdn.microsoft.com/en-us/library/ms537512.aspx">IE conditional comments</a> so it doesn&#8217;t render in anything but IE6 this is then applied with a negative margin equivalent of the border values previously set. Position relative and float left are applied to fix the <a href="http://haslayout.net/css/negmargin">negative margin bug</a>.</p>
<h2 class="subtitle02">The Pros</h2>
<ul>
<li>Minimal mark-up and CSS.</li>
<li>Simple to implement.</li>
<li>Great for simple layouts.</li>
</ul>
<h2 class="subtitle02">The Cons</h2>
<ul>
<li>Border colours can&#8217;t be set to transparent in IE6 this can cause problems when setting background images/colours on the container with the border applied. See example <a title="Issue with borders and background colours" href="http://www.thecssninja.com/demo/ie_min-width/sample1-1.html">here</a>. There is a &#8220;fix&#8221; to create transparent borders in IE6 but it relies on the <a title="IE Chroma Filter property" href="http://msdn.microsoft.com/en-us/library/ms532982(VS.85).aspx">Chroma Filter</a> property this allows background colours to come through the border but does not fix the issue of backgrounds on the div with the border, see the <a title="chroma filter applied to border" href="http://www.thecssninja.com/demo/ie_min-width/sample1-2.html">chroma filter in action here</a>.</li>
<li>Not for every layout. The more complex and graphic intensive a design becomes, the less viable this solution is.</li>
</ul>
<h2 class="subtitle02">Chroma filter fix</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Gets transparent borders working in ie6 */</span>
filter<span style="color: #3333ff;">:progid</span><span style="color: #3333ff;">:DXImageTransform</span><span style="color: #6666ff;">.Microsoft</span>.Chroma<span style="color: #00AA00;">&#40;</span><span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">=</span><span style="color: #cc00cc;">#ff0000</span><span style="color: #00AA00;">&#41;</span>;</pre></div></div>

<h2 class="subtitle02">2. Using padding to create min-width effect</h2>
<p>This technique works in a similar way to the borders but without the issues and hassles of using borders. I have not yet seen this technique used anywhere else.</p>
<div class="resources01"><a class="demo" title="View the demo of the IE6 min-width solution using padding" href="http://www.thecssninja.com/demo/ie_min-width/sample2.html">View min-width using padding demo</a> <a class="demo source" title="Download the source for the IE6 min-width padding technique" href="http://www.thecssninja.com/demo/ie_min-width/ie_min-width-padding.zip">Download the source files</a></div>
<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;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;min_width02&quot;</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--[if IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;div class=&quot;min_width_inner&quot;&gt;</span>
<span style="color: #808080; font-style: italic;">			&lt;div class=&quot;min_width_container&quot;&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;">p</span>&gt;</span>
				Content here
			<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
	<span style="color: #808080; font-style: italic;">&lt;!--[if IE 6]&gt;</span>
<span style="color: #808080; font-style: italic;">			&lt;/div&gt;</span>
<span style="color: #808080; font-style: italic;">		&lt;/div&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;">div</span>&gt;</span></pre></div></div>

<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #6666ff;">.min_width02</span>
<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">min-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span>; <span style="color: #808080; font-style: italic;">/* For good browsers */</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span>;
<span style="color: #00AA00;">&#125;</span>
	<span style="color: #00AA00;">*</span> html <span style="color: #6666ff;">.min_width02</span>
	<span style="color: #00AA00;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">250px</span>;
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #6666ff;">.min_width02</span> <span style="color: #6666ff;">.min_width_inner</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: #808080; font-style: italic;">/*  gives the element hasLayout */</span>
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.min_width02</span> <span style="color: #6666ff;">.min_width_container</span>
		<span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> 0 <span style="color: #933;">-250px</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;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
		<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2 class="subtitle02">How it works</h2>
<p>This uses 3 containers, the main parent container has the min-width property set for the good browsers and also uses the * html selector to apply the padding to the left and right so the padding will equal that of the min-width you wish to use. The 2nd and 3rd containers are in conditional comments as they are only needed for IE6. The 2nd container has width: 100% applied to give IE6 <a href="http://haslayout.net/haslayout">layout</a>. This is set to width because it is the least destructive property to cause layout in IE6, you could use zoom: 1 but this is a propriety CSS property and is better to avoid. Refer here for all properties that <a href="http://haslayout.net/haslayout#get_layout">cause layout</a>. Finally the last container uses negative margins to pull it back into the padding, again the position and float are there to fix the <a href="http://haslayout.net/css/negmargin">negative margin bug</a>.</p>
<h2 class="subtitle02">The Pros</h2>
<ul>
<li>Uses padding rather borders</li>
<li>No issues with having background colours/images</li>
</ul>
<h2 class="subtitle02">The Cons</h2>
<ul>
<li>It&#8217;s a little heavier on the mark-up but this is only rendered in IE6, through the use of conditional comments.</li>
</ul>
<p>There we have 2 ingenious techniques to accomplish what is a very easy task in all the good browsers. With a few workarounds these are hack free, clean and simple to implement.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/xhtml/ie6-min-width-solutions/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Why display: table shouldn&#8217;t be frowned upon</title>
		<link>http://www.thecssninja.com/xhtml/why-display-table-shouldnt-be-frowned-upon</link>
		<comments>http://www.thecssninja.com/xhtml/why-display-table-shouldnt-be-frowned-upon#comments</comments>
		<pubDate>Sat, 24 Jan 2009 03:44:12 +0000</pubDate>
		<dc:creator>Ryan Seddon</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://www.thecssninja.com/?p=17</guid>
		<description><![CDATA[I&#8217;ve seen a lot of commentary on the for, and against of using the CSS property display: table, a lot of it negative. It takes us back to the dark ages, using tables for layout. These people tend to forget that CSS is purely presentational and setting something as display: table is not the same [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen a lot of commentary on the for, and against of using the CSS property <em>display: table</em>, a lot of it negative. It takes us back to the dark ages, using tables for layout. These people tend to forget that CSS is purely presentational and setting something as <em>display: table</em> is not the same as using the table tag. A screen reader going over a layout styled using the CSS table model will not get confused and muddled up. It will in fact breeze through a layout done correctly no matter which technique used floats or CSS tables. The display properties values: <em>table, table-cell, table-row</em> etc are named due to the fact its presentational result is that best described of how a table would work and the similarities end there.<br />
<span id="more-17"></span><br />
Let’s take a look at a few examples of layouts done with <em>display: table</em> and show you some advantages. You will in fact see a lot of reduced mark-up in favour of using the CSS tables’ method. It should be noted that the following techniques do not work in IE6 or IE7 (despite this being in the <a title="The CSS table model" href="http://www.w3.org/TR/CSS21/tables.html#table-display">CSS 2.1 spec</a>) but it is finally supported in IE8. Therefore it’s not recommended to use in real world environments, but that doesn&#8217;t mean we still can&#8217;t have fun.</p>
<h2 class="subtitle02">The run down</h2>
<p>In this example I will do a simple header, content, footer layout but with one twist this layout stretches both vertically and horizontally creating a true fluid layout without the use of hacks or CSS voodooism.</p>
<div class="resources01"><a class="demo" title="Simple demo of CSS tables" href="http://www.thecssninja.com/demo/css_tables/">View a live demo</a><a class="demo source" title="Download the source of the CSS tables demo" href="http://www.thecssninja.com/demo/css_tables/css_tables-simple.zip">Download the source files</a></div>
<div class="cf_info failure" id="usermessagea"><strong>Update:</strong> Removed <em>overflow:hidden</em> from <em>html,body</em> as it wasn&#8217;t needed and caused issues when there was content overflowing. Added extra container inside content and applied <em>display: table-cell</em> so padding could be applied. <a href="http://www.thecssninja.com/demo/css_tables/overflow.html">View overflow example</a></div>
<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;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;maincontainer&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;header&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Header<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;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;content&quot;</span>&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;container&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Content<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;">div</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: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;footer&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Footer<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;">div</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>

<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Makes the layout expand to 100% height. Without this CSS below won't work */</span>
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: #cc00cc;">#maincontainer</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: #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;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span>;
<span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/*  Basic table layout */</span>
	<span style="color: #cc00cc;">#maincontainer</span> <span style="color: #cc00cc;">#header</span><span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#maincontainer</span> <span style="color: #cc00cc;">#content</span><span style="color: #00AA00;">,</span>
	<span style="color: #cc00cc;">#maincontainer</span> <span style="color: #cc00cc;">#footer</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;">table-row</span>;
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#maincontainer</span> <span style="color: #cc00cc;">#header</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;">150px</span>;
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">green</span>;
	<span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#maincontainer</span> <span style="color: #cc00cc;">#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;"><span style="color: #cc66cc;">100</span>%</span>;
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000000</span>;
		<span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#ffffff</span>;
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #cc00cc;">#maincontainer</span> <span style="color: #cc00cc;">#content</span> <span style="color: #6666ff;">.container</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;">table-cell</span>;
			<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span>;
		<span style="color: #00AA00;">&#125;</span>
	<span style="color: #cc00cc;">#maincontainer</span> <span style="color: #cc00cc;">#footer</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;">80px</span>;
		<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">purple</span>;
	<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h2 class="subtitle02">The run down</h2>
<p>Now we&#8217;ll take a look at a technique that isn&#8217;t easily accomplished in the good browsers, I&#8217;m of cause speaking of vertical centring. With the use of table display property we can accomplish this with very little mark-up and CSS.</p>
<div class="resources01"><a class="demo" title="Vertical centering using CSS display: table" href="http://www.thecssninja.com/demo/css_tables/vertical-centre.html">View a live demo</a><a class="demo source" title="Download the source of the vertical centering CSS tables demo" href="http://www.thecssninja.com/demo/css_tables/css_tables-vertical.zip">Download the source files</a></div>
<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;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;maincontainer&quot;</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;table-cel&quot;</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;box01&quot;</span>&gt;</span>
			<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span>&gt;</span>Horizontally and vertically centred!<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;">div</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;">div</span>&gt;</span></pre></div></div>

<h2 class="subtitle02">The CSS</h2>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* Makes the layout expand to 100% height without this CSS below won't work */</span>
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: #cc00cc;">#maincontainer</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: #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;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">100</span>%</span>;
<span style="color: #00AA00;">&#125;</span>
	<span style="color: #808080; font-style: italic;">/* Vertical centre */</span>
	<span style="color: #6666ff;">.table-cel</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;">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: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000000</span>;
	<span style="color: #00AA00;">&#125;</span>
		<span style="color: #6666ff;">.table-cel</span> <span style="color: #6666ff;">.box01</span>
		<span style="color: #00AA00;">&#123;</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;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span>;
			<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span>;
			<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> orange;
		<span style="color: #00AA00;">&#125;</span>
			<span style="color: #6666ff;">.table-cel</span> <span style="color: #6666ff;">.box01</span> p
			<span style="color: #00AA00;">&#123;</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;">line-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">500px</span>;
			<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>These 2 examples only scratch the surface of the power that the table display property gives you. With Microsoft finally adding support in IE8 these techniques will only become more viable.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thecssninja.com/xhtml/why-display-table-shouldnt-be-frowned-upon/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

