<?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>Subooa Studios Blog &#187; HTML &amp; CSS</title>
	<atom:link href="http://blog.subooa.com/category/development/html_and_css/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.subooa.com</link>
	<description>Custom development by Chris Duell aka duellsy</description>
	<lastBuildDate>Wed, 28 Jul 2010 03:57:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Creating a Dropdown Menu with jQuery and CSS</title>
		<link>http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/</link>
		<comments>http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/#comments</comments>
		<pubDate>Mon, 06 Jul 2009 10:59:31 +0000</pubDate>
		<dc:creator>Chris Duell</dc:creator>
				<category><![CDATA[Ajax & Javascript]]></category>
		<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[dropdown]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[menu]]></category>

		<guid isPermaLink="false">http://blog.subooa.com/?p=324</guid>
		<description><![CDATA[I often see requests for help on how to create a simple dropdown menu without requiring too much effort, and usually I direct people to an article for 'son of suckerfish', but since jQuery is in most sites I use now I have moved to using a jQuery based dropdown that is much simpler.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fhtml_and_css%2Fcreating-a-dropdown-menu-with-jquery-and-css%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fhtml_and_css%2Fcreating-a-dropdown-menu-with-jquery-and-css%2F&amp;source=duellsy&amp;style=normal&amp;service=bit.ly&amp;hashtags=dropdown,jquery,menu" height="61" width="50" /><br />
			</a>
		</div>
<h3>The raw base</h3>
<p>To start off with, we&#8217;re going to at least need some sort of menu structure to get us going. For this, the best way to structure the menu is using an unordered list (ul), nesting your submenus as you go. Below is the example we&#8217;re going to use in this demo it its raw unstyled format. </p>
<p>(The running demo is here &#8211; <a href="http://blog.subooa.com/example/css_jquery_dropdown.html">http://blog.subooa.com/example/css_jquery_dropdown.html</a>)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p324code1'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3241"><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
</pre></td><td class="code" id="p324code1"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;!</span>DOCTYPE html <span style="color: #000000; font-weight: bold;">PUBLIC</span> <span style="color: #0000ff;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #0000ff;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>html<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>head<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>title<span style="color: #339933;">&gt;</span>Creating a dropdown menu with jQuery and CSS<span style="color: #339933;">&lt;/</span>title<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>head<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;</span>div id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;mainmenu&quot;</span><span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Menu item <span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Submenu item <span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Submenu item <span style="color: #cc66cc;">1</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Menu item <span style="color: #cc66cc;">2</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Menu item <span style="color: #cc66cc;">3</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Menu item <span style="color: #cc66cc;">4</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;</span>ul<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Submenu item <span style="color:#800080;">4.1</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
				<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Submenu item <span style="color:#800080;">4.2</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
			<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;/</span>li<span style="color: #339933;">&gt;</span>
		<span style="color: #339933;">&lt;</span>li<span style="color: #339933;">&gt;&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;#&quot;</span><span style="color: #339933;">&gt;</span>Menu item <span style="color: #cc66cc;">5</span><span style="color: #339933;">&lt;/</span>a<span style="color: #339933;">&gt;&lt;/</span>li<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;/</span>ul<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>div<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>body<span style="color: #339933;">&gt;</span>
<span style="color: #339933;">&lt;/</span>html<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Opening that in a browser is going to be pretty plain, something like this:<br />
<img src="http://blog.subooa.com/wp-content/uploads/2009/07/raw_menu.jpg" alt="raw_menu" title="raw_menu" width="285" height="147" class="alignnone size-full wp-image-325" /></p>
<h3>A little css</h3>
<p>For the sake of this tutorial we&#8217;re only going to give the menu a basic look and not get too fancy. So we&#8217;ll just create a nice green and black menu.</p>
<p>The nav we are going to create is going to be a left to right manu, with the second level popping out below its parent, so we first need to order the items left to right and get the submenu it the right position. (To keep it simple, the style is going to be added to the same file and not extracted into a saperate stylesheet)</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p324code2'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3242"><td class="line_numbers"><pre>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
</pre></td><td class="code" id="p324code2"><pre class="css" style="font-family:monospace;">	&lt;style type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span><span style="color: #00AA00;">&gt;</span>
&nbsp;
		body<span style="color: #00AA00;">&#123;</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;">font-family</span><span style="color: #00AA00;">:</span> Arial<span style="color: #00AA00;">,</span> Verdana<span style="color: #00AA00;">,</span> Helvetica<span style="color: #00AA00;">,</span> Sans-Serif<span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span>
&nbsp;
		<span style="color: #cc00cc;">#mainmenu</span> ul<span style="color: #00AA00;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100%</span><span style="color: #00AA00;">;</span>
			<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</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;">#393</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: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> <span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
		<span style="color: #00AA00;">&#125;</span>
			<span style="color: #cc00cc;">#mainmenu</span> ul li<span style="color: #00AA00;">&#123;</span>
				<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</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;">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;">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;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</span><span style="color: #00AA00;">;</span>
				<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
			<span style="color: #00AA00;">&#125;</span>
				<span style="color: #cc00cc;">#mainmenu</span> ul 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;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
					<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">30px</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;">30px</span><span style="color: #00AA00;">;</span>
					<span style="color: #000000; font-weight: bold;">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;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
					<span style="color: #000000; font-weight: bold;">border-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#363</span><span style="color: #00AA00;">;</span>
					<span style="color: #000000; font-weight: bold;">border-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#3c3</span><span style="color: #00AA00;">;</span>
				<span style="color: #00AA00;">&#125;</span>
&nbsp;
				<span style="color: #cc00cc;">#mainmenu</span> ul li ul<span style="color: #00AA00;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">170px</span><span style="color: #00AA00;">;</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;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</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;">clear</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>
					<span style="color: #cc00cc;">#mainmenu</span> ul li ul li<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;">#000</span><span style="color: #00AA00;">;</span>
					<span style="color: #00AA00;">&#125;</span>
						<span style="color: #cc00cc;">#mainmenu</span> ul li<span style="color: #6666ff;">.hover</span> ul li a<span style="color: #00AA00;">&#123;</span>
							<span style="color: #000000; font-weight: bold;">border-width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
							<span style="color: #000000; font-weight: bold;">border-bottom</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;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
							<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">29px</span><span style="color: #00AA00;">;</span>
							<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">150px</span><span style="color: #00AA00;">;</span>
						<span style="color: #00AA00;">&#125;</span>	
	&lt;/style<span style="color: #00AA00;">&gt;</span></pre></td></tr></table></div>

<p><img src="http://blog.subooa.com/wp-content/uploads/2009/07/style_no_js.jpg" alt="style_no_js" title="style_no_js" width="600" height="103" class="alignnone size-full wp-image-326" /></p>
<h3>Hiding the submenu</h3>
<p>Now that the menu is working and displaying as we want it to, now we need to hide the submenu by default and setup the style for the hover state.</p>
<p>Change the left value for the &#8220;#mainmenu ul li ul&#8221; class to be off the screen somewhere (we&#8217;re using -12000px here) and add a new hover class for the list item, which moves the ul back to where we just had it when the user hovers over the main menu item.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p324code3'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3243"><td class="line_numbers"><pre>40
41
42
43
44
45
46
47
48
49
50
</pre></td><td class="code" id="p324code3"><pre class="css" style="font-family:monospace;">				<span style="color: #cc00cc;">#mainmenu</span> ul li ul<span style="color: #00AA00;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">170px</span><span style="color: #00AA00;">;</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;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-12000px</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;">clear</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>
&nbsp;
					<span style="color: #cc00cc;">#mainmenu</span> ul li<span style="color: #6666ff;">.hover</span> ul<span style="color: #00AA00;">&#123;</span>
						<span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">0px</span><span style="color: #00AA00;">;</span>
					<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3>Adding the jQuery event&#8230; the fun part</h3>
<p>Up to this point, the file could run as a standalone HTML file, and with a little extra CSS could actually work in a lot of browsers, but there are many out there that don&#8217;t support using the &#8220;:hover&#8221; on list items, so we need to make use of some javascript to tell the browser to react when the user hovers over the main menu items. So first step here is to actually load the jQuery javascript:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p324code4'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3244"><td class="line_numbers"><pre>63
64
65
66
</pre></td><td class="code" id="p324code4"><pre class="javascript" style="font-family:monospace;">	<span style="color: #339933;">&lt;</span>script src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js&quot;</span> type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span>
	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
		jQuery.<span style="color: #660066;">noConflict</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>(The no conflict line has been added in cases where people may already be calling a javascript file that makes use of $, it prevents us from running into any javascript code conflicts)</p>
<p>And now here is where the magic happens, using jQuery you can &#8216;chain&#8217; function calls one after the other without having to do each function call on an element on its own line which cuts down the file size and keeps things neat and together.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p324code5'); return false;">View Code</a> JAVASCRIPT</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3245"><td class="line_numbers"><pre>64
65
66
67
68
69
70
71
72
73
74
75
</pre></td><td class="code" id="p324code5"><pre class="javascript" style="font-family:monospace;">	<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span><span style="color: #339933;">&gt;</span>
		jQuery.<span style="color: #660066;">noConflict</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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>
			jQuery<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'#mainmenu'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">find</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'li'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">mouseenter</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>
				jQuery<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;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hover'</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: #660066;">mouseleave</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>
				jQuery<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;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'hover'</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>
		<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Finally, just to top things off we need to add some hover colors to the menu items.</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p324code6'); return false;">View Code</a> CSS</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p3246"><td class="line_numbers"><pre>63
64
65
66
67
68
69
</pre></td><td class="code" id="p324code6"><pre class="css" style="font-family:monospace;">&nbsp;
				<span style="color: #cc00cc;">#mainmenu</span> ul li<span style="color: #6666ff;">.hover</span> a<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;">#3c3</span><span style="color: #00AA00;">;</span>
				<span style="color: #00AA00;">&#125;</span>
				<span style="color: #cc00cc;">#mainmenu</span> ul li ul li<span style="color: #6666ff;">.hover</span> a<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;">#333</span><span style="color: #00AA00;">;</span>
				<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p><img src="http://blog.subooa.com/wp-content/uploads/2009/07/final_dropdown_menu.jpg" alt="final_dropdown_menu" title="final_dropdown_menu" width="600" height="103" class="alignnone size-full wp-image-327" /></p>
<p>And that&#8217;s it, a fully functional CSS dropdown using jQuery. In a later article, I&#8217;ll cover adding a slight animation and also adding multiple levels of dropdowns.</p>
<h3>Demo and full code</h3>
<p>Here&#8217;s the running demo &#8211; <a href="http://blog.subooa.com/example/css_jquery_dropdown.html">http://blog.subooa.com/example/css_jquery_dropdown.html</a><br />
In case you got a little lost along the way, you can download the full code here to play with &#8211; <a href="http://blog.subooa.com/example/css_jquery_dropdown.zip">css_jquery_dropdown.zip</a></p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/&amp;title=Creating+a+Dropdown+Menu+with+jQuery+and+CSS" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/&amp;title=Creating+a+Dropdown+Menu+with+jQuery+and+CSS" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/&amp;title=Creating+a+Dropdown+Menu+with+jQuery+and+CSS&amp;desc=I%20often%20see%20requests%20for%20help%20on%20how%20to%20create%20a%20simple%20dropdown%20menu%20without%20requiring%20too%20much%20effort%2C%20and%20usually%20I%20direct%20people%20to%20an%20article%20for%20%27son%20of%20suckerfish%27%2C%20but%20since%20jQuery%20is%20in%20most%20sites%20I%20use%20now%20I%20have%20moved%20to%20using%20a%20jQuery%20based%20dropdown%20that%20is%20much%20simpler." rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/&amp;title=Creating+a+Dropdown+Menu+with+jQuery+and+CSS" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/&amp;title=Creating+a+Dropdown+Menu+with+jQuery+and+CSS" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Creating+a+Dropdown+Menu+with+jQuery+and+CSS+-+http://bit.ly/2hGvd9&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fhtml_and_css%2Fcreating-a-dropdown-menu-with-jquery-and-css%2F","http:\/\/twitter.com\/home?status=Creating+a+Dropdown+Menu+with+jQuery+and+CSS+-+http:\/\/bit.ly\/2hGvd9&amp;source=shareaholic"];var wordpress_toolbar_url = "";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2Jsb2cuc3Vib29hLmNvbS9kZXZlbG9wbWVudC9odG1sX2FuZF9jc3MvY3JlYXRpbmctYS1kcm9wZG93bi1tZW51LXdpdGgtanF1ZXJ5LWFuZC1jc3MvPHdwdGI%2BQ3JlYXRpbmcgYSBEcm9wZG93biBNZW51IHdpdGggalF1ZXJ5IGFuZCBDU1M8d3B0Yj5odHRwOi8vYmxvZy5zdWJvb2EuY29tPHdwdGI%2BU3Vib29hIFN0dWRpb3MgQmxvZw%3D%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://blog.subooa.com/development/html_and_css/creating-a-dropdown-menu-with-jquery-and-css/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CushyCMS &#8211; Simple CMS for Static Sites</title>
		<link>http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/</link>
		<comments>http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 08:19:13 +0000</pubDate>
		<dc:creator>Chris Duell</dc:creator>
				<category><![CDATA[HTML & CSS]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[cushy]]></category>
		<category><![CDATA[cushy cms]]></category>

		<guid isPermaLink="false">http://blog.subooa.com/?p=294</guid>
		<description><![CDATA[Often a full CMS is way too much of a hassle for a site. If the site you are building is only a handful of pages, having the overhead of a CMS like Joomla, Drupal or Wordpress can be too much overhead. Enter CushyCMS, an extremely simple CMS that allows you (or your client) to edit particular sections of content without the additional baggage.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-right: 10px; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fhtml_and_css%2Fcushycms-simple-cms-for-static-sites%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fhtml_and_css%2Fcushycms-simple-cms-for-static-sites%2F&amp;source=duellsy&amp;style=normal&amp;service=bit.ly&amp;hashtags=cms,cushy,cushy+cms" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.cushycms.com">CushyCMS</a> is a hosted solution that allows you to build static HTML pages, without the need to install anything extra. This means it is independant of platform, you can use it on a Windows based server, or a Unix based server, the results are the same.</p>
<p>You will of course need to sign up to CushyCMS in order to use the solution, but it&#8217;s a very simple process and is free.</p>
<p>Once you&#8217;ve signed up, you will be asked to add a site to your account which will require details such as the server name and FTP details so that it can make the adjustments to the site as you make your changes. After adding a site, you will need to add a page to list as editable, clicking on the &#8216;assign page to site&#8230;&#8217; link will bring up a list of files (using the FTP details you entered for the site). Click on the file you want to be able to edit, give it a name, and click the &#8216;assign page&#8217; button.</p>
<p>You&#8217;ll now see that page in your list, and you&#8217;ll be able to click through to the edit page. Doing so now though, CushyCMS wont know which parts of the page you want to be editable, so lets go ahead and put in some code to let it know.</p>
<p>Jump into your favourite editor and open up the original file. All you need to do is give all the elements you want to be editble the css class &#8220;cushycms&#8221;. For example:</p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p294code7'); return false;">View Code</a> HTML</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p2947"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p294code7"><pre class="html" style="font-family:monospace;">&lt;h1 class=&quot;cushycms&quot;&gt;My editable title&lt;/h1&gt;</pre></td></tr></table></div>

<p>Once you&#8217;ve added this class to all the elements you want to be editble (including images that are auto resized!) save the file and add it to the server you have hooked up to CushCMS, and go back to the edit page in CushyCMS.</p>
<p>That&#8217;s it. Done. Simple right!</p>
<p>It doesn&#8217;t stop there though, as the main developer, you can also give access to your clients so they can maintain their own content. You can even assign only certain pages to them if you want to restrict their access. When you add a new &#8220;editor&#8221; the client will receive an email with their login details, and they will have a simplified view of the admin area and be able to edit the content for only the pages you have allowed them access to.</p>
<p>So next time you build a small site that still needs CMS capabilities, keep CushyCMS in mind.</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-bg-enjoy">
<ul class="socials">
		<li class="shr-comfeed">
			<a href="http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/feed" rel="nofollow" class="external" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/&amp;title=CushyCMS+-+Simple+CMS+for+Static+Sites" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/&amp;title=CushyCMS+-+Simple+CMS+for+Static+Sites" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-diigo">
			<a href="http://www.diigo.com/post?url=http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/&amp;title=CushyCMS+-+Simple+CMS+for+Static+Sites&amp;desc=Often%20a%20full%20CMS%20is%20way%20too%20much%20of%20a%20hassle%20for%20a%20site.%20If%20the%20site%20you%20are%20building%20is%20only%20a%20handful%20of%20pages%2C%20having%20the%20overhead%20of%20a%20CMS%20like%20Joomla%2C%20Drupal%20or%20Wordpress%20can%20be%20too%20much%20overhead.%20Enter%20CushyCMS%2C%20an%20extremely%20simple%20CMS%20that%20allows%20you%20%28or%20your%20client%29%20to%20edit%20particular%20sections%20of%20content%20without%20the%20additional%20baggage." rel="nofollow" class="external" title="Post this on Diigo">Post this on Diigo</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/&amp;title=CushyCMS+-+Simple+CMS+for+Static+Sites" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/&amp;title=CushyCMS+-+Simple+CMS+for+Static+Sites" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-technorati">
			<a href="http://technorati.com/faves?add=http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/" rel="nofollow" class="external" title="Share this on Technorati">Share this on Technorati</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=CushyCMS+-+Simple+CMS+for+Static+Sites+-+http://bit.ly/prsi&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

<script type="text/javascript">var wordpress_toolbar_urls = ["http:\/\/api.tweetmeme.com\/share?url=http%3A%2F%2Fblog.subooa.com%2Fdevelopment%2Fhtml_and_css%2Fcushycms-simple-cms-for-static-sites%2F","http:\/\/www.cushycms.com","http:\/\/twitter.com\/home?status=CushyCMS+-+Simple+CMS+for+Static+Sites+-+http:\/\/bit.ly\/prsi&amp;source=shareaholic"];var wordpress_toolbar_url = "";var wordpress_toolbar_oinw = "oinw";var wordpress_toolbar_hash = "aHR0cDovL2Jsb2cuc3Vib29hLmNvbS9kZXZlbG9wbWVudC9odG1sX2FuZF9jc3MvY3VzaHljbXMtc2ltcGxlLWNtcy1mb3Itc3RhdGljLXNpdGVzLzx3cHRiPkN1c2h5Q01TICYjODIxMTsgU2ltcGxlIENNUyBmb3IgU3RhdGljIFNpdGVzPHdwdGI%2BaHR0cDovL2Jsb2cuc3Vib29hLmNvbTx3cHRiPlN1Ym9vYSBTdHVkaW9zIEJsb2c%3D";</script>]]></content:encoded>
			<wfw:commentRss>http://blog.subooa.com/development/html_and_css/cushycms-simple-cms-for-static-sites/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
