All in one forum  - Applications | Games | E-Books | Music, Movies & Videos | Mobile Stuff | Live Discussions | Webmaster Stuff | Many More | Community to Hang Out & Stick to
Mark Forums Read

Go Back   Home > Tutorial Section > Programming > CSS and XML
Reload this Page [Tutorial] CSS Sliding Door using only 1 image
Forgot Password? Join Us!
CSS and XML Post your Cascading Style Sheets and eXtensible Markup Language related tutorial here

Notices
Free Image Hosting Solution for all Your link here @ 10$ 10 K Unique Visitors 1 Million Visitors Per Month Your link here @ 10$

Your Ad Here

Rate This Thread - CSS Sliding Door using only 1 image.

Post New Thread Reply
 
LinkBack Thread Tools Display Modes
  (#1 (permalink)) Old
 
KoOL's Avatar
 
User Info
Join Date: Oct 2007
Location: In You Mind
Age: 27
Achievements Posts: 10,862
Casino Cash: $1145330

Total Points: 237,899,712,740.76
Donate

KoOL has disabled reputation

Awards Showcase
Administrator Of the Month Of Jan 
Total Awards: 1
CSS Sliding Door using only 1 image - 06-14-2008, 05:42 AM

Before I know about this technique, I was using different images for each of the button I needed in a navigation bar. I found that it is not user friendly and also need more CSS coding. Besides, it is increasing the processing time and bandwidth in loading a site. In this tutorial, I will show you how to code the navigation bar using only 1 image. I will not cover the image creation part because I think you should know how to do that after follow few of my tutorials in the past. So, start here…
The Image


I will not show how to create this but I will let you guys download the psd file as a reference. I provided 4 types of colors as default, you can edit them according to your preferences. Download the psd here and I even prepared the slices for you. What you need in building the navigation menu is only a 493px X 24px image like below.
Before we start, head over and see what we are going to achieve from this tutorial. Concept


The concept of the sliding door is to use a background image for the buttons in a navigation menu. I am using a span within a link in the list to hold a part of the image. the link itself will hold another part of it. Which means, the important part will be the background-image position. HTML

1
2
3
4
5
6
<ul class="blue">
<li><a href="#" title="home">home</a></li>
<li><a href="#" title="products">products</a></li>
<li><a href="#" title="blog">blog</a></li>
<li><a href="#" title="contact">contact</a></li>
</ul>
This is a normal code to create a list. I assign a class for the <ul> (unorder-list) so that I can easily reuse the whole thing with different style but same structure.
1
2
3
4
5
6
<ul class="blue">
<li><a href="#" title="home" class="current"><span></span>home</a></li>
<li><a href="#" title="products"><span></span>products</a></li>
<li><a href="#" title="blog"><span></span>blog</a></li>
<li><a href="#" title="contact"><span></span>contact</a></li>
</ul>
Now, I add in a <span> for each of the link to hold the left hand side of the background image.
CSS

1. <ul> - Unorder-List
1
2
3
4
5
6
ul.blue {
padding: 5px;
margin: 10px 0;
list-style: none;
float: left;
}
We need to make list-style as none because no image for any list within it. I use a float left here because I am going to use float left for the <span> and also <li>. I am not going to define a width for it because this is just a sample.
For your information, you need to define a width for the container which you had float it.
2. <li> - List
1
2
3
4
5
6
7
8
9
10
11
12
ul.blue li {
float: left;
}

ul.blue li a {
float: left;
text-decoration: none;
color: #ccc;
padding: 4px 15px 0 0;
margin-right: 8px;
font: 900 14px "Arial", Helvetica, sans-serif;
}
Like what mentioned just now, there is a float for the list. padding right for 15px is for the space between the edge of the image and the link text. The margin here is for the space between the list.
3. <span> - span within the link
1
2
3
4
5
6
7
ul.blue li a span {
float: left;
padding-right: 15px;
display: block;
margin-top: -4px;
height: 24px;
}
For the span, we use padding right for the same purpose. However, I add a -4px margin-top because I I have a 4px padding top for the link.
4. <Hover> - mouse over action
1
2
3
4
5
6
7
8
ul.blue li a:hover, ul.blue li a.current {
color: #0d5f83;
background: url(images/blue.png) no-repeat top right;
}

ul.blue li a:hover span, ul.blue li a.current span {
background: url(images/blue.png) no-repeat top left;
}
Since we are going to have the same effect for the mouse over and active link. I combine the codes.
Here is another example with 4 colors.
Conclusion and Download

This is a very useful technique which you can re-use in page with only 1 image. It is easy to use and I hope that you guys can understand my poor English explanation. Any question, just send me an email or drop me a comment here.



For Download Links U need to Press Thanks Button

Please don't PM me For Posts, Request and Not Working Threads. Use Button.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
The Following User Says Thank You to KoOL For This Useful Post:
3dynamic (09-08-2008)
Click here to Donate to remove the Adverts.
Your Ad Here
Post New Thread Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Girls Next Door Season 4 pdiamantino TV Zone 8 09-28-2008 08:16 AM
Right At Your Door (2006) bs0409 HollyWood Movies 0 02-18-2008 08:34 AM
Sliding Doors [1998] dvdrip [Eng] with subtitles [2 hosts] catchspider2002 HollyWood Movies 0 02-06-2008 05:45 AM
Right At Your Door (2006) KoOL HollyWood Music 1 10-13-2007 11:11 PM
how much would a new door for a 2007 camry yeaitsme000 PC World 0 07-23-2007 07:05 PM


New To AiO Forum? Need Help?

All times are GMT. The time now is 04:16 AM.
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
vBulletin Skin developed by: vBStyles

RapidShare Links PhazeDDL Warez
PhazeDDL Warez