Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

CSS Forum


You are currently viewing our CSS Forum as a guest. Please register to participate.
Login



Reply
Multiple styles for <ul> in dropdown menu: seeking advice
Old 06-18-2009, 02:24 PM Multiple styles for <ul> in dropdown menu: seeking advice
Average Talker

Posts: 16
Name: Brian
Trades: 0
Hello,
I'm working on a css driven dropdown menu and would like to style the different dropdowns (lists) differently. Mainly, I just need the background image, width and height of each list to vary.

For example, here are two dropdowns which I've identified with unique <ul> IDs ("cat_1_drop" and "cat_2_drop"). The <ul> for the entire menu system is called "navbar".

HTML Code:
<ul id="navbar">
 
 <li><a id="cat_1" href="#"><span>1st Category</span></a>
  <ul id="cat_1_drop">
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
  <li><a href="#">Link 4</a></li>
  <li><a href="#">Link 5</a></li>
  </ul>
 </li>
 
<li>
 
<li><a id="cat_2" href="#"><span>2nd Category</span></a>
  <ul id="cat_2_drop">
  <li><a href="#">Link 1</a></li>
  <li><a href="#">Link 2</a></li>
  <li><a href="#">Link 3</a></li>
  <li><a href="#">Link 4</a></li>
  </ul>
 
</li>
</ul>
Code:
 
#navbar {
 font-family:Verdana, Arial, Helvetica, sans-serif;
 font-size: 11px;
 margin: 0;
 padding: 0;
 height: 30 px;
 width: 732 px;
 margin-top: 116px;
}
 
#navbar li {
 list-style: none;
 float: left; 
 text-decoration: none;
 display: inline;
 padding: 0;
 margin: 0;
 }
 
#navbar li a {
 display: block;
 text-decoration: none;
}
 
#navbar li a:hover {
 font-weight:bold;
}
 
#navbar li ul {
display: none;
background-image: url(../images/menus/top_nav/about_us_drop_bg.jpg);
}
 
#navbar  li:hover ul, #navbar li.hover ul {
display: block;
position: absolute;
text-align:center;
margin: 0;
padding: 0; 
width: 116px;
height: 126px;
padding-top:25px;
line-height: 22px;}
 
#navbar  li:hover li, #navbar li.hover li {
float: none; }
 
#navbar  li:hover li a, #navbar li.hover li a {
color: #000; 
} 
 
 
 
 #cat_1_drop li ul {
 display: none;
 background-image: url(../images/menus/top_nav/about_us_drop_bg.jpg);
 }
 
 #cat_1_drop li:hover ul, #navbar li.hover ul {
 display: block;
 position: absolute;
 text-align:center;
 margin: 0;
 padding: 0; 
 width: 116px;
 height: 126px;
 padding-top:25px;
 line-height: 22px;}
 
 #cat_1_drop li:hover li, #navbar li.hover li {
 float: none; }
 
 #cat_1_drop li:hover li a, #navbar li.hover li a {
 color: #000; 
 
 } 
 
 
 
 #cat_2_drop li ul {
 display: none;
 background-image: url(../images/menus/top_nav/about_coffee_drop_bg.jpg);
 }
 
 #cat_2_drop li:hover ul, #navbar li.hover ul {
 display: block;
 position: absolute;
 text-align:center;
 margin: 0;
 padding: 0; 
 width: 146px;
 height: 130px;
 padding-top:25px;
 line-height: 22px;}
 
 #cat_2_drop li:hover li, #navbar li.hover li {
 float: none; }
 
 #cat_2_drop li:hover li a, #navbar li.hover li a {
 color: #000; 
 
 }
I thought the IDs on the nested <ul> tags would override the style on the "navbar" <ul> but they don't seem to. If I strip out the redundancies between the "navbar" <ul> and the "cat" <ul>s (such as background-image tags. then the list just doesn't even show a bg image. Can anyone tell me what I'm doing wrong? Thanks for any help.
mistercheezit is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-18-2009, 02:28 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
EricReese's Avatar
Super Talker

Posts: 137
Name: Eric Reese
Location: Maryland, USA
Trades: 0
Can you post a link to the website? Also, what browser(s) does this occur in?
__________________
I am 17 years old.Looking for Web Design Job(s). If interested use my
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Funny Line- "I'll Twitter your Yahoo! until I Google all over your FaceBook :D
EricReese is offline
Reply With Quote
View Public Profile Visit EricReese's homepage!
 
Old 06-18-2009, 02:39 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
Average Talker

Posts: 16
Name: Brian
Trades: 0
You can see what I'm working on here http://brianonweb.com/clients/LFT/top_menu.html

I've been testing in Firefox but just looked at IE and noticed that it has its own set of issues. This is frustrating, I'm trying to avoid a javascript menu system.

"cat_1" and "cat_2" are actually "about_us" and "about_coffee" on the page.

See how the "About Coffee" list should be wider than, say, "Flagstaff"? I'm creating separate bg images for each dropdown so that it appears like the dropdowns come down behind that organic edge.
mistercheezit is offline
Reply With Quote
View Public Profile
 
Old 06-18-2009, 03:36 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
EricReese's Avatar
Super Talker

Posts: 137
Name: Eric Reese
Location: Maryland, USA
Trades: 0
Your menu <li> is out of place. This is weird. I actually have a problem I can't solve So I sort of cheated and decided to use a conditional comment. Add this in:

Code:
<!--[if IE 7]>
<style type="text/css">
#navbar li{margin-top:-40px;}
</style>
<![endif]-->
Fixes your problem, but hopefully someone who isn't having a brain fart today can solve it and explain it. I am interested in this answer. Isn't anything I can think of....good question OP.
__________________
I am 17 years old.Looking for Web Design Job(s). If interested use my
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Funny Line- "I'll Twitter your Yahoo! until I Google all over your FaceBook :D
EricReese is offline
Reply With Quote
View Public Profile Visit EricReese's homepage!
 
Old 06-18-2009, 03:43 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
One thing I see right away is that you have not cleared the floats in your list. The easiest way to do this is to add overflow: auto to the #navbar ul, then your floated list items will be 'contained' within the UL itself, as you intended it to be.

Quote:
IE and noticed that it has its own set of issues. This is frustrating, I'm trying to avoid a javascript menu system.
IE has been frustrating web designers all along.. and it still is! You won't need a javascript solution, but you most likely will need separate css files just to hold the 'fixes' needed to make IE behave correctly, called by conditional comments in your html.

Unfortunately, it's really whacked in IE6, haven't looked at it with IE7, and we don't have IE8, but that at least should behave more like Firefox that it's predecessors.

I'll have to download it and pick thru the code for the solution.
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Last edited by LadynRed; 06-18-2009 at 03:47 PM..
LadynRed is offline
Reply With Quote
View Public Profile
 
Old 06-18-2009, 04:06 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
EricReese's Avatar
Super Talker

Posts: 137
Name: Eric Reese
Location: Maryland, USA
Trades: 0
Well it turns out that the reason it was occuring is because it had hasLayout. So put clear:both; on .topnav and then bring the menu down with margin. (#navbar will need margin-top:116px)

This fixes it perfectly in IE7. I don't have IE6 to test so let me know if I need to upload it to my site and then use browsershots.org to view IE6

Cheers
__________________
I am 17 years old.Looking for Web Design Job(s). If interested use my
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Funny Line- "I'll Twitter your Yahoo! until I Google all over your FaceBook :D
EricReese is offline
Reply With Quote
View Public Profile Visit EricReese's homepage!
 
Old 06-18-2009, 04:13 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
Average Talker

Posts: 16
Name: Brian
Trades: 0
Thank you for the tips on the IE correction and clearing the floats. I'm still not sure how to solve the main problem which is (simplified):

How do I get the different nested lists to have separate id styles applied (bg images, heights and widths)? The generic structure of the html is:

HTML Code:
 
<ul>
     <li>Dropdown 1
     <ul>
     <li>1</li>
     <li>2</li>
     <li>3</li>
     </ul>
     </li>
 
     <li> Dropdown 2
     <ul>
     <li>1</li>
     <li>2</li>
     <li>3</li>
     </ul>
     </li>
<ul>
 
Shouldn't I be able to assign classes or categories to the containing <ul> and the nested <ul>s? Like so:

HTML Code:
 
<ul id="navbar">
 
  <li><a href="#">About Us</a>
  <ul id="about_us_drop">
  <li><a href="#">Our Roastery</a></li>
  <li><a href="#">Our Menu</a></li>
  <li><a href="#">Our History</a></li>
  </ul>
  </li>
 
  <li>
  <li><a href="#">About Coffee</a>
  <ul id="about_coffee_drop">
  <li><a href="#">Growing &amp; Processing</a></li>
  <li><a href="#">Roasting</a></li>
  </ul>
  </li>
 
</ul>
 
mistercheezit is offline
Reply With Quote
View Public Profile
 
Old 06-18-2009, 04:29 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
Average Talker

Posts: 16
Name: Brian
Trades: 0
Maybe I should wrap the whole thing in a div called "navbar" and take the id "navbar" out of the first <ul> listing? Does this seem plausible?

HTML Code:
 
<div id="navbar">
<ul>
 
  <li><a href="#">About Us</a>
  <ul id="about_us_drop">
  <li><a href="#">Our Roastery</a></li>
  <li><a href="#">Our Menu</a></li>
  <li><a href="#">Our History</a></li>
  </ul>
  </li>
 
  <li>
  <li><a href="#">About Coffee</a>
  <ul id="about_coffee_drop">
  <li><a href="#">Growing &amp; Processing</a></li>
  <li><a href="#">Roasting</a></li>
  </ul>
  </li>
 
</ul>
</div>
 
mistercheezit is offline
Reply With Quote
View Public Profile
 
Old 06-18-2009, 05:03 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
Average Talker

Posts: 16
Name: Brian
Trades: 0
Hold on...I may have it. Tagging #drop_ID_name to a couple #navbar selections seems to work. I just have to create duplicates. Like so:

Code:
 
 #navbar li ul#about_us_drop {
 display: none;
 overflow: auto;
 background-image: url(../images/menus/top_nav/about_us_drop_bg.jpg);
 }
  
 #navbar  li:hover ul#about_us_drop, #navbar li.hover ul#about_us_drop {
 display: block;
 position: absolute;
 text-align:center;
 margin: 0;
 padding: 0; 
 padding-top:25px;
 line-height: 22px;
 width: 116px;
 height: 126px;
 
 }
Code:
 
 #navbar li ul#about_coffee_drop {
 display: none;
 overflow: auto;
 background-image: url(../images/menus/top_nav/about_coffee_drop_bg.jpg);
 }
  
 #navbar  li:hover ul#about_coffee_drop, #navbar li.hover ul#about_coffee_drop {
 display: block;
 position: absolute;
 text-align:center;
 margin: 0;
 padding: 0; 
 padding-top:25px;
 line-height: 22px;
 width: 146px;
 height: 130px;
 
 }
mistercheezit is offline
Reply With Quote
View Public Profile
 
Old 06-18-2009, 06:22 PM Solved
Average Talker

Posts: 16
Name: Brian
Trades: 0
It may not be the best way, but it seems to work (including a few IE conditional stylesheets):

http://brianonweb.com/clients/LFT/top_menu.html

I'm taking this down soon but the fix was tagging the ID with each other instead of a separate designation:

Code:
 
 #navbar li ul#about_us_drop {
 display: none;
 overflow: auto;
 background-image: url(../images/menus/top_nav/about_us_drop_bg.jpg);
 }
 
 #navbar  li:hover ul#about_us_drop, #navbar li.hover ul#about_us_drop {
 display: block;
 position: absolute;
 text-align:center;
 margin: 0;
 padding: 0; 
 padding-top:25px;
 line-height: 22px;
 width: 116px;
 height: 126px;
 
 }
The HTML which pulls in the CSS:

HTML Code:
 
<ul id="navbar">
 
    <li><a id="about_us" href="#" title"About Us"><span>About Us</span></a>
  <ul id="about_us_drop">
  <li><a href="#">Our Roastery</a></li>
  <li><a href="#">Our Menu</a></li>
  <li><a href="#">Our History</a></li>
  <li><a href="#">Contact Us</a></li>
  <li><a href="#">Favorite Links</a></li>
        </ul>
 </li>
 
</ul>
 
Thanks for your help.
mistercheezit is offline
Reply With Quote
View Public Profile
 
Old 06-18-2009, 08:01 PM Re: Multiple styles for <ul> in dropdown menu: seeking advice
LadynRed's Avatar
Defies a Status

Posts: 10,017
Location: Tennessee
Trades: 0
Quote:
So put clear:both; on .topnav
I already told the OP to clear his floats and how to do it.
Quote:
the fix was tagging the ID with each other instead of a separate designation:
In other words, the fix had to do with specificity and being MORE specific
__________________
Web Goddess & Web Standards Evangelist :) - Tables Be Gone !!

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

LadynRed is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Multiple styles for <ul> in dropdown menu: seeking advice
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.83629 seconds with 12 queries