Sunday, 13 January 2008

Digg-like navigation bar using CSS

Navigation bar with rounded corners an sliding doors technique for background images, Digg inspired.

This tutorial explains how to design a digg-like navigation bar using a liquid design with rounded corners for links.

The result is something like this:

Download this tutorial

Step 1: HTML page
Create a new HTML page and copy and paste the following code inside <body> tag:

<div id="topbar">
<a href="p1.html"><span>All</span></a>
<a href="p2.html" class="active"><span>News</span></a>
<a href="p3.html"><span>Video</span></a>
<a href="p4.html"><span>Images</span></a>
</div>
<div id="middlebar">
<a href="p1.html"><span>Technology</span></a>
<a href="p2.html"><span>World</span></a>
<a href="p3.html"><span>Science</span></a>
<a href="p4.html"><span>Gaming</span></a>
</div>

In the second link, "News", I added the class "active" (in bold). If you use URL variables and PHP to implement a dynamic navigation bar with some topics, if is defined an URL variable equal to "topic name" (in this case equal to "news") then add the attribute class="active" to the link. The code to implement this simple tip is very simple:

<?php if(isset($_GET['news'])){ echo 'class="active"';}?>


Step 2: rounded corners with liquid design for links
Before to start, I spend few rows to explain how to implement this simple effect using CSS. The typical way is using this simple structure:

...in HTML code:

<a href="mypage.html"><span>All</span></a>


Step 3: CSS file, #topbar
Create a new CSS file (style.css) and copy and paste the following code for #topbar element (remeber to link this file in your HTML page):

#topbar{
font-size:14px;
color:#3b5d14;
background:#b2d281;
font-weight:bold;
padding:6px;
overflow:auto;
height:1%;
clear:both;
}
#topbar a{
color:#3b5d14;
text-decoration:none;
margin:0 10px;
height:23px;
line-height:23px;
float:left;
display:block;
}
a.active{
height:23px;
line-height:23px;
background:url(pic/tb_a.png) right top no-repeat;
padding-right:10px;
}
a.active span{
background:url(pic/tb_span.png) left top no-repeat;
height:23px;
display:block;
padding-left:10px;
}



Step 4: CSS file, #middlebar
In the same CSS file (style.css), add the following code:

#middlebar{
font-size:11px;
color:#3b5d14;
background:#90b557;
font-weight:bold;
padding:6px;
overflow:auto;
height:1%;
clear:both;
}

#middlebar a{
color:#3b5d14;
text-decoration:none;
margin:0 5px;
padding-right:10px;
height:23px;
line-height:23px;
display:block;
float:left;
background:url(pic/mb_a.png) right top no-repeat;
}
#middlebar a span{
background:url(pic/mb_span.png) left top no-repeat;
height:23px;
display:block;
padding-left:10px;
}

Save and test the result!

Download this tutorial

Related posts

No comments:

Post a Comment