<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Web International Awards &#187; code</title>
	<atom:link href="http://www.webia.info/category/articles/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.webia.info</link>
	<description></description>
	<lastBuildDate>Tue, 09 Aug 2011 15:42:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Coding a simple slider in no time</title>
		<link>http://www.webia.info/articles/code/coding-a-simple-slider-in-no-time/</link>
		<comments>http://www.webia.info/articles/code/coding-a-simple-slider-in-no-time/#comments</comments>
		<pubDate>Tue, 10 May 2011 15:00:51 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[article]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[lightweight]]></category>
		<category><![CDATA[simple]]></category>
		<category><![CDATA[slider]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1879</guid>
		<description><![CDATA[

We've published a couple of articles on sliders in the past. We first had a tutorial on building a XML powered slider, then we released the source codes and demo for the xml slider and we finally released the latest revision as the xml slider plugin. Today we're going back to basics, as I am [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2011/05/simple_slider.jpg"><img src="http://www.webia.info/wp-content/uploads/2011/05/simple_slider.jpg" alt="simple slider" title="simple slider" width="540" height="250" class="alignnone size-full wp-image-1868" /></a></p>
<p>
We've published a couple of articles on sliders in the past. We first had a <a href="http://www.webia.info/articles/tutorials/make-your-own-jquery-slider-using-xml/">tutorial on building a XML powered slider</a>, then we released the <a href="http://www.webia.info/articles/tutorials/awesome-slider-demo-and-source-codes/">source codes and demo for the xml slider</a> and we finally released the latest revision as the <a href="http://products.webraptor.eu/AwesomeSlider/">xml slider plugin</a>. Today we're going back to basics, as I am going to show you how to make a rather simple, lightweight slider in no time. Here's a <a href="http://demos.webia.info/simple_slider/">demo</a> of what we're building today.
</p>
<h2>HTML structure</h2>
<p>This structure will retain and contain the actual thumbs which will be displayed as the slider's content. As you'll probably figure out, I am using the <a href="http://960.gs/">960gs</a> to keep the structural integrity as simple as possible.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;wrapper&quot; class=&quot;container_12&quot;&gt;
&nbsp;
	&lt;div id=&quot;featured-wrapper&quot; class=&quot;grid_12 all-rounded&quot;&gt;
		&lt;div class=&quot;arrowleft&quot;&gt;&amp;nbsp;&lt;/div&gt;
		&lt;div id=&quot;featured-thumb&quot; class=&quot;grid_12 alpha omega all-rounded&quot;&gt;	
			&lt;ul id=&quot;featured-thumb-list&quot;&gt;
&nbsp;
			&lt;/ul&gt;	
		&lt;/div&gt;
		&lt;div class=&quot;arrowright&quot;&gt;&amp;nbsp;&lt;/div&gt;
		&lt;div class=&quot;clear&quot;&gt;&amp;nbsp;&lt;/div&gt;
	&lt;/div&gt;
&lt;/div&gt;</pre></td></tr></table></div>



<p>
The <em>wrapper</em> is used to hold the entire contents of the page in the center of it. <em>featured-wrapper</em> will hold the next, previous arrows as well as the <em>featured-thumb</em> div that wraps the thumbnail list. <em>featured-thumb</em> will have overflow set to hidden so that only a couple of thumbs are shown at a time. The unordered list will be shifting left to right when users click the arrows to reveal other caricatures. Before we get there, here's the code that is used to display the thumbs. The following piece of code will be repeated inside the unordered list depending on how many thumbs we want to display.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;li class=&quot;grid_2&quot;&gt;
	&lt;a href=&quot;#&quot; class=&quot;all-rounded&quot;&gt;
		&lt;img src=&quot;thumb_featured.png&quot; width=&quot;120&quot; height=&quot;150&quot; alt=&quot;caption title&quot; class=&quot;all-rounded&quot; /&gt;
		caption title
	&lt;/a&gt;
&lt;/li&gt;</pre></td></tr></table></div>



<h2>Styling the slider with a sprinkle of css</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#featured-wrapper</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">35px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">207px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-wrapper</span> <span style="color: #6666ff;">.arrowleft</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: #00AA00;">;</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;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">49px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">61px</span><span style="color: #00AA00;">;</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;">;</span> <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">-25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">55px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'arrow_left.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-wrapper</span> <span style="color: #6666ff;">.arrowright</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: #00AA00;">;</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;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">49px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">61px</span><span style="color: #00AA00;">;</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;">;</span> <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span><span style="color: #933;">-27px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">55px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">100</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'arrow_right.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-thumb</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: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#FFF</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</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;">;</span> <span style="color: #000000; font-weight: bold;">z-index</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">50</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</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;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-thumb-list</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;">20000px</span><span style="color: #00AA00;">;</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;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-thumb-list</span> li a <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#featured-thumb-list</span> li img <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F1F1F1</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">10px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>



<p>
I left out the code for the grid system. What this piece of css does is it sets the width and heigh of the div that wraps the slider controls and content, it positions the arrows and displays their background images (I used background images for the arrow design). It also sets the structure and overflow of the <em>featured-thumb</em> div that wraps the list of thumbnails. Finally, it applies some basic styles to the thumbnail placeholder and the links used for each thumbnail.
</p>
<h2>jQuery functionality</h2>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> featured_thumb<span style="color: #009900;">&#40;</span>maxwidth<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>	<span style="color: #006600; font-style: italic;">// featured thumb functionality</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">typeof</span> maxwidth<span style="color: #339933;">==</span><span style="color: #3366CC;">'undefined'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">||</span><span style="color: #009900;">&#40;</span>maxwidth<span style="color: #339933;">==</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>maxwidth<span style="color: #339933;">=</span><span style="color: #CC0000;">900</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.arrowright'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#featured-thumb-list&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;margin-left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&lt;=-</span>maxwidth<span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			    <span style="color: #3366CC;">'margin-left'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'-'</span><span style="color: #339933;">+</span>maxwidth
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #006600; font-style: italic;">// Animation complete.</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			    <span style="color: #3366CC;">'margin-left'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'-=160'</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #006600; font-style: italic;">// Animation complete.</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.arrowleft'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">live</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'click'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> Math.<span style="color: #660066;">round</span><span style="color: #009900;">&#40;</span>parseFloat<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#featured-thumb-list&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;margin-left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #CC0000;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">&gt;=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			    <span style="color: #3366CC;">'margin-left'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'0'</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #006600; font-style: italic;">// Animation complete.</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">else</span>
		<span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#featured-thumb-list'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
			    <span style="color: #3366CC;">'margin-left'</span><span style="color: #339933;">:</span> <span style="color: #3366CC;">'+=160'</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">500</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			    <span style="color: #006600; font-style: italic;">// Animation complete.</span>
			  <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #006600; font-style: italic;">// end featured thumb functionality</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">ready</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	featured_thumb<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">850</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>
In the above javascript snippet we define a function which adds the required functionality to the slider. Its sole parameter is the <em>maxwidth</em> variable, which is the maximum width of the margin-left property which is modified to move the thumbnail inside the placeholder. So if the placeholder is 800 px in width and the <em>maxwidth</em> variable set to 850, the thumbs will move around in a 1650 box. There are two onclick events (lines 4 and 24) which basically trigger the same functionality that is applied in opposite directions (left and right). To move left, we add pixels to left margin. To move right, we subtract from the left margin.
</p>
<p>Because the margin-left attribute is defined as <em>X px;</em>, where <em>X</em> is a number, we parse this value into a float (to allow negative values also), then we round the number (to prevent anything bad going on) and compare the value with 0 or <em>maxwidth</em> depending on the direction we're headed to. If we're going left and by clicking the left arrow the margin would become greater than 0, we have reached the end of the slider and we therefor stop the animation from sliding the content even further. If you try many repeated clicks you'll  this code will even perform an effect similar to a bouncing effect. Similarly, if moving the content to the right, the margin is compared to negative <em>maxwidth</em> (<=-maxwidth). If we reach this threshold, once again we're at the end of the thumbnails box and the animation needs to be stopped to prevent moving the thumbnails further.
</p>
<p>
To conclude, I guess that in order to reduce the size of the code one can write an extra function for the <em>onclick</em> behavior and call it when needed instead of copy pasting it into each of the events and doing the minor customization I've done.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/code/coding-a-simple-slider-in-no-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Start passenger standalone on server restart or on service failure</title>
		<link>http://www.webia.info/articles/code/start-passenger-standalone-on-server-restart-or-on-service-failure/</link>
		<comments>http://www.webia.info/articles/code/start-passenger-standalone-on-server-restart-or-on-service-failure/#comments</comments>
		<pubDate>Tue, 03 May 2011 15:00:12 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cronjob]]></category>
		<category><![CDATA[health]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[passenger standalone]]></category>
		<category><![CDATA[phusion]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[reboot]]></category>
		<category><![CDATA[rubyonrails]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=1854</guid>
		<description><![CDATA[
We've had this problem with our own servers and rails apps running on Passenger standalone and turns out there are a lot of you experiencing the same problems from time to time. This short tutorial will help you solve the following problems:


How can I keep Passenger Standalone up even after a server restart?
How do I [...]]]></description>
			<content:encoded><![CDATA[<p>
We've had this problem with our own servers and rails apps running on Passenger standalone and turns out there are a lot of you experiencing the same problems from time to time. This short tutorial will help you solve the following problems:
</p>
<ol>
<li>How can I keep Passenger Standalone up even after a server restart?</li>
<li>How do I run health checks on Passenger Standalone?</li>
<li>How do I automatically restart and spawn a rails app if it crashes under Passenger Standalone?</li>
</ol>
<p>
There are a number of fixes for the above issues, but there isn't a simple one to fix all in one. Or at least I haven't come across any of them. One fix for the first problem was placing a script in <em>/etc/init</em> so that passenger would start when the server is rebooted. This however didn't fix the other two issues as it would only start Passenger when the entire server would start, meaning Passenger wouldn't be started if for example the server ran out of memory, something crashed the rails apps etc.
</p>
<p>
The best fix I could think of was creating a script that checks whether Passenger standalone is running every minute and if it isn't, then start it. This fix would work for all scenarios: server reboot, application crash. Moreover, as the script would run as a cronjob every minute, it would also perform a health check on all running apps. Here's the code for the script.
</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>lsof <span style="color: #660033;">-i</span> :<span style="color: #000000;">13007</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP1<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">test</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP1<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #666666; font-style: italic;"># passenger down</span>
    <span style="color: #c20cb9; font-weight: bold;">date</span>
    . <span style="color: #ff0000;">&quot;/usr/local/rvm/scripts/rvm&quot;</span>
    rvm use 1.9.2
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP1<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>
    passenger start <span style="color: #660033;">-a</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">13007</span> <span style="color: #660033;">-d</span> <span style="color: #660033;">-e</span> production <span style="color: #660033;">--user</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>lsof <span style="color: #660033;">-i</span> :<span style="color: #000000;">13008</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP2<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">test</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP2<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>;
  <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #666666; font-style: italic;"># passenger down</span>
    <span style="color: #c20cb9; font-weight: bold;">date</span>
    . <span style="color: #ff0000;">&quot;/usr/local/rvm/scripts/rvm&quot;</span>
    rvm use 1.9.2
    <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>rails_apps<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>APP2<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>
    passenger start <span style="color: #660033;">-a</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">13008</span> <span style="color: #660033;">-d</span> <span style="color: #660033;">-e</span> production <span style="color: #660033;">--user</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>USER<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>



<p>
The above example is for a server running two apps on Passenger Standalone behind apache on ports 13007 and 13008. Replace <em>{USER} , {APP1}, {APP2}</em> with your own configuration. Once you've written your file, save it to <em>/home/{USER}/rails_apps/health_check.sh</em> and then add a cronjob to run it every minute, 5 minutes or whenever you want.
</p>
<p>
The code above checks whether there are any processes listening on the ports defined for each app. If there is a single process, the output will be written to a file which will have a file size greater than 0. If there are no processes listening on that port, the file size will be 0. The next step is to check the file size. If it is 0, our app is not running and we can start it. Simple as that. And it works for reboots, crashes, integrity and health checks and more. 
</p>
<p>
If you're wondering what's with the date command, here's the answer. In my cronjob I've set the output of the command to  <em>/home/{USER}/rails_apps/health_check.log</em>. If any app is started (meaning it was down for some reason) I will have the info and the timestamp in the log. I can then look throughout the apache / nginx / rails logs at that specific timestamp and identify the problem that caused the app to crash, if there were any bugs.
</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/code/start-passenger-standalone-on-server-restart-or-on-service-failure/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Enhance your clients list page with jQuery goodness</title>
		<link>http://www.webia.info/articles/code/enhance-your-clients-list-with-jquery-goodness/</link>
		<comments>http://www.webia.info/articles/code/enhance-your-clients-list-with-jquery-goodness/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 15:36:48 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[tutorials]]></category>
		<category><![CDATA[client list]]></category>
		<category><![CDATA[enhance]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[usability]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=881</guid>
		<description><![CDATA[
I have seen a lot of web development companies, or for that matter, companies that offer IT services having a dull client list page. They usually reside to a logo showcase or a text list divided into multiple columns. This later design is what we will try to achieve in this tutorial, but we will [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/11/clients_list.jpg" title="Clients list demo preview"><img src="http://www.webia.info/wp-content/uploads/2009/11/clients_list.jpg" alt="clients list demo preview" /></a></p>
<p>I have seen a lot of web development companies, or for that matter, companies that offer IT services having a dull client list page. They usually reside to a logo showcase or a text list divided into multiple columns. This later design is what we will try to achieve in this tutorial, but we will also add a service list, and map the two lists together. Pointing to a service will reveal clients that bought that service while pointing to a client will reveal services bought by that client. We will use jQuery to map the two together.</p>
<h2>The HTML</h2>
<p>I will be using HTML 5 tags for this tutorial, which means what we are building here will only work on modern browsers. However, it's just a few tags and a doctype that need to be changed to make it work on every browser. The structure of the file will be consisted of two HTML 5 tags: <em>header</em> and <em>section</em>. Enough talk, here's the code:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;header class=&quot;top-rounded&quot;&gt;
	&lt;!-- this is the horizontal bar with the gradient--&gt;
	&lt;h1&gt;Services&lt;/h1&gt;
	&lt;h2&gt;Clients&lt;/h2&gt;
&lt;/header&gt;
&lt;section&gt;
	&lt;ul class=&quot;services btlft-rounded&quot;&gt;
		&lt;!-- this is the section that will hold the services--&gt;
		&lt;li&gt;Systems Development
			&lt;ul&gt;
				&lt;li class=&quot;ubn&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Business Needs&lt;/a&gt;&lt;/li&gt;
				&lt;li class=&quot;dd&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Design &amp;amp; Development&lt;/a&gt;&lt;/li&gt;
				&lt;li class=&quot;ti&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Test &amp;amp; Implement&lt;/a&gt;&lt;/li&gt;
			&lt;/ul&gt;
		&lt;/li&gt;
		&lt;li&gt;Design &amp;amp; Branding
			&lt;ul&gt;
				&lt;li class=&quot;mr&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Market Research&lt;/a&gt;&lt;/li&gt;
				&lt;li class=&quot;bs&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Business Strategy&lt;/a&gt;&lt;/li&gt;
				&lt;li class=&quot;ci&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Corporate Identity&lt;/a&gt;&lt;/li&gt;
				&lt;li class=&quot;obp&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Online Brand Presence&lt;/a&gt;&lt;/li&gt;
				&lt;li class=&quot;ue&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;User Experience&lt;/a&gt;&lt;/li&gt;
				&lt;li class=&quot;ia&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Information Architecture&lt;/a&gt;&lt;/li&gt;
				&lt;li class=&quot;ad&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Application Development&lt;/a&gt;&lt;/li&gt;
			&lt;/ul&gt;
		&lt;/li&gt;
	&lt;/ul&gt;
	&lt;ul class=&quot;clients btrght-rounded&quot;&gt;
		&lt;!-- this is the section that will hold all clients --&gt;
		&lt;li class=&quot;dd ti&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Nike&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;ubn di ti&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Adidas&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;dd&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Hugo Boss&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;ci ad&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Canal +&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;mr bs ci obp&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;TV shop plus&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;ad&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;CBS&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;ia&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;NBC&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;mr bs ci ue ia ad&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;GOL TV&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;ia ad&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;Petrom&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;ue ia ad&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;OMV&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;ci obp&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;La pizza&lt;/a&gt;&lt;/li&gt;
		&lt;li class=&quot;mr&quot;&gt;&lt;a href=&quot;#&quot; class=&quot;&quot;&gt;The shop&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
&lt;/section&gt;</pre></td></tr></table></div>



<p>As you see in the code above, each list item has a various number of classes. These classes are used to identify services and to map services to clients and viceversa. The class attribute in the anchor tags is used to emphasize which clients or services are selected. With that said it is time to move on to some basic styling.</p>
<h2>The CSS</h2>
<p>I will use some rounded corners instructions, but apart from that everything else is pretty simple. Here's the CSS code</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* reset basic styling and set rounded corners */</span>
<span style="color: #00AA00;">*</span>
<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #993333;">inherit</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
.all-rounded<span style="color: #00AA00;">,</span>
ul<span style="color: #6666ff;">.services</span> li a<span style="color: #00AA00;">,</span>
ul<span style="color: #6666ff;">.clients</span> li a			
<span style="color: #00AA00;">&#123;</span> border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -moz-border-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -webkit-border-radius<span style="color: #00AA00;">:</span> <span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btlft-rounded</span>			
<span style="color: #00AA00;">&#123;</span> border-bottom-left-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -moz-border-radius-bottomleft<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -webkit-border-bottom-left-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.btrght-rounded</span>			
<span style="color: #00AA00;">&#123;</span> border-bottom-right-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -moz-border-radius-bottomright<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -webkit-border-bottom-right-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #6666ff;">.top-rounded</span>			
<span style="color: #00AA00;">&#123;</span> border-top-left-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -moz-border-radius-topleft<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -webkit-border-top-left-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> 
border-top-right-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -moz-border-radius-topright<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> -webkit-border-top-right-radius<span style="color: #00AA00;">:</span><span style="color: #933;">9px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* styling of the general structure: size, position and alike */</span>
header
<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;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">801px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</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;">#888</span><span style="color: #00AA00;">;</span>  <span style="color: #000000; font-weight: bold;">border-bottom</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
header h1<span style="color: #00AA00;">,</span> header h2
<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;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
header h1
<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;">;</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;">;</span> <span style="color: #00AA00;">&#125;</span>
section	
<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;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">803px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">50px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">auto</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul
<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;">;</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;">;</span> <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding-bottom</span><span style="color: #00AA00;">:</span><span style="color: #933;">15px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.services</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;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.clients</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;">600px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* visual styling: colors, font size etc */</span>
header
<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#999</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../images/top.png'</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">repeat-x</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
header h1<span style="color: #00AA00;">,</span> header h2
<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F6F6F6</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">40px</span><span style="color: #00AA00;">;</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;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.services</span>
<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#999</span><span style="color: #00AA00;">;</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;">#888</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.clients</span>
<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F0F0F0</span><span style="color: #00AA00;">;</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;">#888</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
ul<span style="color: #6666ff;">.services</span> a<span style="color: #00AA00;">,</span> ul<span style="color: #6666ff;">.clients</span> a
<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.services</span> li 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;">block</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#F0F0F0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">23px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</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;">#999</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.services</span> li a<span style="color: #3333ff;"><span style="color: #00AA00;">:</span>hover
</span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#222222</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</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;">#222222</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#999</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../images/hover_services.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.services</span> li ul		
<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.services</span> li			
<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;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
ul<span style="color: #6666ff;">.clients</span> li 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;">block</span><span style="color: #00AA00;">;</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;">;</span> <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">138px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">23px</span><span style="color: #00AA00;">;</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;">;</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;">#F0F0F0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
ul<span style="color: #6666ff;">.clients</span> li a<span style="color: #3333ff;"><span style="color: #00AA00;">:</span>hover
</span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#222222</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</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;">#222222</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#999</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../images/hover_services.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
ul<span style="color: #6666ff;">.services</span> li a.selected<span style="color: #00AA00;">,</span>
ul<span style="color: #6666ff;">.clients</span> li a<span style="color: #6666ff;">.selected</span>
<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#222222</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span><span style="color: #933;">25px</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">0px</span> <span style="color: #933;">5px</span><span style="color: #00AA00;">;</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;">#222222</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#999</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000;">'../images/hover_services.png'</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>



<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/11/clients_list_issues.jpg" title="Clients list demo, columns of unequal height"><img src="http://www.webia.info/wp-content/uploads/2009/11/clients_list_issues.jpg" alt="Clients list demo, columns of unequal height" /></a></p>
<p>And <a href="http://demos.webia.info/clients_list/demo1.html" target="_new">here is a demo</a> of how what we coded looks like. Being done with HTML and CSS, we move forward to jQuery coding to map services and clients together.</p>
<h2>The jQuery</h2>
<p>As you've seen in the demo the two columns do not share the same height. If you have many services and few clients, or few services and lots of clients, it is very likely that the two columns will not be of equal height. We can easily fix that with the following jQuery code:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// resize column for same height</span>
<span style="color: #003366; font-weight: bold;">var</span> servicesHeight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.services'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// get height of services ul</span>
<span style="color: #003366; font-weight: bold;">var</span> clientsHeight <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.clients'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// get height of clients ul</span>
<span style="color: #006600; font-style: italic;">// check who's bigger and set height accordingly</span>
<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>servicesHeight<span style="color: #339933;">&gt;</span>clientsHeight<span style="color: #009900;">&#41;</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.clients'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span>servicesHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
   <span style="color: #000066; font-weight: bold;">else</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.services'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">height</span><span style="color: #009900;">&#40;</span>clientsHeight<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>You can <a href="http://demos.webia.info/clients_list/demo2.html" target="_new">view a demo</a> with the equal height columns problem solved. Next piece of code is the one creating the behavior necessary when clicking on services.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// if services on the left are clicked</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.services a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.selected'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// a service is clicked, make any, if selected, as not selected</span>
   <span style="color: #006600; font-style: italic;">// when we click one service we need to emphasize that it is selected</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// set current link as selected	</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">// get the services classes</span>
   <span style="color: #003366; font-weight: bold;">var</span> classesString  <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> classes <span style="color: #339933;">=</span> classesString.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// now classes contains all class attributes of the service clicked</span>
   <span style="color: #006600; font-style: italic;">// loop through all classes</span>
   <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&lt;</span> classes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">// set selected to all clients that have such a service</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.clients li.'</span><span style="color: #339933;">+</span>classes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">' a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>When clicking a client, same thing happens but exactly the other way. We first get the class attribute of the client to check out the services bought and then loop through those services and set them as selected. Pretty neat! Here's the code:</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">// if clients on the right are clicked</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.clients li a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.selected'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// a client is clicked, make any, if selected, as not selected</span>
   <span style="color: #006600; font-style: italic;">// when we click one client we need to emphasize that it is selected</span>
   $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// set current link as selected	</span>
&nbsp;
   <span style="color: #006600; font-style: italic;">// get the client's classes</span>
   <span style="color: #003366; font-weight: bold;">var</span> classesString  <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">parent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">var</span> classes <span style="color: #339933;">=</span> classesString.<span style="color: #660066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">// now classes contains all class attributes of the client clicked</span>
   <span style="color: #006600; font-style: italic;">// loop through all classes</span>
   <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i<span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #339933;">;</span>i <span style="color: #339933;">&lt;</span> classes.<span style="color: #660066;">length</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
      <span style="color: #006600; font-style: italic;">// set selected to all services that were bought by the client</span>
      $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.services li.'</span><span style="color: #339933;">+</span>classes<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #3366CC;">' a'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'class'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'selected'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>



<p>And we're done. You can check out the <a href="http://demos.webia.info/clients_list/final.html" target="_new">final demo over here</a> and download the <a href="http://demos.webia.info/clients_list/clients_list.zip">source codes over here</a>. If you enjoyed this article you can stay updated to new content via our <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">RSS feed</a> or by <a href="http://feedburner.google.com/fb/a/mailverify?uri=WebInternationalAwards&#038;loc=en_US" target="_new">email</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/code/enhance-your-clients-list-with-jquery-goodness/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Graceful flash degradation, reloaded!</title>
		<link>http://www.webia.info/articles/graceful-flash-degradation-reloaded/</link>
		<comments>http://www.webia.info/articles/graceful-flash-degradation-reloaded/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 11:07:25 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[articles]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[techniques]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[degradation]]></category>
		<category><![CDATA[html]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=582</guid>
		<description><![CDATA[
A couple of weeks ago I talked about graceful flash degradation: what it means, issues that arise while developing in flash, and how to fix them properly. This is the second article on the topic. Before we continue, make sure you're familiar with the first article on flash degradation, because this article contains examples to [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/09/nyt_flash.jpg" title="New York Times Photojournalism section: flash version"><img src="http://www.webia.info/wp-content/uploads/2009/09/nyt_flash.jpg" alt="NYT photojournalism section, flash version" /></a></p>
<p>A couple of weeks ago I talked about graceful flash degradation: what it means, issues that arise while developing in flash, and how to fix them properly. This is the second article on the topic. Before we continue, make sure you're familiar with the first article on <a href="http://www.webia.info/articles/usability/graceful-flash-degradation/">flash degradation</a>, because this article contains examples to emphasize what the previous article described.</p>
<h2>Good flash degradation from New York Times</h2>
<p>We previously stumbled upon UEFA's site and a wine company's website. Today we are looking upon a newspaper's website. The name is self explanatory, New York Times being the largest metropolitan newspaper published in the United States. Having that weight attached to their necks, they knew their online presence must be perfect. And it is. </p>
<p>New York Times has an online photojournalism section which is built in flash. It is consisted of a series of posts, each around an image. Each post has apart from the image, a brief paragraph describing the picture, where it was taken and so on. A nice feature is the small sneak peak to the next and previous articles, which are visible in the left and right sidebars of the article you are currently viewing. However, I don't think this was a feature they specifically developed, as the full screen mode lacks it.</p>
<p>What really matters here is that they also have a non flash version of the site which kicks in if you do not have the necessary plugins. They also let you know that if you want to fully enjoy the features of the site, you should install flash player. Flawless solution. Great job for New York Times, but perhaps more congrats should go to the site developers, whoever they are.</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/09/nyt_non_flash.jpg" title="New York Times Photojournalism section: non-flash version"><img src="http://www.webia.info/wp-content/uploads/2009/09/nyt_non_flash.jpg" alt="NYT photojournalism section, non-flash version" /></a></p>
<p>If you have any other examples or pointers please leave them in the comments section bellow. If you liked this article you can subscribe to the full content <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">rss feed</a> and stay updated as we post new information.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/graceful-flash-degradation-reloaded/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Graceful flash degradation</title>
		<link>http://www.webia.info/articles/usability/graceful-flash-degradation/</link>
		<comments>http://www.webia.info/articles/usability/graceful-flash-degradation/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 14:18:00 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[techniques]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[degradation]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=487</guid>
		<description><![CDATA[
It has been quite some time since I last wrote an article here, and I hope you all enjoyed the summer and summer holiday. I read a lot of blogs each day and I must say that there's a decent amount of articles about javascript, content, and how to properly code a site when using [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/09/uefa_flash.jpg"><img src="http://www.webia.info/wp-content/uploads/2009/09/flashplayerlogo.jpg" alt="flash player logo on artwork" /></a></p>
<p>It has been quite some time since I last wrote an article here, and I hope you all enjoyed the summer and summer holiday. I read a lot of blogs each day and I must say that there's a decent amount of articles about javascript, content, and how to properly code a site when using javascript. You have to be careful because of those people who disable javascript or use old browsers that don't have such features. However, I haven't seen any articles describing some short guidelines as to what you should do when developing a site in flash.</p>
<h2>Issues with flash developing</h2>
<p>The first issue that has to be taken into consideration here is that while many people have flash player installed, its version may be an older one, and the site or web app you are building with flash 10 may not work correctly, or at all on some people's computers. Moreover, there are individuals that don't have flash player installed, just like the ones without javascript. </p>
<h2>How to handle flash generated problems</h2>
<p>The easiest option would be to develop a html version of the site. Though this is ok, the costs of such a solution grow as the site grows. This is ok for small sites or sites that are not updated frequently. What happens when you have a big site, with content updated on a daily basis?</p>
<span id="more-487"></span>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/09/uefa_flash.jpg"><img src="http://www.webia.info/wp-content/uploads/2009/09/uefa_flash.jpg" alt="eufa.com screenshot" /></a></p>
<p>One interesting solution, which I definitely like is the one adopted by UEFA (Union of European Football Associations). Their website is not entirely flash, but has many flash sections. One of them is a content slider, which could have been built using javascript. They used flash and that is ok too, but how they fix search engine issue that come by using flash. How can people using mobile devices like the iPhone - which doesn't have flash - browse their website and read valuable content?</p>
<p>The solution is quite simple. UEFA's website displays all content headlines as plain text. Those headlines were previously bundled with images in the flash content slider. Moreover, the headlines appear in the same area of the site, leaving the layout uncrippled. Another important feature is that they also display a small button telling their visitors that if they want to fully enjoy the site they should install flash player. They also link to Adobe's download page.</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/09/uefa_non_flash.jpg"><img src="http://www.webia.info/wp-content/uploads/2009/09/uefa_non_flash.jpg" alt="uefa.com screenshot" /></a></p>
<p>UEFA does a great job making a well developed website, but they have their own pitfalls. During the UEFA Champions League and UEFA Europa League draws, which took place last week, their live coverage of the event had only flash versions, rendering blank pages for users without flash player. Mobile users had to make phone calls in order to find out the group of their favorite team.</p>
<p>A website that does a bad job about non flash user experience is <a href="http://www.vinuldenunta.ro" target="_new">vinuldenunta.ro</a> . Such users do see something other than a blank page. They are presented with a small paragraph which unfortunately isn't formatted in any way, leaving the impression the site is under construction. No information is provided regarding the cool flash version of the site that is hidden to them.</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/09/vinuldenunta.jpg"><img src="http://www.webia.info/wp-content/uploads/2009/09/vinuldenunta.jpg" alt="vinuldenunta.ro screenshot" /></a></p>
<h2>Pointers for better flash developing</h2>
<ul>
<li>1. If possible, provide a non flash version of the site</li>
<li>2. If important content is displayed within flash, make sure it is available for users that do not have flash player</li>
<li>3. Don't use flash for navigation, and if you do, provide a secondary navigation menu using html</li>
<li>4. If you only have flash version, make sure you let non flash users know about that</li>
</ul>
<p>The above are just some basic pointers, but sticking to them will insure a high quality website. If you have any other examples or pointers please leave them in the comments section bellow. If you liked this article you can subscribe to the full content <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">rss feed</a> and stay updated as we post new information.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/usability/graceful-flash-degradation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fixed background</title>
		<link>http://www.webia.info/articles/code/fixed-background/</link>
		<comments>http://www.webia.info/articles/code/fixed-background/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 06:28:39 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[background]]></category>
		<category><![CDATA[fixed]]></category>
		<category><![CDATA[fixed-background]]></category>
		<category><![CDATA[page]]></category>
		<category><![CDATA[webia]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=409</guid>
		<description><![CDATA[Achieving a fixed background on a webpage is not so difficult. However, there's lots of topics out there (especially on forums), with lots of solutions to this problem, including some javascript or flash techniques. The point is that you don't need javascript, nor flash to achieve this. Especially flash! The trick is simple. You must [...]]]></description>
			<content:encoded><![CDATA[<p>Achieving a fixed background on a webpage is not so difficult. However, there's lots of topics out there (especially on forums), with lots of solutions to this problem, including some javascript or flash techniques. The point is that you don't need javascript, nor flash to achieve this. Especially flash! The trick is simple. You must set the background not to repeat, and the make it fixed. You do that by adding "background-attachment: fixed;" to your css code and you're done. The rest of background positioning must be done just as you would on any other background.</p>
<p>Here's a <a href="http://www.webia.info/demos/fixed_background/" target="_new">demo</a>, and here's the <a href="http://www.webia.info/demos/fixed_background/fixed.zip" target="_new">source code</a> for the demo. If you liked this article you can subscribe to the full content <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">rss feed</a> and stay updated as we post new information.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/code/fixed-background/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Switch from px to em</title>
		<link>http://www.webia.info/articles/code/switch-from-px-to-em/</link>
		<comments>http://www.webia.info/articles/code/switch-from-px-to-em/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 08:12:15 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[conversions]]></category>
		<category><![CDATA[em]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[px]]></category>
		<category><![CDATA[reset]]></category>
		<category><![CDATA[size]]></category>
		<category><![CDATA[sizing]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=417</guid>
		<description><![CDATA[In order to achieve real flexible layouts, one should develop the css code using ems, not pxs. Pixels can cripple your designs if the visitors use browser features to increase text size or to reduce it. Using em helps you develop websites that will look beautifully if such a thing happens.
Reset default value of text
Most [...]]]></description>
			<content:encoded><![CDATA[<p>In order to achieve real flexible layouts, one should develop the css code using ems, not pxs. Pixels can cripple your designs if the visitors use browser features to increase text size or to reduce it. Using em helps you develop websites that will look beautifully if such a thing happens.</p>
<h2>Reset default value of text</h2>
<p>Most web developers reset the default font-size of text so that further problems are easily tackled. Without proper resets it would be very difficult to set font-sizes of 11 px, 13px and so on. 1 em is equal to 16 px by default. In order to rapidly convert your pixel thoughts to ems, you'd be better of resetting 1 em to 10 px, which is setting it to 62.5%. We achieve this by placing in the body css tag the following: "font-size:62.5%;". This will make 1 em equal exactly 10 pixels.</p>
<h2>Some issues</h2>
<p>Many users set for links a font size that is smaller or bigger than the actual font size of the paragraph text. This is ok, but when ems are used, their settings are relative to their parent. Having the paragraph text set to 1.2 em (12 pixels), will not make a link 10 pixels if you use 1em setting. 10 pixels are actually 83% out of 12 pixels. This means that the link settings should be 0.83em instead of 1em. Similarly, to achieve 13 pixels links, you shouldn't use 1.3em, but 1.08em instead, as 13 pixels is 108% out of 12 pixels. It is as simple as that.</p>
<p>Check out a <a href="http://www.webia.info/demos/em_sizing/" target="_new">demo</a> and <a href="http://www.webia.info/demos/em_sizing/em_sizing.zip">download the source files</a>. If you liked this article you can subscribe to the full content <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">rss feed</a> and stay updated as we post new information.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/code/switch-from-px-to-em/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design for grandma too!</title>
		<link>http://www.webia.info/articles/usability/design-for-grandma-too/</link>
		<comments>http://www.webia.info/articles/usability/design-for-grandma-too/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 08:13:26 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[1995]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[IE 2]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[layout]]></category>
		<category><![CDATA[old browsers]]></category>
		<category><![CDATA[stylesheet]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=169</guid>
		<description><![CDATA[
So I proud myself that all websites I develop for my clients are cross browser. I usually test them on different platforms, different screen resolutions, different browsers. I use my own resources to do that, or I use online businesses that provide exactly these screening services so that you can test your site on more [...]]]></description>
			<content:encoded><![CDATA[<p class="imgpreview"><a class="showie2screen"><img src="http://www.webia.info/wp-content/uploads/2009/03/ie2_screenshot.jpg" alt="IE 2 screenshot" /></a></p>
<p>So I proud myself that all websites I develop for my clients are cross browser. I usually test them on different platforms, different screen resolutions, different browsers. I use my own resources to do that, or I use online businesses that provide exactly these screening services so that you can test your site on more than 50 browsers.
</p>
<span id="more-169"></span>
<p>However, there's a point where I stop looking back. That is IE 5.5 for Internet Explorer, Firefox 1.5 for Firefox, and so on. Yesterday I took a look through one of my site's logs and I have found that somebody visited my site using IE 2. Yes, I am not kidding. The operating system was Windows 95!
</p>
<p>You would lie yourself if you'd say that such antique operating systems and browsers are not in use anymore. The fact is that they are. The basic question is have you ever thought how your site looks on IE 2? Or some early versions of Firefox? I haven't done so until yesterday, but I will now try to get my hands on some PC that I can use to make those tests for IE 2 and alike.
</p>
<p>And what if you site is not even readable on such a browser? Of course the percent of such users is under 1%, but what if that was a client that would have bought services of thousands of dollars? One solution I think that could work is using a design similar to one generated for printing the webpage, but applied by default for old browsers. Using javascript to check the browser wouldn't probably work, because javascript was invented in '95, and I highly doubt that '95 browsers use it.
</p>
<h2>Conclusion</h2>
<p>Perhaps you shouldn't design for browsers that are this old (more than 10 years), but I think that 30 more minutes to develop a style sheet that will make the site usable for such browsers is time well spent. Overall, this will only show your professionalism.</p>
<p>I hope you enjoyed this article. Let me know what you think about it in the comments. If you liked this one, you can stay updated to upcoming articles via the <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">rss feed</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/usability/design-for-grandma-too/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Multi column layout, equal height</title>
		<link>http://www.webia.info/articles/design/multi-column-layout-equal-height/</link>
		<comments>http://www.webia.info/articles/design/multi-column-layout-equal-height/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 09:52:52 +0000</pubDate>
		<dc:creator>Bogdan Pop</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[column]]></category>
		<category><![CDATA[equal height]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[layout]]></category>

		<guid isPermaLink="false">http://www.webia.info/?p=142</guid>
		<description><![CDATA[This post was inspired by the actual development of this design. The process would have been easy but, as I wanted to add the post info (date, comments) as an ear, floating on the left of the content box, things got a little more complicated. One solution was using some technique based on faux columns, [...]]]></description>
			<content:encoded><![CDATA[<p>This post was inspired by the actual development of this design. The process would have been easy but, as I wanted to add the post info (date, comments) as an ear, floating on the left of the content box, things got a little more complicated. One solution was using some technique based on faux columns, having a content wrapper and a sidewrapper. The content wrapper would float to the left. The post info box would float relative to its parent to the left, but only that would have kept the box inside the content wrapper, not right just next to it.
</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/03/column_equal_heights1_big.jpg" class="showsketchfloating" target="_self" title="Floating post info box inside the content box"><img src="http://www.webia.info/wp-content/uploads/2009/03/column_equal_heights1.jpg" alt="Floating post info box inside the content box" /></a></p>
<span id="more-142"></span>
<h2>The temporary solution</h2>
<p>This issue has a relatively fast solution. You just put a negative left margin to the post info box, and it should go right out of there. This works relatively ok. The problems is that only really new browsers had no issues with this. I tested on IE 6, Firefox 1.06 and the post info box with negative margins disappeared from the view. That was due to the fact that the negative margin moved the box outside the content wrapper.
</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/03/column_equal_heights2.jpg" class="showsketchfloating" target="_self" title="Floating post info box with negative margins, outside of the content wrapper"><img src="http://www.webia.info/wp-content/uploads/2009/03/column_equal_heights2.jpg" alt="Floating post info box with negative margins, outside of the content wrapper" /></a></p>
<p>That could have been easily fixed by expanding the content wrapper with the post info box width, and floating the content to the right. Basically, this would have been a faux column layout inside another faux column layout. It works great, but when you hit the next problem, there are no apparent solutions at the horizon.
</p>
<h2>What if you want rounded corners? CSS 3 rounded corners!</h2>
<p>The problem with rounded corners is that you cannot expand the content wrapper, as the corners would go away from the content, rendering the layout useless. (check out the below image). The solution I found was to add a new wrapper, which would wrap the post info box, the content boxes (multiple posts have multiple boxes), and the side wrapper.
</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/03/column_equal_heights3.jpg" class="showsketchfloating" target="_self" title="Rounded corners on expanded box vs new overall wrapper"><img src="http://www.webia.info/wp-content/uploads/2009/03/column_equal_heights3.jpg" alt="Rounded corners on expanded box vs new overall wrapper" /></a></p>
<p>That new wrapper looks great. All you need to do is to add left rounded corners to the content boxes, and right rounded corners to the side wrapper. WRONG! That would work in most cases, but if you have a really long side wrapper, chances are you will have pages with content that do not have the same height! And that's when the cookie crumbles. Check out how you could end up with your background.
</p>
<p class="imgpreview"><a href="http://www.webia.info/wp-content/uploads/2009/03/column_equal_heights4.jpg" class="showsketchfloating" target="_self" title="Rounded corners with new wrapper installed. Content height lower than side wrapper"><img src="http://www.webia.info/wp-content/uploads/2009/03/column_equal_heights4.jpg" alt="Rounded corners with new wrapper installed. Content height lower than side wrapper" /></a></p>
<p>We put all that thinking into it and it looks like it doesn't work. Ok then, Browsers 1 - Developers 0. Some say you can fix this problem with going to css height and min-height properties. Having a body , html and wrappers with <strong>height:100%</strong>, and the last content box having <strong>min-height:100%</strong> should fix the problem. Well it doesn't. It does that if you don't have many nested wrappers. If you have many wrappers, it works only if the content area's height is lower than that of the side wrapper. If it is higher, you get the original problem (just the one you see in the screen above), but transferred to the side wrapper. Browsers 1 - Developers 1 because the problem is partially solved.</p>
<h2>The ultimate solution</h2>
<p>After struggling for around 2 and a half hours with height, min-height and wrapper variations, after not reaching any solution, I fixed this in 10 minutes with jQuery. Who would have though that the solution is that simple? So what was the jQuery code to handle this issue.</p>
<p>Remember we had a content wrapper, containing content boxes, one for each post? We also have the side wrapper. The solution is to get the height of the side wrapper, the height of the content wrapper, which grows due to the content boxes, and then compare the two values. If the content wrapper's height is smaller, you should increase it to match that of the side wrapper. But how?</p>
<h2>One span and jQuery to the rescue!</h2>
<p>You simply add a span tag to the end of the last content box, not the content wrapper. If the height of the content wrapper is smaller than that of the side wrapper, set the span tag's height to be the difference between the mentioned 2 heights. The result, no matter which box is the highest, is the one you see on this very own site. With rounded corners. All the time. Browsers 1 - Developers 2.</p>
<h2>The jQuery code</h2>
<code><pre>
	var diff = 0;
	var sideWrapper = 0;
	var cWrapper = 0;
	sideWrapper = $('#sidewrapper').height();
	cWrapper = $('#cwrapper').height();
	if(cWrapper < sideWrapper)
		{
			diff = sideWrapper - cWrapper;
			$(".end").height(diff);
		}
</pre></code>
<p>I hope you enjoyed this article. Let me know what you think about it in the comments. If you liked this one, you can stay updated to upcoming articles via the <a href="http://feeds2.feedburner.com/WebInternationalAwards" target="_new">rss feed</a>. A demo, and full source of this layout will be soon available.</p>]]></content:encoded>
			<wfw:commentRss>http://www.webia.info/articles/design/multi-column-layout-equal-height/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

