CSS - Css Menus
Hi there.
I've become fond of the idea of non-javascript menus. I've been experimenting a little. So with help from various sources I managed to get a simple set working. I have this... Code: #menu ul li > ul { display: none; position: absolute; top: 18px; left: 0; width: 170px; } which correctly 'hides' the sub-menu. Then I have this Code: #menu ul li:hover > ul { display: block; } which should 'unhide' the sub-menu. Now, because I'd had success with the menu, I thought I should now look at validating my html and css. So far, I've just looked at the html part. My question is, why does it work with this code (which doesn't validate under Strict doctype)? Code: <div id="menu"> <ul> <li class="small"><a href="blah.php">About</a> <li>Details On... <ul> <li class="small"><a href="blah.php">Registering</a> </ul> </ul> </div> and not this (which does validate)? Code: <div id="menu"> <ul> <li class="small"><a href="blah.php">About</a></li> <li>Details On...</li> <li> <ul> <li class="small"><a href="blah.php">Registering</a></li> </ul> </li> </ul> </div> I'll listen to any thoughts on this, even the use (or not) of doctype strict. Thanks for listening! Stay JOLLY H Similar TutorialsPlease help me. This is driving me crazy. I am getting a problem in IE and I can't seem to figure out how to fix it. Of course, it works just fine in Firefox, but not IE. In IE, go to to this page. On the horizontal drop-down menu, go to "Guides." Then scroll through the three drop-down options and back up. Notice how the 3rd level menu suddenly dissapears behind the 2nd level menu? Here's the portion of my CSS file controling the menu: Code: /********** LAYOUT - HEADER **********/ #header {background: #ffffff; margin-top: 10px; margin-bottom: 25px; padding: 0 0 8px;} img.headerimg {margin-left: 25px;} /** NAV - top horizontal nav **/ #nav, #nav ul {padding: 0; margin: 0; list-style: none} #nav {height:1.5em; font: 80% arial; margin-top: 1em; margin-left: 75px;} #nav li {position:relative; float: left; width: auto; display:block; margin: 0; padding:0} #nav a {display: block; padding: 3px 10px 2px; border-bottom: 1px solid rgb(98,61,15); border-top: 1px solid rgb(98,61,15);} /************* 2nd tier *************/ #nav li ul {width: 15em; position: absolute; left: -999em; background: #ffffff} #nav li:hover ul, #nav li.sfhover ul {left: 10px; z-index:55555} #nav li li {background:#9BCD9B; float:none; border: 1px solid rgb(98,61,15); border-top: none; padding-left: 0} #nav li li a, #nav li li a:link, #nav li li a:visited, #nav li li a:hover {color:#000; padding: 3px 10px; border-bottom: none; border-top: none;} #nav li li a:hover {color: #000; background: #FFDAB9;} #nav li.active {background: #FFDAB9;} #nav li.active a {color: #000000} /************* 3rd tier *************/ #nav li ul ul {width: 30em; font-size: 100%; margin-left: 7em; margin-top: -.7em} #nav li:hover ul ul, #nav li.sfhover ul ul {left: -999em;} #nav li li:hover ul, #nav li li.sfhover ul {left: auto;} #nav li li li {background: #f6f6f6; border-top: 1px solid #fff;} #nav li li li a, #nav li li li a:link, #nav li li li a:visited, #nav li li li a:hover {color: #006400} /************* 4th tier *************/ #nav li ul ul ul{width: 30em;} #nav li:hover ul ul ul, #nav li.sfhover ul ul ul {left: -999em;} #nav li li li:hover ul, #nav li li li.sfhover ul {left: auto;} #nav li li li li {background: #FFDAB9;} #nav li li li li a:hover {color: #000; background: #9BCD9B;} Please help me! Thanks! Manny Hi, I wanted to do a horizontal popout menu. I have the code and it works but I am trying to undertsand it better. It uses a csshover.htc file which i didn't download but the thing still works fine with a ie sniffer code in it. It doesn't use any javascript which I thought it needed. There seems a few ways to do expanding menus in css (with/without javascript)? Menus are more complicated than they look but I would some explanation on the above points before i continue. i have 2 menus on my page. one is a vertical sliding menu & other is a floating menu. i want the vertical sliding menu to slide over the floating menu. i tried giving the floating menu a z-index of -2 since the vertical menu has z-index of -1. but it doesn't work coz the floating menu disappears. the vertical menu is written with tables while the floating menu has a div tag around it. this is the style for the vertical menu Code: table.topnav {position: relative; top: 0; left: 0; padding-left: 2px; } table.menu {position: absolute; bottom: 0; z-index: -1; } .pad{padding-top: 2px;} .banner{z-index: 1; position: relative;} and this is the style for the floating menu Code: <script> if (!document.layers) document.write('<div id="divStayTopLeft" style="position:absolute">') </script> thank you xia I am very new to this whole css thing, but am trying to get all learned about it. I think I am doing badly so far. I am trying to make css drop-down menus, and have pulled code from all over the place, and modified it to look correct (so as to match my design comp). it is based on the suckerfish model <http://www.alistapart.com/articles/dropdowns/> and it works exactly as it should in safari, firefox (mac & pc). but doesn't work correctly at all in IE (mac or pc). I have implemented the "ie fix" with the javascript code several sites instructed me to use, and while it now sorta works (in the sense that the menus drop down), there are still problems. such as in IE on pc you can't roll down to the drop down menus, because they go away as soon as you roll off the top menu item. in IE on mac they are messed up in a whole other way. you can roll down to them, and they don't go away as soon as you're off the top nav option, but the hover is all jacked, and the menu is broken, sending the last nav button down to the next line! aaahhh! can anyone help me?! I'm sorry I'm so stupid and helpless, but... well. I am. any tips/etc would be mighty appreciated! -daniel In today's Website Development world, which kind of Drop Down menus do the pro's prefer to use, pure CSS without Javascript or CSS with Javascript? And also, can pure CSS Drop Down menus be used in Dynamic Websites? Thank you. Hi All, I seem to have made a mistake in installing a CSS drop-down menu b/c despite my best efforts, I cannot seem to make it work in Internet Explorer. I am using the Suckerfish method found http://www.alistapart.com/articles/dropdowns My CSS file is here And a sample page can be found here Does anyone see a mistake I made? All other browsers work beautifully, so the problem must lie in the Internet Explorer hack. Thank you for your time and assistance. I am working on building my first website in 2 years. I am very interested in developing a good site interface with standard code that may be easily edited later. Specifically, I am interested in creating dynamic navigation menus that will be supported by as many browsers as possible. I have seen dynamic menus created with javascript, but I know I don't want to do that since some browsers do not support it/or do not have it enabled by default. Can you comment on whether or not CSS would be a good solution to get around this problem? I have never used CSS to create menus in the past, but it seems very useful for standardizing a site interface. I am also open to other suggestions, what would you do to accomplish this task? Hello, I'm trying to replace one CSS nav menu with another, is there anyone who is familiar enough to assist me? I've been grappling with this for a long while now. I pretty much have it working, except for the life of me I cannot get the drop down menus to appear under the corresponding link. position: absolute makes the menus always appear off to the left. Does anyone know what the secret is to this? Code: <div id="nav_wrapper"> <div id="nav_bar"> <div id="nav_content"> <ul id="nav_ul"> <li><a href="/">Home</a></li> <li><a href="/forum/">Forum</a> <div class="nav_subcontent"> <ul> <li><a href="/forum/search.php">Search</a></li> <li><a href="/forum/memberlist.php">Members</a></li> </ul> </div> </li> <li><a href="#">A link without a menu</a></li> </ul> </div> </div> </div> Code: /* Wrapper */ #nav_wrapper { clear: both; } /* Bar */ #nav_bar { background: url('images/nav_swish_fade.jpg'); background-repeat: repeat-x; height: 36px; } /* All the buttons within the bar, the middle portion */ #nav_content { display: inline; margin: 0 auto; text-align: center; background: #fff; height: 36px; } /* Entire unordered list */ #nav_ul { list-style: none; position: relative; } /* Top level unordered list */ #nav_content ul>li { display: block; } /* Top level unordered list links */ #nav_content ul>li a { display: block; float: left; padding: 9px; margin-left: 2px; margin-right: 2px; } /* Menus */ .nav_subcontent { display: none; position: absolute; background: #222; margin-top: 8px; } /* Menu link */ #nav_content .nav_subcontent a { display: block; padding: 9px 20px 9px 0; margin-left: -5px; text-align: left; min-width: 100px; } /* Show menus */ #nav_content ul>li:hover .nav_subcontent { display: block; } I have this test site using CSS drop down menus, but when you scroll over, they disappear. Seems to be happening in IE9, Firefox and Chrome. Can't figure it out. Any help would be appreciated! Here is the script: Code: <head> <title>Untitled Document</title> <style type="text/css"> body {background-color: #FFFFFF; font-family: verdana, arial; font-size: 10pt; font-weight: bold; color: #0000ff;} .box1 { width: 1000px; height: 600px; position:relative; left: 150px; top: 0px; } .blue_box { width: 900px; position:absolute; top: 5px; left: 20px; height: 15px; } .box2 { width: 1050px; position:absolute; top: 40px; left: 20px; height: 15px; z-index: 2; } .main_image { position: relative; top: 3px; } .pic_box { width: 738px; /* 10px longer than actual jpg */ position:absolute; top: 75px; height: 167px; left: 20px; z-index; 1; } .text_box1 { width: 738px; position:absolute; top: 218px; height: 159px; left: 26px; border-color: #ff0000; } .education_box { width: 881px; position:absolute; top: 321px; height: 350px; left: 21px; } .top_news_box { width: 136px; position:absolute; top: 1px; height: 317px; margin-left: 5px; left: 715px; border-color: #ff0000; } /*Credits: Dynamic Drive CSS Library */ /* Top menu */ .menu ul{ padding: 3px 0; margin-left: 0; margin-top: 1px; margin-bottom: 0; font: bold 12px Verdana; list-style-type: none; text-align: center; /*set to left, center, or right to align the menu as desired*/ } .menu li{ display: inline; margin: 0; } .menu li a{ text-decoration: none; padding: 5px 7px; margin-right: 5px; border: 1px solid #778; color: white; background: #3282c2; border-radius: 8px; /*w3c border radius*/ box-shadow: 3px 3px 4px rgba(0,0,0,.5); /* w3c box shadow */ -moz-border-radius: 8px; /* mozilla border radius */ -moz-box-shadow: 3px 3px 4px rgba(0,0,0,.5); /* mozilla box shadow */ background: -moz-linear-gradient(center top, #a4ccec, #72a6d4 25%, #3282c2 45%, #357cbd 85%, #72a6d4); /* mozilla gradient background */ -webkit-border-radius: 8px; /* webkit border radius */ -webkit-box-shadow: 3px 3px 4px rgba(0,0,0,.5); /* webkit box shadow */ background: -webkit-gradient(linear, center top, center bottom, from(#a4ccec), color-stop(25%, #72a6d4), color-stop(45%, #3282c2), color-stop(85%, #357cbd), to(#72a6d4)); /* webkit gradient background */ } .menu li a { background: darkred; background: -moz-linear-gradient(center top, #f5795d, #e55e3f 25%, #d02700 45%, #e55e3f 85%, #f5795d); background: -webkit-gradient(linear, center top, center bottom, from(#f5795d), color-stop(25%, #e55e3f), color-stop(45%, #d02700), color-stop(85%, #e55e3f), to(#f5795d)); } .menu li a:hover{ color: #FFFFFFF; background:#0033CC; } /* Drop down menu buttons */ .blue ul { /* For all tags under <ul> (main and sub) */ padding: 3px 0; margin-left: 0; margin-top: 1px; margin-bottom: 0; font: bold 10pt Verdana; list-style-type: none; text-align: center; /*set to left, center, or right to align the menu as desired*/ } .blue li { /* Sets the properties associated with <li> */ display: inline; /* Sets li tags horizontal(main and sub) */ position: relative; margin: 0; } .blue li a { /* Sets the properties associated for all anchor tags */ text-decoration: none; padding: 5px 7px; margin-right: 15px; /* Sets margin to 15px, which spaces out each menu button by 15px */ border: 1px solid #778; color: white; background: #3282c2; border-radius: 8px; /*w3c border radius*/ box-shadow: 3px 3px 4px rgba(0,0,0,.5); /* w3c box shadow */ -moz-border-radius: 8px; /* mozilla border radius */ -moz-box-shadow: 3px 3px 4px rgba(0,0,0,.5); /* mozilla box shadow */ background: -moz-linear-gradient(center top, #a4ccec, #72a6d4 25%, #3282c2 45%, #357cbd 85%, #72a6d4); /* mozilla gradient background */ -webkit-border-radius: 8px; /* webkit border radius */ -webkit-box-shadow: 3px 3px 4px rgba(0,0,0,.5); /* webkit box shadow */ background: -webkit-gradient(linear, center top, center bottom, from(#a4ccec), color-stop(25%, #72a6d4), color-stop(45%, #3282c2), color-stop(85%, #357cbd), to(#72a6d4)); /* webkit gradient background */ } .blue li ul { /* Sets the properties for all li ul (sub menus). Rest is inherited */ position: absolute; /* All settings (e.g. left, top, etc.) will be relative to the top menu buttons (non sub menu buttons) */ left: 1px; display: none; /* Blocks all sub menu tags */ } .blue li:hover ul{ display: block; /* Shows all elements under each other (as opposed to next to each other) */ } .blue li:hover ul a { position: absolute; width: 150px; top: 5px; /* Amount of space the first sub menu starts from the parent button */ border-radius: 8px; text-decoration: none; background-color: #0000FF; padding: 5px; /* Pads area around text 5x in all 4 directions */ border: 1px solid #cccccc; border-bottom: 0; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt; font-weight: bold; color: #FFFFFF; } </style> </head> <body> <div class="box1"> <div class="blue_box"> <div class="menu"> <ul> <li><a href="">Join MSSNY</a></li> <li><a href="">Pay Dues On Line</a></li> <li><a href="">Directory Questionaire</a></li> <li><a href="">MSSNYPAC</a></li> <li><a href="">Grassroots Action Center</a></li> <li><a href="">Member Login</a></li> </ul> </div><!-- Close menu --> </div><!-- Close box2 --> <div class="box2"> <div class="blue"> <ul> <li><a href="#">Home</a></li> <li><a href="#">About MSSNY</a> <ul> <li><a href="#">Divisions</a></li> <li><a href="#">Governance</a></li> <li><a href="#">Committees</a></li> <li><a href="#">Member Sections</a></li> <li><a href="#">House of Delegates</a></li> <li><a href="#">Position Statements</a></li> <li><a href="#">By Laws</a></li> <li><a href="#">Contact Us</a></li> </ul> </li> <li><a href="#">Membership</a> <ul> <li><a href="#">Applications</a></li> <li><a href="#">Pay Dues Online</a></li> <li><a href="#">AAPI Physicians</a></li> <li><a href="#">NYS Medical Directory</a></li> </ul> </li> <li><a href="#">Medical Community</a> <ul> <li><a href="#">County Societies</a></li> <li><a href="#">Speciality Societies</a></li> <li><a href="#">State Societies</a></li> <li><a href="#">Ethnic Medical Associations</a></li> <li><a href="#">American Medical Association</a></li> <li><a href="#">NYS Department of Health</a></li> <li><a href="#">Additional Medical Links</a></li> </ul> </li> <li><a href="#">Public Health</a> <ul> <li><a href="#"></a></li> <li><a href="#"></a></li> <li><a href="#"></a></li> <li><a href="#"></a></li> </ul> </li> <li><a href="#">Physician Advocacy</a> <ul> <li><a href="#"></a></li> <li><a href="#"></a></li> <li><a href="#"></a></li> <li><a href="#"></a></li> </ul> <li><a href="#">Practice Resources</a> <ul> <li><a href="#">WCB Guidelines and Fee Schedule</a></li> <li><a href="#">EHR Implementation Services</a></li> <li><a href="#">CME Physicial Education</a></li> <li><a href="#">MSSNY Online Library</a></li> </ul> </li> </ul> </div> <!-- Close blue --> </div> <!-- Close blue_box --> <div class="pic_box"><img src="050211a_Original.jpg" class="main_image" width="691" height="136" border="0" /> <!-- Close top_news_Box --> <div class="top_news_box"> <p><img src="Facebook-Twitter-Linkedin.JPG" border="0" /></p> <p>Visit the MSSNY Blog Forum. .</p> <p>News of New York<br /> Rate Card and Classifieds </p> <p> MSSNY eNews 6/17/11 </p> <p>MSSNY Legal Resources </p> <p> *** Members Section *** <br /> Members: Click Here</p> <p> Non Members: <br /> Browse Our Benefits Join US </p> <p> <br /> </p> </div> </div> <!-- Close pic_box --> <div class="text_box1">To All New York Physicians: No Tort Reform HOD Ref. Comm. Documents Health Care Reform <br /> <br /> WCB Guidelines and Fee Schedule 6-Credit CME Course on New Workers Compensation <br /> Treatment Guidelines <br /> <br /> Influenza Surveillance: How to become an ILINET Provider for 2010-11 flu season <br /> </div> <div class="education_box"><img src="MED101014-Infection-Course-Image_1.jpg" width="263" height="219" border="0" /> <img src="MED100513-Course-Graphic.jpg" border="0" /></div> <!-- Close pic_box --> </div> </body> </html> I am learning CSS and started to like it I was trying to make an image gallery so was just playing around with this link I got Please see this http://www.cssplay.co.uk/menus/tabmenu.html When I added five more images in this, the last images ceases to display How can I correct that I was testing this by adding this code 5 times <li> <a href="#nogo"> William Turner<br /> (1775-1851) <span> <img src="../img/turner.jpg" alt="painting" title="painting" /> This English painter was one of the greatest romantic interpreters of nature in the history of Western art and is still unrivaled in the virtuosity of his painting of light. </span> </a> </li> I was anticipating that a scrollbar would come automatically in the browser but that dint happen What should I do? Can someone recommend a workaround for this issue I am having please. Rollover the top blue menus to see what i mean. There is an advert appearing in an iframe and it is blocking the drop down menus above it. Z indexes etc don't seem to help. this is the link ( very frustrating you can't post a link - it would make things easier for people to help ) sidouglas.net/nz-tourism-guide-prototype/index.html index.html: Iframe source is the same as the domain; menu can appear above the iframe no problem. index2.html: iframe source references another domain; menu dissapears. index3.html: iframe source is same as domain - but references swf resources from another domain. menu dissapears. Surely someone has faced this same issue? I am tied down to having to a situation with index2.html as there has to be a click tracking registering from another domain. Very frustrating, please help. Thanks. Hello does anyone have any links to good tabs tutorials I been looking at some other and most of the CSS code would not work well but I would just like some links thanks for ur time Dear Forum, I am designing a website using HTML and Java for the drop down menus. Although for one page this seemed ok at the begining, now I want to add links to other catagories where I only want to change the main body of the page. Up to now I have had to insert the Java script into every page I want to link to. The problem is A) The pages blink and the menu is lost while the graphics are being loaded, B) If I need to change the menus in the future I have to change all pages. Is there a way I can use CSS to keep the consistency of the Top and sides of the page and only change the body for other pages. I can do this with frames but I prefer not to use them. The test page can be seen at http://test.kipseli.com Thanks Rob Hi there, I'm trying to integrate some SEO friendly dropdown menus into an existing website design. The trouble I'm experiencing so far is that the body of the design is aligned centre, and most of the examples I've seen thus far use absolute positioning of <div> elements (i.e. the design is left-aligned, so the designer knows to position the dropdown div X pixels). Is there a good reference I can use for positioning my divs properly? Thanks Hi, At work I have to do popup menus (I hate them), so I am trying with all I have to not use Javascript. I have the following working using just CSS and HTML: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US"> <head> <title>Pure CSS Popups</title> <style type="text/css"> body { font-family: Arial; } div#menubar { background-color: steelblue; font-weight: bold; } div#menubar a.menuhead { position: relative; text-decoration: none; margin-right: 18pt; color: darkblue; } div#menubar a.menuhead:hover { color: white; background-color: darkblue; } div#menubar a.menuhead div.menu { visibility: hidden; position: absolute; left: 0; top: 1em; width: 15em; background-color: steelblue; border: 2px solid darkblue; } div#menubar a.menuhead:hover div.menu { visibility: visible; } div#menubar a.menuhead div.menu div.menuitem { width: 100%; cursor: pointer; background-color: steelblue; border-bottom: 1px solid darkblue; } div#menubar a.menuhead div.menu div.menuitem:hover { background-color: darkblue; } div.menuitem a { } </style> </head> <body> <div id="menubar"> <a class="menuhead" href="">Menu 1 <div class="menu"> <div class="menuitem">Menuitem 1</div> <div class="menuitem">Menuitem 2</div> <div class="menuitem">Menuitem 3</div> <div class="menuitem">Menuitem 4</div> <div class="menuitem">Menuitem 5</div> </div> </a> </div> </body> </html> Now what I want to do is put real hyperlinks inside of the menuitem divs. However, when I do so it messes up for some strange reason in both Firefox and IE. If someone could tell me why I would GREATLY appreciate it. Code: <div id="menubar"> <a class="menuhead" href="">Menu 1 <div class="menu"> <div class="menuitem">Menuitem 1</div> <div class="menuitem">Menuitem 2</div> <div class="menuitem"><a href="">Menuitem 3</a></div> <div class="menuitem">Menuitem 4</div> <div class="menuitem">Menuitem 5</div> </div> </a> </div> In Firefox, the menu items after the one with the hyperlink no longer format correctly, and the menu also becomes part of the menubar. In IE it looks ok, but when the mouse is moved over the menuitem hyperlink the menu goes away. In both, the menuitem divs get shrunk down to the width of the text. Any ideas??? I am just being scripting and have been messing with this problem for several hours and still have gotten no where at all so I was hoping for some assistance. I am attempting to make my stacked links open upon mouseover to display all the sublinks beneath the main ones and then close one the mouse is moved away from that area. I have the main ones working, as that is easy, it is those others that have me stumped. I am using outset and inset boarders to make it appear as if a drawer is being pulled out to reveal the sub-links. Any advice would be great, thank you. Im trying to make my site into a CSS layout with dropdown menus. The layout was fine untill i implemented the dropdown menu. Now the center window area is broken. 1. Why is this happening and whats the solution? 2. How can I make the navigation bar extend across the full length of my page area? http://www.nevertap.com/float/ http://www.sdtars.com/development/ I can't figure out why I can't get them to popup over the other menus. Can anyone see what I am doing wrong? Thanks! http://www.cyclomedia.co.uk/?24 took a couple of days to debug for major browsers, the horizontal version doesnt work in ie (even if you fully merge the CSS). if anyone knows what the problem is there then it'd be good to know. what is interesting is that if you look at all the sub menus in IE and then switch to the horiztontal version they work correctly... i think it's something to do with trying to place an absolutely positioned element outside of a float that is also position:relative! (overflow: visible doesnt help BTW) the source is overly spread out and commented, eventually i'll produce a more compact source for both versions. note: the html is the same for the horizontal and vertical versions! one day i'll update my site to be more blog like, allowing comments for each article... one day! edit: atricle/article edit: fixed the IE bug, needed another work around for the general lack of support for the child selector, basically the root menu items need to be floats, but everything below that doesnt. |