We’ve had a few requests for art­icles on the site lately, and more and more of them are ask­ing about the design of the site itself. So for today I thought I would detail how I designed the header for Super­pos­i­tion Kitty. An ini­tial warn­ing: I have no idea how many browsers this works in (as my usual test­ing pro­ced­ure of using Browser Shots is no help for hover states), how­ever it should work for all the major browsers, even IE6. Secondly: This code — or more spe­cific­ally, nest­ing a <div> between <ul> and <li> ele­ments — is not XHMTL valid.

I spent a lot of time wor­ry­ing about the second part until I real­ised the valid­ity of my code had abso­lutely no effect on how the site is dis­played to vis­it­ors. This doesn’t mean you should just throw val­id­a­tion out the win­dow — at the very least it is a great way to dis­cover hid­den errors in your code, or why some­thing isn’t dis­play­ing as you think it should — but I just don’t believe it is as import­ant as I once did.

Head­ers in Word­Press are a rel­at­ively simple affair. If you want to brush up on the basics then I would recom­mend check­ing out the excel­lent Word­Press Codex art­icle on design­ing head­ers. The header for Super­pos­i­tion Kitty is based on Son Of Suck­er­fish Drop­downs, which is in turn based on the ground­break­ing A List Apart art­icle: Suck­er­fish Drop­downs. Read­ing through both of those art­icles (which I heav­ily recom­mend) will give you a good ground­ing in how to style lists as a hori­zontal (or even ver­tical) menu.

First up we have the HTML code, which will tra­di­tion­ally go dir­ectly after the <body> tag in the header.php file in your Word­Press directory:

<div id="head">
<div id="navigation">
	<ul>
		<li><a href="#">#</a></li>
		<li><a href="#">#</a>
			<ul>
			<div class="center">
				<li><a href="#">#</a></li>
				<li><a href="#">#</a></li>
			</div>
			</ul>
		</li>
		<li><a href="#">#</a></li>
	</ul>
</div>
</div>

This cre­ates the basis for a simple two-tiered menu of three items (the second of which will have two child items). The <div class="center"> is the tag men­tioned at the begin­ning of this art­icle that will break val­id­a­tion. How­ever, it is neces­sary to cen­ter the list items with the rest of the site while still allow­ing the back­ground to take up 100% width. This should become more obvi­ous with the CSS:

#head {
width:100%;
background:#222;
height:36px;
}

#navigation, #navigation ul, .center {
margin:0px auto;
width:960px;
}

#navigation ul li {
float:left;
margin:0px 12px 0px 6px;
padding:18px 3px 0px 3px;
font-size:15px;
line-height:18px;
font-weight:bold;
text-transform:uppercase;
}

#navigation ul li a {
color:#FDFDFD;
}

#navigation ul li:hover, #navigation ul li:active {
background:#34B0F8;
color:#222;
}

#navigation li ul {
position:absolute;
left:-9999px;
}

#navigation li:hover ul {
left:0px;
width:100%;
padding-top:2px;
background:#34B0F8;
}

#navigation li ul li {
padding:0px;
margin:0px 9px;
}

#navigation li ul li a:active, #navigation li ul li a:hover, #navigation ul li a:active, #navigation ul li a:hover {
color:#222;
}

This should be rel­at­ively self-explanatory if you read the art­icles linked above. We’re simply styl­ing a list as a menu, and when the mouse is hovered over an item with a child ele­ment that ele­ment is unhid­den. The only prob­lem we have here is that Inter­net Explorer won’t prop­erly recog­nise the :hover class on any ele­ment other than <a>, so we’re going to need to bor­row some JavaS­cript from the Son Of Suck­er­fish Drop­downs article:


sfHover = function() {
var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

What this does is look for <li> ele­ments in navigation and then apply :sfhover to them when moused-over, and remove it when moused-out. So we’ll have to add the fol­low­ing to our CSS file for it to have a class to apply:

#navigation li:sfhover ul {
left:0px;
width:100%;
padding-top:2px;
background:#34B0F8;
}

Put all this together and you should have some­thing that looks rather sim­ilar to our menu. Feel free to post any com­ments, sug­ges­tions or ques­tions below.


Leave a Reply

Details

'WordPress, Headers, And Superposition Kitty' was posted on January 6th, 2010 in the Category: Tutorials.

You can subscribe to the comments on this post, or post a comment of your own



Related Posts

About Us

SuperpositionKitty is Ryan Smith & Jennifer Smith. Based in Australia, but operating out of the United Kingdom, they have been working together since roughly the turn of the century. Read More…

Get In Touch

You can get in touch with Ryan at ryan@superpositionkitty.com, or Jen at jen@superpositionkitty.com. If you have any questions, feedback, or suggestions for the website, then you can contact us at collective.

CompleteTrimmedSecond FrameAll SidesGluedGluing

Currently Saying

Jen:  Ryan: