/    Sign up×
Community /Pin to ProfileBookmark

Hi,

I have a CSS navigation menu but when I change the background color on #navMenu li it changes the background colour on the top menu as well as the drop down menus, but I only want to change the BG color on the drop downs. How can I do this?

[CODE] <div id=”navMenu”>
<ul>
<li><a href=”../index.html”>Home</a>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>

<div id=”navMenu”>
<ul>
<li><a href=”http://about.me/thomashochkins”>About</a>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>

<div id=”navMenu”>
<ul>
<li><a href=”../gallery.html”>Gallery</a>
<ul>
<li><a href=”../download.html”>Download</a></li>
<li><a href=”../photos.html”>Photos</a></li>
</ul>
</li>
</ul>
</div>

<div id=”navMenu”>
<ul>
<li><a href=”../videos.html”>Videos</a>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>

<div id=”navMenu”>
<ul>
<li><a href=”../contact.html”>Contact</a>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>[/CODE]

[CODE]#navMenu {
margin:0;
padding:0;
}

#navMenu ul {
margin:0;
padding:0;
line-height:30px;
}

#navMenu li {
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
background-color:#f0eccd;
}

#navMenu ul li a {
text-align:center;
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
text-decoration:none;
width:85px;
height:30px;
display:block;
color:#ff9a29;
}

#navMenu ul ul {
position:absolute;
visibility:hidden;
top:30px;
}

#navMenu ul li:hover ul {
visibility:visible;
}

#navMenu li:hover {
background-color:#ff9a29;
}

#navMenu ul li:hover ul li a:hover {
background:#ff9a29;
color:#FFF;
}

#navMenu a:hover {
color:#FFF;
}

#navMenu ul li:hover a {
color:#fff;
}[/CODE]

Thanks
Thomas

to post a comment
CSS

8 Comments(s)

Copy linkTweet thisAlerts:
@pwinfreyJun 17.2011 — All of your menus are using the same id. Ids by definition are unique.
Copy linkTweet thisAlerts:
@TomTom100authorJun 17.2011 — Ok, so is there a way for me to fix it?


Thanks

Thomas
Copy linkTweet thisAlerts:
@pwinfreyJun 17.2011 — Use a class. class="navmenu" instead of id="navmenu"

Your CSS will be .navmenu instead of #navmenu.
Copy linkTweet thisAlerts:
@TomTom100authorJun 18.2011 — Sorry, I don't really understand! I'm not really very good at CSS.

Please could you explain in more detail? ?


Thanks

Thomas
Copy linkTweet thisAlerts:
@pwinfreyJun 18.2011 — [CODE]<div class="navMenu">
<ul>
<li><a href="../index.html">Home</a>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>


<div id="navMenu">
<ul>
<li><a href="http://about.me/thomashochkins">About</a>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>


<div class="navMenu">
<ul>
<li><a href="../gallery.html">Gallery</a>
<ul>
<li><a href="../download.html">Download</a></li>
<li><a href="../photos.html">Photos</a></li>
</ul>
</li>
</ul>
</div>

<div class="navMenu">
<ul>
<li><a href="../videos.html">Videos</a>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>


<div class="navMenu">
<ul>
<li><a href="../contact.html">Contact</a>
<ul>
<li></li>
<li></li>
</ul>
</li>
</ul>
</div>[/CODE]


[CODE].navMenu {
margin:0;
padding:0;
}

.navMenu ul {
margin:0;
padding:0;
line-height:30px;
}

.navMenu li {
margin:0;
padding:0;
list-style:none;
float:left;
position:relative;
background-color:#f0eccd;
}

.navMenu ul li a {
text-align:center;
font-family:Arial, Helvetica, sans-serif;
font-weight:bold;
text-decoration:none;
width:85px;
height:30px;
display:block;
color:#ff9a29;
}

.navMenu ul ul {
position:absolute;
visibility:hidden;
top:30px;
}

.navMenu ul li:hover ul {
visibility:visible;
}

.navMenu li:hover {
background-color:#ff9a29;
}

.navMenu ul li:hover ul li a:hover {
background:#ff9a29;
color:#FFF;
}

.navMenu a:hover {
color:#FFF;
}

.navMenu ul li:hover a {
color:#fff;
}[/CODE]
Copy linkTweet thisAlerts:
@TomTom100authorJun 18.2011 — Thanks for your help!


But I don't think I worded the question well at the start. I meant how can I change the background color of just the drop down items and not the top ones? Presumably I should still keep it as a class though (.navMenu)


Sorry for my error

Thanks

Thomas
Copy linkTweet thisAlerts:
@djadejonesJun 18.2011 — not 100&#37; on this because i only have basic knowledge of css too but i think what i would do is give the top link (list item) a class of outer for example and then the inner links (list items) a class of outer and then in your css rather than having your background-color on .navmenu li you can have it on .outer or .inner and it should just change one or the other.

Hope this helps (or it could just all be waffle).
Copy linkTweet thisAlerts:
@TomTom100authorJun 19.2011 — Yes, thank you! That did the job perfectly!


Thanks ?

Thomas
×

Success!

Help @TomTom100 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...