View Full Version : Drop down menus - css or javascript and in general...
pepsi_max2k
07-10-2007, 08:17 PM
Hey, I'm just re-designing my site and adding a drop-down menu bar, and just wondered wherther it would be better to do it in javascript or css or at all for a few reasons..
fwiw, here's an example of my two options:
css: http://www.cssplay.co.uk/menus/final_drop.html
javascript: http://vista-buttons.com/
1) touch screens. iphone users now have them, hopefully i'll have one within a year... but i know javascript's mouseover event doesn't work with the iphone. dunno how well it will work with css though... what's the advice for designing hover based dropdowns to view on touchscreens? are they just never gonna work?
2) javascript or css, which is better in general? i dont like all the IE tweaks needed with css but i don't know if i'd have just as many compatibility probs with javascript.
3) should i bother at all? think that's about it...
thanks.
_Aerospace_Eng_
07-10-2007, 09:02 PM
I believe the iphone uses a mobile version of Safari so it should support the CSS menus just fine.
IE6 will need a sprinkle of javascript to get the menus to work.
I've never really liked the way cssplay does its drop down menu. I recommend the menu tutorial here. http://www.alistapart.com/articles/dropdowns/
pepsi_max2k
07-10-2007, 09:07 PM
thanks. will a dropdown-on-hover css menu actually work on a touch screen? or would it have to be an on-click kinda thing? that doesn't bother me so much as i can just have the main menu link link to a seperate index page for anyone who can't get hovers, but it's nice to plan ahead :)
_Aerospace_Eng_
07-10-2007, 09:34 PM
You would probably have to use a:focus as well as a:hover for the drop down to work on a touch screen. If you have Dreamweaver CS3 then you have Device Central which is basically an emulator of how your site will look on mobile devices. I don't know if the iphone is included yet.
pepsi_max2k
07-11-2007, 01:52 PM
had to do a lot of editing of the list apart code, using the author's new version ( http://www.htmldog.com/articles/suckerfish/dropdowns/ ) and a slightly edited version ( http://www.cssdrive.com/index.php/examples/exampleitem/css_drop_down_menu/ ) but have ended up with something pretty good :cool: code below if anyone wants to check it out. it has varying size menu colums, just simple text for the root menu links, and some much nicer looking menu boxes...
fwiw, didn't put the a:focus on most of the stuff as it makes anything that's clicked stay that way until something else is clicked (eg highlighted links look same as hovered links).
/*###### Start Menu CSS ######*/
#cssdropdown, #cssdropdown ul {
padding:0px;
margin: 0;
list-style: none;
z-index: 9999;
}
#cssdropdown li {
float: left;
position: relative;
z-index: 9999;
}
#cssdropdown li>ul {
top: auto;
}
#cssdropdown li ul {
left: -999em;
}
#cssdropdown li:hover ul, #cssdropdown li:focus ul, #cssdropdown li.sfhover
ul {
left: auto;
display: block;
}
/* Root link formatting */
.mainitems a {
display: block;
padding-right: 10px;
text-decoration: none;
font-weight:bold;
color: #FDED8F;
}
.mainitems a:hover, .mainitems a.sfhover {
color: black;
}
/* Menu box formatting */
#cssdropdown ul {
padding:2px;
}
.subuls {
position: absolute;
margin: 0px;
list-style-type: none;
padding: 2px;
background-color: #FFED88;
border: solid 1px #9D9D9D;
}
.subuls li {
width: 100%;
}
/* Menu link formatting */
.subuls li a {
display: block;
margin: 0;
padding: 2px;
border: 1px solid #FDED8F;
background: #FFF5BF;
font-weight: normal;
font-family: Tahoma;
font-size: 8pt;
color: black;
}
/* Menu link hover formatting */
.subuls li a:hover, .subuls li a.sfhover {
display: block;
padding: 2px;
border: 1px solid #927773;
background: #FFFFFF;
color: black;
}
#restofcontent { /*wrap rest of content of the page inside this div*/
clear: left;
}
/*###### End Menu CSS ######*/
<script type="text/javascript"><!--//--><![CDATA[//><!--
sfHover = function() {
var sfEls = document.getElementById
("cssdropdown").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp("
sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//--><!]]></script>
<ul id="cssdropdown">
<li class="mainitems">
<a href="http://www.cssdrive.com">HOME</a>
<ul class="subuls" style="width: 10em">
<li><a href="http://www.alistapart.com/articles/dropdowns/">Gordon
Mac</a></li>
<li><a href="http://www.htmldog.com/articles/suckerfish/dropdowns/">Juiced
Thoughts</a></li>
<li><a
href="http://www.cssdrive.com/index.php/examples/exampleitem/css_drop_down_me
nu/">The Daily Flight</a></li>
<li><a href="">GrapeFruit</a></li>
</ul>
</li>
<li class="mainitems">
<a href="http://www.cssdrive.com/index.php/examples/">ARCHIVES</a>
<ul class="subuls" style="width: 15em">
<li><a href="">CSS2 Generated Content</a></li>
<li><a href="">Custom scrollbar colors</a></li>
<li><a href="">Markerless and "no indent" Lists</a></li>
</ul>
</li>
<li class="mainitems">
<a href="http://www.cssdrive.com/index.php/examples/">GIGS</a>
<ul class="subuls" style="width: 3.5em">
<li><a href=""> 23</a></li>
<li><a href=""> 2444</a></li>
<li><a href=""> 2444</a></li>
</ul>
</li>
</ul>
<div id="restofcontent">
rest of page
</div>
_Aerospace_Eng_
07-11-2007, 08:45 PM
I was just suggesting a:focus because you said you wanted it to work on the iphone. You can supply a seperate stylesheet for portable devices by using the media attribute in the link to the stylesheet.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.