<?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>Paul Bennett - User Interface Developer &#187; CSS</title>
	<atom:link href="http://pmbennett.net/tag/css/feed/" rel="self" type="application/rss+xml" />
	<link>http://pmbennett.net</link>
	<description></description>
	<lastBuildDate>Thu, 27 Oct 2011 15:10:11 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>CSS3 Animated Photo Stack with jQuery</title>
		<link>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/</link>
		<comments>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/#comments</comments>
		<pubDate>Fri, 28 May 2010 11:51:42 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Transitions Webkit]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=377</guid>
		<description><![CDATA[CSS3 transitions and animations are rightly attracting a lot of attention. With support in most modern browsers, there is a lot of scope for creating rich user experiences using only CSS. In this post, I will walk through how to create a stack of photos using CSS keyframe animations and a dash of jQuery to achieve a pretty awesome effect.]]></description>
			<content:encoded><![CDATA[<p>So, lets dive straight in! The markup is pretty straightforward, you just need a container filled with the images for the stack of photos:</p>
<pre><code>&lt;div id="photo_stack"&gt;
	&lt;img id="photo1" src="images/photostack1.jpg" alt="Alt text goes here..." /&gt;
	&lt;img id="photo2" src="images/photostack2.jpg" alt="Alt text goes here..." /&gt;
	&lt;img id="photo3" src="images/photostack3.jpg" alt="Alt text goes here..." /&gt;
&lt;/div&gt;</code></pre>
<p>You will then need some simple CSS to style and position the images in a stack. We will be using jQuery to alter the z-index values of each image once the animation has completed, so we will start by giving each image a high z-index value. You will also need to setup the speed and easing functions for the transitions. </p>
<pre><code>#photo_stack img {
	position: absolute;
	border: 10px solid #FFF;
	box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	-moz-box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	-webkit-box-shadow: 2px 2px 8px rgba(0,0,0,0.5);
	z-index: 9999;

	/* setup transition speed and easing */
	-moz-transition: all 0.2s ease; /* Firefox */
	-webkit-transition: all 0.2s ease; /* WebKit */
	-o-transition: all 0.2s ease; /* Opera */
	transition: all 0.2s ease; /* Standard */

}
#photo_stack #photo1 {
	top: 0;
	left: 100px;
}
#photo_stack #photo2 {
	top: 12px;
	left: 55px;
}
#photo_stack #photo3 {
	top: 27px;
	left: 50px;
}</code></pre>
<p>Once this is complete you can add the CSS to create the keyframe animation, which will take the image at the top of the stack and place it at the bottom of the photo stack.</p>
<pre><code>@-webkit-keyframes shuffle {
	0% {
		margin-left: 0px;
	}
	50% {
		margin-left: 450px;
		-webkit-transform: scale(0.9);
		-moz-transform: scale(0.9);
		transform: scale(0.9);
	}
	100% {
		margin-left: 0px;
		-webkit-transform: scale(1);
		-moz-transform: scale(1);
		transform: scale(1);
	}
}
#photo_stack .animate {
	-webkit-animation-name: shuffle;
	-webkit-animation-duration: 1s;
	-webkit-animation-iteration-count: 1;
}</code></pre>
<p>What this is basically doing, is running the keyframe animation called &#8217;shuffle&#8217; once and for a duration of 1 second. The animation itself is moving the image 450px to the right of the stack, scaling down to give an impression of depth, and then moving it back to where it&#8217;s original position. Note that this will only happen when the image is assigned the &#8216;animate&#8217; class.</p>
<p>Okay, so you now have a cool animation effect, but nothing triggers it and the image does not go to the bottom of the stack: Enter jquery. What jquery will do, is trigger the animation by assigning the &#8216;animate&#8217; class to the image on the top of the stack, removing it once the animation is complete. </p>
<pre><code>$imgs = $("#photo_stack img");
$imgCount = $imgs.length;
$curr_index = 0;
$imgs.last().addClass('current'); /* Set the image at top of stack to current */

$("#photo_stack")
	.delegate('img', 'click', function() {
		$this = $(this);

		/* If the image is at the top of the stack */
		if ($this.hasClass('current')) {
			/* Work out new z-index value */
			$zi = $this.css('zIndex') - $imgCount;

			/* Trigger animation */
			$this.addClass('animate');

			/* Assign new z-index value then stop animation after complete */
			setTimeout(function() { $this.css('zIndex', $zi); }, 200);
			setTimeout(function() { $this.removeClass('animate'); }, 1000);

			/* Set next image to current */
			$this.removeClass('current');
			if ($this.index() == 0) {
				$imgs.last().addClass('current');
			} else {
				$imgs.eq($this.index()-1).addClass('current');
			}
		}
	})</code></pre>
<p>You will now have some images in a stack that you can click on and they will be animated and placed to the bottom of the stack. Now it is time to use the rotation transition to make the photo stack look a little more realistic. I used CSS classes to rotate the images somewhere between -4 and 4 degrees and used jQuery to randomly assign one of those classes to each image when the DOM has loaded. Then I just added a CSS rule to rotate the image to 0 degrees on hover. </p>
<pre><code>#photo_stack .deg1 {
	-webkit-transform: rotate(1deg);
   	-moz-transform: rotate(1deg);
   	transform: rotate(1deg);
}
#photo_stack .deg2 {
	-webkit-transform: rotate(2deg);
   	-moz-transform: rotate(2deg);
   	transform: rotate(2deg);
}
#photo_stack .deg3 {
	-webkit-transform: rotate(3deg);
   	-moz-transform: rotate(3deg);
   	transform: rotate(3deg);
}
#photo_stack .deg4 {
	-webkit-transform: rotate(4deg);
   	-moz-transform: rotate(4deg);
   	transform: rotate(4deg);
}
#photo_stack .deg1neg {
	-webkit-transform: rotate(-1deg);
   	-moz-transform: rotate(-1deg);
   	transform: rotate(-1deg);
}
#photo_stack .deg2neg {
	-webkit-transform: rotate(-2deg);
   	-moz-transform: rotate(-2deg);
   	transform: rotate(-2deg);
}
#photo_stack .deg3neg {
	-webkit-transform: rotate(-3deg);
   	-moz-transform: rotate(-3deg);
   	transform: rotate(-3deg);
}
#photo_stack .deg4neg {
	-webkit-transform: rotate(-4deg);
   	-moz-transform: rotate(-4deg);
   	transform: rotate(-4deg);
}
#photo_stack .hover {
	-webkit-transform: rotate(0deg);
   	-moz-transform: rotate(0deg);
   	transform: rotate(0deg);
	cursor: pointer;
}</code></pre>
<p>I chose to use this approach, as it means that you can have any number of images in the stack, and they will be randomly rotated. If you wanted, you could just assign a specific angle to each photo in the stack using each images ID for complete control.</p>
<p>The full code for the animated photo stack can be found on the <a href="/demos/css3-animated-photo-stack.html">demo page</a>. It works best in the latest version of Chrome or Safari. Firefox works but without the animation and I did not even bother checking Internet Explorer &#8211; it always spoils the party!</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/05/28/css3-animated-photo-stack-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS display: inline-block &#8211; underused and underrated?</title>
		<link>http://pmbennett.net/2010/05/24/css-display-inline-block-underused-and-underrated/</link>
		<comments>http://pmbennett.net/2010/05/24/css-display-inline-block-underused-and-underrated/#comments</comments>
		<pubDate>Mon, 24 May 2010 13:55:30 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[inline-block]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=366</guid>
		<description><![CDATA[<p>Before I continue, I must point out this this is neither new or revolutionary; but it amazed me that after 6 years of front-end devlopement, I had never used the CSS2 <code>display: inline-block</code> selector. It's usefulness has been pointed out <a href="http://robertnyman.com/2010/02/24/css-display-inline-block-why-it-rocks-and-why-it-sucks/">many times in the past</a>, but I still thought that it would be worthwhile documenting my usage of it.</p>]]></description>
			<content:encoded><![CDATA[<p>What I basically wanted to do was to add an icon after a heading, that would always line-up next to the last word, regardless of the amount to text. For various reasons I was using a <code>span</code> element, to which I applied Mike Rundle&#8217;s Phark image replacement technique. However, in order for the <code>span</code> to obey any dimensions, it caould not be displayed <code>inline</code>. I started to think about how I would achieve this, and all my solutions were fairly longwinded for what would appear to be a pretty trivial task: that&#8217;s when I remembered the <code>inline-block</code> selector! Using this allowed me to give the <code>span</code> the desired dimensions, whilst allowing it to line-up against the text.</p>
<p>Unfortunately, this doesn&#8217;t work in IE6+7 or Firefox 2. But fear not, these can be addressed (at the expense of a stylesheet that no longer validates). Here is the code:</p>
<pre><code>h3 span {
	width: 16px;
	height: 16px;
	overflow: hidden;
	text-indent: -9999em;
	background: url(/img/secure_lock_icon.png) no-repeat 0 0;
	display: -moz-inline-stack;	/* Get FF2 to play nicely */
        display: inline-block;	/* Modern browsers get this */
	vertical-align: top;

	/* these go in your IE specific stylesheet to make it play fairly as well */
	zoom: 1;
        display: inline;
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/05/24/css-display-inline-block-underused-and-underrated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Animated Backgrounds with jQuery</title>
		<link>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/</link>
		<comments>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 18:37:40 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://pmbennett.net/?p=230</guid>
		<description><![CDATA[<p>I apologise in advance, a this is a very old technique, but it's something I have wanted to try out since last year. A while ago, I stumbled upon <a href="http://www.sunrisedesign.com/" target="_blank">Sunrise Design</a>, and absolutely loved the subtle background animation!</p>]]></description>
			<content:encoded><![CDATA[<p>Of course, this has been done many times before, but not in such an ethereal manner. So I have put together a not-so-subtle demo to have a go at this myself. I am not going to post the code here as this is very simple to achieve and hardly ground-breaking! If you want to see how this effect is achieved, you can view the source code of the demo.</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2010/01/12/animated-backgrounds-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with TypeKit</title>
		<link>http://pmbennett.net/2009/10/14/getting-started-with-typekit/</link>
		<comments>http://pmbennett.net/2009/10/14/getting-started-with-typekit/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 18:15:54 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Typography]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://pmbennett.net/articles/?p=86</guid>
		<description><![CDATA[I finally got my invite to <a href="http://typekit.com">TypeKit</a> today! I had to wait for an invite from a friend in the end. I must say, I see it as a great resource for the future.]]></description>
			<content:encoded><![CDATA[<p>I say that because until a large enough percentage of the population have moved over to a browser that supports @font-face, I doubt I will use it for any of the projects I am involved in.</p>
<p>I am a big fan of progressive enhancement, but a lot of clients still use IE6, and trying to tell them that they will only get the nice design and typography if they upgrade their browser just isn&#8217;t a realistic option. This is why I see it as a useful resource for the future. There is also the issue of reliability. Even the biggest and best sites have down time every now and then. Trying to explain this &#8220;bug&#8221; to a client will be a right pain.</p>
<p>On a positive note, this is a step in the right direction when it comes to using fonts legally on a website. It will help keep designers happy, as they will be able to use all the nice fonts and it will keep the font creators themselves happy, as they will get the credit and return they deserve.</p>
<p>It should also be said that the service is incredibly easy to use. Sign-up, choose your fonts, set your CSS hooks and copy-and-paste the supplied Javascript into the head of your HTML document. That is literally it! </p>
<p>I wait with eagerness for the first release of <a href="http://fontdeck.com">Font Deck</a> to see how it compares to TypeKit!</p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2009/10/14/getting-started-with-typekit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Bar Chart with jQuery</title>
		<link>http://pmbennett.net/2009/08/20/css-bar-chart-with-jquery/</link>
		<comments>http://pmbennett.net/2009/08/20/css-bar-chart-with-jquery/#comments</comments>
		<pubDate>Thu, 20 Aug 2009 15:12:00 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://pmbennett.net/articles/?p=75</guid>
		<description><![CDATA[I saw a flash bar chart the other day, which had a nice animation and looked very nice, and wondered if it would be possible to achieve a similar effect using just XHTML, CSS and a little bit of jQuery.]]></description>
			<content:encoded><![CDATA[<h4>Step 1: The Markup</h4>
<p>I started with a simple ordered list, which contained the text values which would represent the height of each bar on the chart. there are wrapped in a span which we will require in order to style this correctly in the CSS. </p>
<pre><code>&lt;div id="chart"&gt;
&lt;ol&gt;
	&lt;li id="green_bar"&gt;<span>450</span>&lt;/li&gt;
	&lt;li id="yellow_bar"&gt;<span>600</span>&lt;/li&gt;
	&lt;li id="red_bar"&gt;<span>300</span>&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;</code></pre>
<h4>Step 2: The <abbr title="Cascading Style sheets">CSS</abbr></h4>
<p>I then used some background images to create the graph and the 3D bars. The CSS specifies how high each bar should be and adds the background images. (This can be quite tricky as it requires a little bit of arithmetic to ensure that the bar is the correct height and the scales are consistent).</p>
<pre><code>#chart {
	background: #FFF url('../images/chart_bg.png') no-repeat 0 0;
	width: 636px;
	height: 420px;
}
#chart ol {
	margin: 0;
	padding: 0;
	list-style-type: none;
	position: relative;
	height: 420px;
	width: 636px;
	overflow: hidden;
}
#chart ol li {
	text-indent: -9999em;
	width: 140px;
	position: absolute;
	bottom: 0;
	background-repeat: no-repeat;
	background-position: -140px 0;
	background-color: transparent;
	padding: 38px 0 0 0;
}
#green_bar {
	height: 150px;
	background-image: url('../images/green_bar_top.png');
	left: 80px;
}
#green_bar span {
	background: transparent url('../images/green_bar.png') no-repeat left bottom;
	display: block;
	height: 150px;
}
#yellow_bar {
	height: 200px;
	background-image: url('../images/yellow_bar_top.png');
	left: 260px;
}
#yellow_bar span {
	background: transparent url('../images/yellow_bar.png') no-repeat left bottom;
	display: block;
	height: 200px;
}
#red_bar {
	height: 100px;
	background-image: url('../images/red_bar_top.png');
	left: 440px;
}
#red_bar span {
	background: transparent url('../images/red_bar.png') no-repeat left bottom;
	display: block;
	height: 100px;
}</code></pre>
<h4>Step 3: Adding some jQuery animation</h4>
<p>At this point we have a fairly nice looking three dimensional graph using only CSS and some markup: now to add the animation! All we need to do is position the bars below the x-axis using jQuery, and then add the animation that will slide them in. It&#8217;s pretty simple, but looks pretty nice. It does have it&#8217;s drawbacks, as the height of the highest bar needs to be known so that the chart background image can be created. Any dynamic graphs that are created on-the-fly will be difficult to create, but for one-off static graphs, this is a neat little effect.</p>
<pre><code>$(function() {
  // hide the bars to begin with
	$('#chart ol li').each(function() {
		$(this).css({'bottom': '-' + $(this).height() + 'px'});
		$(this).css({'background-position': '0 0'});
	});
  // animate the bars position to show on the graph
	$('&lt;p&gt;<a href="#">Show_results</a>&lt;/p&gt;').click(function() {
		$('#chart ol li').each(function() {
			$(this)
			.css({'background-position': '-140px 0'})
			.animate({
				bottom: '0px'
			}, 500);
		});
		return false;
	}).appendTo('body');
});</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2009/08/20/css-bar-chart-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fading Navigation Text with CSS &amp; jQuery</title>
		<link>http://pmbennett.net/2009/08/02/fading-navigation-text-with-css-jquery/</link>
		<comments>http://pmbennett.net/2009/08/02/fading-navigation-text-with-css-jquery/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 19:37:49 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://pmbennett.net/articles/?p=63</guid>
		<description><![CDATA[It's been a while since the last post, mainly because I haven't had anything to post about. However, recently, I wanted to achieve a fading effect when I hovered on the navigation elements of a website I was making. I could have just used jQuery to animate the color of the text using the <a href="http://plugins.jquery.com/project/color">color plugin</a> and that would be the end of it. Unfortunately, the designer used a non-standard font for the navigation, so I needed an alternative approach.]]></description>
			<content:encoded><![CDATA[<p>So I remembered reading <a href="http://snook.ca/archives/javascript/jquery-bg-image-animations/">an article by Jonathon Snook</a> and knew that I could do something similar to achieve this effect. So my approach was to use an image for each navigation element, which had the text cut out of it.</p>
<h4>Step 1: The Markup</h4>
<p><img class="f_left" src="/demos/images/illustration.png" alt="Illustration of how this technique works" />As with any navigation menu, I have started off with a simple list. Each list item needs a link inside it, and each of these links needs a span inside it. The span is required so that we can add the transparent cut-out text image on-top of the gradient background colour. Additionally, I have given each list item an id, as we need these hooks for the CSS and jQuery animation.</p>
<pre><code>&lt;ol&gt;
  &lt;li id="home"&gt;<a href="#"><span>home</span></a>&lt;/li&gt;
  &lt;li id="about"&gt;<a href="#"><span>about</span></a>&lt;/li&gt;
  &lt;li id="blog"&gt;<a href="#"><span>blog</span></a>&lt;/li&gt;
  &lt;li id="contact"&gt;<a href="#"><span>contact</span></a>&lt;/li&gt;
&lt;/ol&gt;</code></pre>
<h4>Step 2: The <abbr title="Cascading Style Sheets">CSS</a></h4>
<p>The CSS is actually straight forward: firstly, we add the gradient background image to the link, and then add the cut-out text image to the span nested inside of it. You will notice I have used the <a href="http://www.twinhelix.com/css/iepngfix/">iepngfix</a> hack to get the transparencies working in IE6 (Although without further workarounds, I believe the link won&#8217;t be clickable&#8230;meh!). I have included a hover state for these links, so that without Javascript, the color will still change, you just won&#8217;t get the fading animation.</p>
<pre><code>#navigation ol li {
	list-style-type: none;
	padding: 0;
	margin: 0;
	color: #FFF;
	width: 141px;
	float: left;
	padding: 0;
	height: 54px;
}
#navigation ol li a {
	text-decoration: none;
	display: block;
	width: 100%;
	height: 54px;
	padding: 0;
	margin: 0;
	color: #FFF;
	text-indent: -9999em;
	background-color: #FFF;
	background-position: 0 0;
	background-repeat: repeat-x;
	background-image: url('../images/nav_gradient.png');
}
#navigation ol li a:hover {
	background-position: 0 -162px;
}
#navigation ol li a span {
	display: block;
	background-color: transparent;
	background-repeat: no-repeat;
	background-position: 0 0;
	height: 54px;
	width: 100%;
	behavior: url('../js/iepngfix.htc');
}
#navigation ol li#home a span {
	background-image: url('../images/home_tab.png');
}
#navigation ol li#about a span {
	background-image: url('../images/about_tab.png');
}
#navigation ol li#blog a span {
	background-image: url('../images/blog_tab.png');
}
#navigation ol li#contact a span {
	background-image: url('../images/contact_tab.png');
	width: 141px;
}</code></pre>
<h4>Step 3: The jQuery Animation</h4>
<p>This is incredibly simple: all you need to do is define a hover function for each link, and then animate the background position when the mouse is moved over and out of the link. <strong>Note: </strong>In order to get background animations to work, you will need to download and include the <a href="http://plugins.jquery.com/project/backgroundPosition-Effect">background position plugin</a>.</p>
<pre><code>$(function() {
	$('#navigation ol li a')
	.css({backgroundPosition: '0 0'})
	.hover(
		function () {
			$(this).stop().animate(
				{backgroundPosition: '(0 -162px)'},
				{duration: 500}
			);
		},
		function () {
			$(this).stop().animate(
				{backgroundPosition: '(0 0)'},
				{duration: 400}
			);
		}
	);
});</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2009/08/02/fading-navigation-text-with-css-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS Polls</title>
		<link>http://pmbennett.net/2009/06/07/css-polls/</link>
		<comments>http://pmbennett.net/2009/06/07/css-polls/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 10:49:18 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://pmbennett.net/articles/?p=43</guid>
		<description><![CDATA[A number of websites I have been involved in recently have required a poll, where users can vote and see the overall results in the form of a graph. In this post, I will describe my approach to this.]]></description>
			<content:encoded><![CDATA[<p>Firstly, we have the XHTML markup. I have chosen to use an ordered list, with some additional markup to provide enough hooks for the CSS:</p>
<pre><code>&lt;ol&gt;
 &lt;li&gt;
  <strong><em style="width: 54%;">54%</em></strong>
  <span>Option 1</span>
 &lt;/li&gt;
 &lt;li&gt;
  <strong><em style="width: 22%;">22%</em></strong>
  <span>Option 2</span>
 &lt;/li&gt;
 &lt;li&gt;
  <strong><em style="width: 14%;">14%</em></strong>
  <span>Option 3</span>
 &lt;/li&gt;
 &lt;li class="last"&gt;
  <strong><em style="width: 10%;">10%</em></strong>
  <span>Option 4</span>
 &lt;/li&gt;
&lt;/ol&gt;</code></pre>
<p>Now that we have enough hooks, we can apply our style to achieve this graphical representation of the poll results. These pages are generated by a CMS, and the percentage values are variables populated for a database. Therefore, to achieve this, inline styles are needed to set the graph bars to the appropriate widths. It is a bit annoying that you can&#8217;t completely separate the presentation from the mark-up, but I think it is a small price to pay, for a nice effect.</p>
<pre><code>#pollWrapper {
 width: 800px;
 padding: 1em 0;
 overflow: hidden;
 height: auto;
}

#pollWrapper ol {
 list-style-type: none;
 margin: 0;
 padding: 2px;
 position: relative;
 border: 1px solid #CCC;
}

#pollWrapper ol li {
 overflow: hidden;   /* clear floats in modern browsers */
 zoom: 1;    /* clear floats in IE6 - put in external stylesheet */
 font-size: 0.75em;
 margin: 0 0 2px 0;
}

#pollWrapper ol li.last {
 margin: 0;
}

#pollWrapper ol li strong {
 width: 200px;
 margin-right: 10px;
 padding: 1px;
 float: left;
 display: inline;
 background: #FAFAFA;
}

#pollWrapper ol li em {
 display: block;
 background: #CCC;
 color: #333;
 text-indent: 2px;
}

#pollWrapper ol li span {
 width: 582px;
 float: left;
}</code></pre>
<p class="articleLinks"><a href="/articles/demos/css-polls.html" target="_blank">View demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2009/06/07/css-polls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remote linking with a twist</title>
		<link>http://pmbennett.net/2009/06/04/remote-linking-with-a-twist/</link>
		<comments>http://pmbennett.net/2009/06/04/remote-linking-with-a-twist/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 19:46:08 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[XHTML]]></category>

		<guid isPermaLink="false">http://pmbennett.net/articles/?p=14</guid>
		<description><![CDATA[Recently, I came across a scenario where a client wanted a list of links which would link to certain areas of the site. Additionally, they wanted to add a roll-over effect, where an image would change depending what link the mouse was hovering over. Without giving it a thought, I initially began to write some jQuery to do the trick, which would have been fine; but then I came across <a href="http://css-tricks.com/remote-linking/">Chris Coyier's remote linking article</a>, and thought that I could build upon this to provide me with a CSS only solution.]]></description>
			<content:encoded><![CDATA[<p>There isn&#8217;t too much to this: it makes use of positioning and z-index to achieve this. Firstly we have the mark-up, which basically embeds each image, with the link text inside the anchor itself:</p>
<pre><code>&amp;lt;ol&amp;gt;
    &amp;lt;li&amp;gt;
        &amp;lt;a id="red"&amp;gt;Red Square
            &amp;lt;img src="images/red_square.png" alt="Red Square" /&amp;gt;
        &amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;
        &amp;lt;a id="yellow"&amp;gt;Yellow Circle
            &amp;lt;img src="images/yellow_circle.png" alt="Yellow Square" /&amp;gt;
        &amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;
        &amp;lt;a id="green"&amp;gt;Green Triangle
            &amp;lt;img src="images/green_triangle.png" alt="Green Triangle" /&amp;gt;
        &amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;
        &amp;lt;a id="blue"&amp;gt;Blue Hexagon
            &amp;lt;img src="images/blue_hexagon.png" alt="Blue Hexagon" /&amp;gt;
        &amp;lt;/a&amp;gt;&amp;lt;/li&amp;gt;
&amp;lt;/ol&amp;gt;</code></pre>
<p>And the CSS, where the magic happens:</p>
<pre><code>#linksWrapper ol {
	list-style-type: none;
	margin: 0;
	padding: 0;
	position: relative;
}
#linksWrapper ol li {
	width: 180px;
}
#linksWrapper ol li a {
	text-decoration: none;
	padding: 0.25em 10px;
	display: block;
	color: #000;
	width: 160px;
}
#linksWrapper ol li a img {
	position: absolute;
	top: 0;
	left: 180px;
	z-index: 100;
	border: none;
}
#linksWrapper ol li a#red img {
	z-index: 500;
}
#linksWrapper ol li a#yellow:hover {
	background-color: #FFFC00;
	color: #000;
}
#linksWrapper ol li a#red:hover {
	background-color: #FF0000;
	color: #FFF;
}
#linksWrapper ol li a#green:hover {
	background-color: #24EA44;
	color: #FFF;
}
#linksWrapper ol li a#blue:hover {
	background-color: #2B99F6;
	color: #FFF;
}
#linksWrapper ol li a:hover img {
	z-index: 1000;
}</code></pre>
<p class="articleLinks"><a target="_blank" href="/demos/remote-linking-with-a-twist.html">View demo</a></p>
]]></content:encoded>
			<wfw:commentRss>http://pmbennett.net/2009/06/04/remote-linking-with-a-twist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

