View Full Version : CSS menu problems..
Ok so heres the issue.
I created a web template using Photoshop,
I'm trying to code a drop down menu using pre made images as the main menu.
The drop down background is another image.
I am having a hard time getting the whole thing to stay together. Heres my code.
---------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Menu</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
font-family: Arial, sans-serif;
}
body {
margin: 20px;
font-size: 10px;
}
body {
behavior: url(csshover.htc);
}
ul {
list-style: none;
}
ul a {
color: #FFF;
text-decoration: none;
display: block;
padding: 5px 5px 5px 10px;
width: 100px;
background-image:url('images/bg.jpg')
}
ul a:hover {
color: #4BD8FF;
text-decoration: none;
background: #0c4065;
}
ul li {
border-bottom: 1px solid #FFF;
border-right: 1px solid #FFF;
float: left;
position: relative;
}
ul li ul {
list-style: none;
position: absolute;
left: 0;
top: 100%;
display: none;
width: 100px;
border-top: 1px solid #FFF;
}
ul li:hover ul li ul { display: none; }
ul li ul li:hover ul {
display: block;
position: absolute;
left: 115px;
top: -1px;
border-left: 1px solid #FFF;
}
ul li:hover ul { display: block; }
</style>
</head>
<!--Menu Start -->
<!-- Facility -->
<ul>
<li><a href="facility.html"><img border="0" src=images/Menu2_Facility.gif></a>
<ul>
<li><a href="#">Hour of Operation</a></li>
<li><a href="#">Access Requirements</a></li>
<li><a href="#">Amenities</a></li>
<li><a href="#">Reservations ></a>
<ul>
<li><a href="#">Facility Request Form</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<!-- Aquatics -->
<ul>
<li><a href="aquatics.html"><img border="0" src=images/Menu2_Aquatics.gif></a>
<ul>
<li><a href="#">Pool Hours</a></li>
<li><a href="#">Neptune Swimming & Diving</a></li>
<li><a href="#">Private Lessons</a></li>
<li><a href="#">AMR Classes</a></li>
</ul>
</li>
</ul>
------------------------------------------------------------------
I will appreciate any help or tips I can get.
BabyJack
05-04-2008, 08:34 AM
1. Use the [ code] [ /code] (without the spaces) tags to show code
2. Where's this Doctype at? Sort it out! :)
3. I would put the Stylesheet in a different document and include it in the HTML (add <link rel="Stylesheet" type="text/css" href="whatever you called the stylesheet document..css" media="all">
EDIT: And as far as I'm aware, you need Javascript to program Dropdown menus, aswell as CSS. :)
BabyJack
1) sorry I'll go edit that.
2) I left doc type out for sake of shortening the code.
here it is
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3) I do plan on adding the css to its own file once I get it working properly.
Thanks for the tips.
BabyJack
05-04-2008, 08:47 AM
Look at below post!
BabyJack
05-04-2008, 08:51 AM
1. Insert the following style sheet and script into the <head> section of your page:
<style type="text/css"> #dropmenudiv{ position:absolute; border:1px solid black; border-bottom-width: 0; font:normal 12px Verdana; line-height:18px; z-index:100; } #dropmenudiv a{ width: 100%; display: block; text-indent: 3px; border-bottom: 1px solid black; padding: 1px 0; text-decoration: none; font-weight: bold; } #dropmenudiv a:hover{ /*hover background color*/ background-color: yellow; } </style> <script type="text/javascript"> //Contents for menu 1 var menu1=new Array() menu1[0]='<a href="http://www.javascriptkit.com">JavaScript Kit</a>' menu1[1]='<a href="http://www.freewarejava.com">Freewarejava.com</a>' menu1[2]='<a href="http://codingforums.com">Coding Forums</a>' menu1[3]='<a href="http://www.cssdrive.com">CSS Drive</a>' //Contents for menu 2, and so on var menu2=new Array() menu2[0]='<a href="http://cnn.com">CNN</a>' menu2[1]='<a href="http://msnbc.com">MSNBC</a>' menu2[2]='<a href="http://news.bbc.co.uk">BBC News</a>' var menuwidth='165px' //default menu width var menubgcolor='lightyellow' //menu bgcolor var disappeardelay=250 //menu disappear speed onMouseout (in miliseconds) var hidemenu_onclick="yes" //hide menu when user clicks within menu? /////No further editting needed var ie4=document.all var ns6=document.getElementById&&!document.all if (ie4||ns6) document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>') function getposOffset(what, offsettype){ var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop; var parentEl=what.offsetParent; while (parentEl!=null){ totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop; parentEl=parentEl.offsetParent; } return totaloffset; } function showhide(obj, e, visible, hidden, menuwidth){ if (ie4||ns6) dropmenuobj.style.left=dropmenuobj.style.top="-500px" if (menuwidth!=""){ dropmenuobj.widthobj=dropmenuobj.style dropmenuobj.widthobj.width=menuwidth } if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover") obj.visibility=visible else if (e.type=="click") obj.visibility=hidden } function iecompattest(){ return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body } function clearbrowseredge(obj, whichedge){ var edgeoffset=0 if (whichedge=="rightedge"){ var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15 dropmenuobj.contentmeasure=dropmenuobj.offsetWidth if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth } else{ var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18 dropmenuobj.contentmeasure=dropmenuobj.offsetHeight if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up? edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either? edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge } } return edgeoffset } function populatemenu(what){ if (ie4||ns6) dropmenuobj.innerHTML=what.join("") } function dropdownmenu(obj, e, menucontents, menuwidth){ if (window.event) event.cancelBubble=true else if (e.stopPropagation) e.stopPropagation() clearhidemenu() dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv populatemenu(menucontents) if (ie4||ns6){ showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth) dropmenuobj.x=getposOffset(obj, "left") dropmenuobj.y=getposOffset(obj, "top") dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px" dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px" } return clickreturnvalue() } function clickreturnvalue(){ if (ie4||ns6) return false else return true } function contains_ns6(a, b) { while (b.parentNode) if ((b = b.parentNode) == a) return true; return false; } function dynamichide(e){ if (ie4&&!dropmenuobj.contains(e.toElement)) delayhidemenu() else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)) delayhidemenu() } function hidemenu(e){ if (typeof dropmenuobj!="undefined"){ if (ie4||ns6) dropmenuobj.style.visibility="hidden" } } function delayhidemenu(){ if (ie4||ns6) delayhide=setTimeout("hidemenu()",disappeardelay) } function clearhidemenu(){ if (typeof delayhide!="undefined") clearTimeout(delayhide) } if (hidemenu_onclick=="yes") document.onclick=hidemenu </script>
2.: Having done the above, all that's left is setting up your link(s) so a menu drops down. The below sample HTML demonstrates two links, one with the menu dropping down onMouseover, and the other, onClick:
Select All
<a href="default.htm" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, menu1, '150px')" onMouseout="delayhidemenu()">Web Design</a> | <a href="default2.htm" onClick="return dropdownmenu(this, event, menu2, '200px')" onMouseout="delayhidemenu()">News Sites</a> (onclick)
The dropdownmenu() function accepts 4 parameters as shown:
dropdownmenu(this, event, menuarray, 'width')
Only customize the last two parameters (menuarray and 'width'), where:
3. Menuarray- The array contents you wish the menu to display (see code of Step 1).
4. Width- The width of the menu (pass in "" if you simply wish to use the default menu width).
Thats it! If you need more help, just ask!
Here are the images.
http://kragersoft.net/menu/
BabyJack
05-04-2008, 08:59 AM
See if that above code works :) Just edit the code so that you get your dropdown.
you confused me a bit with the javascript. I am trying to accomplish this using css.
I tried to follow your instructions to the best of my knowledge but it didn't do anything.
BabyJack
05-04-2008, 09:06 AM
Hmm... I'm afraid I cannot do anything else :(
Well thanks for trying. I'm going to go to bed and hope that someone can help me in the morning.
BabyJack
05-04-2008, 09:10 AM
Ok,here, in the UK, it is morning!
abduraooft
05-04-2008, 12:02 PM
The above posted code doesn't give any clue regarding the type of your drop down. I think it's a single level menu. Anyway here a good tutorial, http://www.htmldog.com/articles/suckerfish/dropdowns/
Maybe im not explaining this correctly,
Heres my menu now
http://kragersoft.net/menu/Menu.html
I want to replace the top images with my own menu images but leave all the drop down backgrounds the same.
well, that doesn't wokr as it is in ie6. so you will need js if you want ie6 viewers to see it.
Also, suckerfish will do as you want. Just put the images, you want to use, into the css.
bazz
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.