Styling the Menu/NavBar

This is a discussion on Styling the Menu/NavBar within the HTML / XHTML forums, part of the Development category; Right I have created the menu for my website. However, I'm having a problem styling the menu links and text. ...


Reply
 
LinkBack Thread Tools Display Modes
Old 16th August 2009, 08:23 PM   #1
moderator
 
Wrams's Avatar
 
Join Date: Apr 2009
Location: Bristol, UK
Posts: 906
Blog Entries: 1
Thanks: 50
Thanked 7 Times in 7 Posts
Wrams has a spectacular aura aboutWrams has a spectacular aura aboutWrams has a spectacular aura about
Expertise: (X)HTML / CSS
Experience: Intermediate
Exclamation Styling the Menu/NavBar

Right I have created the menu for my website. However, I'm having a problem styling the menu links and text.

What I want to do is make the font a different style for example Verdana or Sans-Serif. Also I want the menu text to be white. Then I'll make the hover affect after.



HTML
Code:
<ul id="nav">
  <li class="selected"><a href="index.html">Home</a></li>
  <li><a href="about.html">About</a></li>
  <li><a href="service.html">Service</a></li>
  <li><a href="portfolio.html">Portfolio</a></li>
  <li><a href="hosting.html">Hosting</a></li>
  <li><a href="contact_us.html">Contact Us</a></li>
</ul>
</div>
CSS
Code:
[ul#nav {
height:32px; 
}
ul#nav li {
float: left; 
padding: 10px 47px; 
}
ul#nav li a:hover { 
text-decoration: underline;
}
ul#nav li.selected a { 
color: red;
}
ul {
list-style: none;
}
Thank you for any advise given.
__________________

Last edited by Wrams; 17th August 2009 at 10:04 AM..
Wrams is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 16th August 2009, 10:08 PM   #2
supermod
 
CloudedVision's Avatar
 
Join Date: Jan 2009
Location: Your Imagination
Posts: 729
Blog Entries: 4
Thanks: 1
Thanked 27 Times in 26 Posts
CloudedVision has a spectacular aura aboutCloudedVision has a spectacular aura aboutCloudedVision has a spectacular aura about
Expertise: PHP
Experience: Professional
Default

Code:
font-family:Verdana, sans-serif;
color:#fff;
Add that to the link styling.
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
The Following User Says Thank You to CloudedVision For This Useful Post:
Wrams (17th August 2009)
Old 17th August 2009, 09:59 AM   #3
moderator
 
Wrams's Avatar
 
Join Date: Apr 2009
Location: Bristol, UK
Posts: 906
Blog Entries: 1
Thanks: 50
Thanked 7 Times in 7 Posts
Wrams has a spectacular aura aboutWrams has a spectacular aura aboutWrams has a spectacular aura about
Expertise: (X)HTML / CSS
Experience: Intermediate
Default

Quote:
Originally Posted by CloudedVision View Post
Code:
font-family:Verdana, sans-serif;
color:#fff;
Add that to the link styling.
Thanks CV. Which one is the Link Styling...?

I've done this CSS and it made the text turn white. Is this correct...?

Code:
a {
font-family:Verdana, sans-serif;
color:#FFF;
text-decoration: none;
}
The only problem I can see is that if I have other links they also will be white. Can I put something infront or behind it like

a nav{
}

Will that make it style for only the menu...?

:EDIT: I've put the following and it works.

ul a {
}

This has made the text white and only covers the menu.
__________________

Last edited by Wrams; 17th August 2009 at 10:33 AM..
Wrams is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 17th August 2009, 10:44 AM   #4
admin
 
WelshStew's Avatar
 
Join Date: Dec 2008
Posts: 1,844
Blog Entries: 3
Thanks: 13
Thanked 36 Times in 34 Posts
WelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond repute
Expertise: (X)HTML / CSS
Experience: Professional
Default

So this will again do this for all unordered lists on your site - is this what you want?

If you want to target just the nav then use the following:
Code:
#nav{
font-family:Verdana, sans-serif;
color:#fff;}
WelshStew is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 17th August 2009, 10:47 AM   #5
moderator
 
Wrams's Avatar
 
Join Date: Apr 2009
Location: Bristol, UK
Posts: 906
Blog Entries: 1
Thanks: 50
Thanked 7 Times in 7 Posts
Wrams has a spectacular aura aboutWrams has a spectacular aura aboutWrams has a spectacular aura about
Expertise: (X)HTML / CSS
Experience: Intermediate
Default

Quote:
Originally Posted by WelshStew View Post
So this will again do this for all unordered lists on your site - is this what you want?

If you want to target just the nav then use the following:
Code:
#nav{
font-family:Verdana, sans-serif;
color:#fff;}
Thanks Stew.

I do want to target just the nav, however, I've used

ul a {
}

That has worked on styling the menu. But, will it affect other <ul>'s ? Or shall it be better to use your coding...? I'll try your way to and let you know.

Thanks mate.

Right I've just tried that and the text went back to a blue colour even though I don't have blue specified. This is weird...Lol
__________________

Last edited by Wrams; 17th August 2009 at 10:49 AM..
Wrams is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 17th August 2009, 11:28 AM   #6
Tom
trusted
 
Tom's Avatar
 
Join Date: Jan 2009
Posts: 730
Blog Entries: 16
Thanks: 17
Thanked 34 Times in 34 Posts
Tom will become famous soon enough
Expertise: Design & Graphics
Experience: Quite Good
Default

it will affect all UL tags on your site from now on, the way I would do this is to define it as follows:

Code:
#nav ul {font-family:}

#nav li a {color: white;}
#nav li a:hover {}
#nav li a:active {}
#nav li a:visited {color: white;}
This will then only affect UL's with the #nav id.
Code:
<div id="nav">
<ul>
<li>list1</li>
<li><a href="#">list2</a></li>
</ul>
</div>
(this does have the wrapping div directly around it, but as long as the ul list is inside the #nav id then you can have anything esle within there too)
__________________
Fusion Web Hosting - Friendly and easy to use www.fusionservers.co.uk
Tom is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
The Following User Says Thank You to Tom For This Useful Post:
Wrams (17th August 2009)
Old 17th August 2009, 11:39 AM   #7
Gaz
Member
 
Gaz's Avatar
 
Join Date: Jan 2009
Location: 127.0.0.1
Posts: 113
Thanks: 1
Thanked 6 Times in 6 Posts
Gaz is on a distinguished road
Expertise: (X)HTML / CSS
Experience: Expert
Default

The above is the best method, but your getting a bit of divitous if your placing that div just around the UL.
It's better practices to take out that div and put the ID in the UL. removing 2 lines of code and getting rid of 11 characters.
Gaz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 17th August 2009, 11:47 AM   #8
moderator
 
Wrams's Avatar
 
Join Date: Apr 2009
Location: Bristol, UK
Posts: 906
Blog Entries: 1
Thanks: 50
Thanked 7 Times in 7 Posts
Wrams has a spectacular aura aboutWrams has a spectacular aura aboutWrams has a spectacular aura about
Expertise: (X)HTML / CSS
Experience: Intermediate
Default

Quote:
Originally Posted by Gaz View Post
The above is the best method, but your getting a bit of divitous if your placing that div just around the UL.
It's better practices to take out that div and put the ID in the UL. removing 2 lines of code and getting rid of 11 characters.
Can you give me an example of what you mean Gaz...?

Thanks!!
__________________
Wrams is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
Old 17th August 2009, 12:30 PM   #9
admin
 
WelshStew's Avatar
 
Join Date: Dec 2008
Posts: 1,844
Blog Entries: 3
Thanks: 13
Thanked 36 Times in 34 Posts
WelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond reputeWelshStew has a reputation beyond repute
Expertise: (X)HTML / CSS
Experience: Professional
Default

It's as you had it in your original post:
Code:
<ul id="nav">
<li></li>
</ul>
rather than:
Code:
<div id=nav>
<ul>
<li></li>
</ul>
</div>
divitius is sometimes an issue, and something I rather suffer from...
WelshStew is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
The Following User Says Thank You to WelshStew For This Useful Post:
Wrams (17th August 2009)
Old 17th August 2009, 12:54 PM   #10
Gaz
Member
 
Gaz's Avatar
 
Join Date: Jan 2009
Location: 127.0.0.1
Posts: 113
Thanks: 1
Thanked 6 Times in 6 Posts
Gaz is on a distinguished road
Expertise: (X)HTML / CSS
Experience: Expert
Default

The above example is spot on.

It's not much of an issue at present, but in some cases it can be just as bad as tables.
Gaz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!twitter
Reply With Quote
The Following User Says Thank You to Gaz For This Useful Post:
Wrams (17th August 2009)
Reply

Tags
menu or navbar, styling

Thread Tools
Display Modes