Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-11-2009, 12:15 PM   PM User | #1
SteveDD
Regular Coder

 
Join Date: Aug 2008
Posts: 127
Thanks: 2
Thanked 0 Times in 0 Posts
SteveDD is an unknown quantity at this point
CSS Horizontal Menu Help

I am trying to make a horizontal menu and have a couple of problems:

1) When home is selected I want it to highlight it the same color i.e: #b2b2b2
however at the minute I cannot figure out how to do this. I also want it to do the same for the about us page etc (but havent added this to the code at the minute).

2) I want the menu to be horizontal at the minute it keeps going on top of each other and the spacing is really tight.

I want it like:

Home | About | Products | Contact Us | Special Offers


My code:

<div id="main-nav"><div id="altnavhead">
<a href="index.php?page=home">Home</a><a href="index.php?page=aboutus">About</a> <a href="index.php?page=contactus">Contact Us</a> <a href="index.php?page=retailproducts">Retail Products</a> <a href="index.php?page=specialoffers">Special Offers</a>
</div>
</div>


#main-nav {
height: 50px;
background-color: #ebecf0;
margin-left: 160px;
}

#main-nav a {
color: #ff75ba;
weight: bold;
text-decoration: none;
}

#main-nav a:hover {
color: #b2b2b2;
}

#main-nav #altnavhead {
padding-top: 20px;
padding-left: 30px;
}

body.home main-nav#home,
body.home main-nav#home a,
body.home main-nav#home a:hover,
color: #b2b2b2;
}


I do set in my include page the page class: <body class="home">
SteveDD is offline   Reply With Quote
Old 05-11-2009, 12:36 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
1) When home is selected I want it to highlight it the same color i.e: #b2b2b2
however at the minute I cannot figure out how to do this. I also want it to do the same for the about us page etc (but havent added this to the code at the minute).
Quote:
I do set in my include page the page class: <body class="home">
Code:
.home #main-nav a{
 color: #b2b2b2;
}
Quote:
2) I want the menu to be horizontal at the minute it keeps going on top of each other and the spacing is really tight.
By default, anchors are inline elements, so they should sit in line with other. You may have some other CSS rule than the above which might be affecting them.

You may override it by adding either display:inline; or float:left; to your #main-nav a (though there will some difference in the behavior of the items for these two)
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 05-11-2009, 12:46 PM   PM User | #3
SteveDD
Regular Coder

 
Join Date: Aug 2008
Posts: 127
Thanks: 2
Thanked 0 Times in 0 Posts
SteveDD is an unknown quantity at this point
I have added:
.home #main-nav a{
color: #b2b2b2;
}
into my code but that just turns my whole menu, b2b2b2 and nothing happens on selection or hover?

I used your code to replace: body.home main-nav#home,
body.home main-nav#home a,
body.home main-nav#home a:hover,
color: #b2b2b2;
}

which I know is wrong.
SteveDD is offline   Reply With Quote
Old 05-11-2009, 12:58 PM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
I have added:
.home #main-nav a{
color: #b2b2b2;
} into my code but that just turns my whole menu, b2b2b2 and nothing happens on selection or hover?
I missed one point.
Code:
<body id="home">
.....
<div id="main-nav"><div id="altnavhead">
<a href="index.php?page=home" class="home">Home</a><a href="index.php?page=aboutus">About</a> <a href="index.php?page=contactus">Contact Us</a> <a href="index.php?page=retailproducts">Retail Products</a> <a href="index.php?page=specialoffers">Special Offers</a>
</div>
Code:
#home #main-nav a.home{
 color: #b2b2b2;
}
should do it.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 05-11-2009, 01:10 PM   PM User | #5
SteveDD
Regular Coder

 
Join Date: Aug 2008
Posts: 127
Thanks: 2
Thanked 0 Times in 0 Posts
SteveDD is an unknown quantity at this point
added this but the only problem is home is always highlighted now? When I click about home still stays highlighted?

I want to go through and repeat it with about, contact us etc... so when they are selected they are in the font #b2b2b2 but as I say above home is always highlighted.

Thanks for your help so far its been great..
SteveDD is offline   Reply With Quote
Old 05-11-2009, 01:13 PM   PM User | #6
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
When I click about home still stays highlighted?
In the about page, your body tag should have a different id, say id="about"
Refer http://www.codingforums.com/showpost...64&postcount=3
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 05-11-2009, 01:45 PM   PM User | #7
SteveDD
Regular Coder

 
Join Date: Aug 2008
Posts: 127
Thanks: 2
Thanked 0 Times in 0 Posts
SteveDD is an unknown quantity at this point
nope when I add in the id for about they both stay highlighted home and about.
SteveDD is offline   Reply With Quote
Old 05-11-2009, 01:52 PM   PM User | #8
SteveDD
Regular Coder

 
Join Date: Aug 2008
Posts: 127
Thanks: 2
Thanked 0 Times in 0 Posts
SteveDD is an unknown quantity at this point
Just so you know where I am at:#.css code
#main-nav {
height: 50px;
background-color: #ebecf0;
margin-left: 160px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 11px;
}

#main-nav a {
color: #ff75ba;
text-decoration: none;
}

#main-nav a:hover {
color: #b2b2b2;
}

#main-nav #altnavhead {
padding-top: 20px;
padding-left: 30px;
}

#main-nav a.home{
color: #b2b2b2;
}
#main-nav a.about{
color: #b2b2b2;
}


and my menu code:

<div id="main-nav"><div id="altnavhead">
<a href="index.php?page=home" class="home">Home</a><b>|</b><a href="index.php?page=aboutus" class="about">About</a><b>|</b><a href="index.php?page=contactus">Contact Us</a><b>|</b><a href="index.php?page=retailproducts">Retail Products</a><b>|</b><a href="index.php?page=specialoffers">Special Offers</a>
</div>
</div>
SteveDD is offline   Reply With Quote
Old 05-13-2009, 02:54 PM   PM User | #9
SteveDD
Regular Coder

 
Join Date: Aug 2008
Posts: 127
Thanks: 2
Thanked 0 Times in 0 Posts
SteveDD is an unknown quantity at this point
Can anyone see why the home and now about buttons are remaining highlighted even when not on that page.

I am using the body tag <body class="home"> to indicate what page it is.
SteveDD is offline   Reply With Quote
Old 05-13-2009, 03:02 PM   PM User | #10
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
Can anyone see why the home and now about buttons are remaining highlighted even when not on that page.
I'm pretty sure about the working of the method explained in the above given link. Have you followed it correctly?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 05-13-2009, 06:13 PM   PM User | #11
codedpsd
New to the CF scene

 
Join Date: May 2009
Location: New York City
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
codedpsd is an unknown quantity at this point
Apply styles to a:visited as well.
__________________
Psd to Html
codedpsd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 10:50 PM.


Advertisement
Log in to turn off these ads.