Click to See Complete Forum and Search --> : ugly code...
Jackimalyn
08-28-2006, 08:35 PM
Help...
I finally got my drop down menus working but the code looks like s***:
http://www.tramont.com/CSS/CPGnav.asp
Can anyone help?? I obviously didn't write the code, I thought if I let Fireworks do its thing I could figure out what it did and write some clean code but it looks crappy. ANyone know how I can clean this up??? Thank you---
generally, the best way to make a drop down list is to use a list.
From what I am seeing there exist no list at all.
Then *in short* alter the display state per user behavior(ie. mouseover, mouseout, etc).
For instance, this is most likly were I would start being I've never attempted this before.
<body>
<ul>
<li><a href="">mainone</a></li>
<li><a href="">maintwo</a></li>
<li><a href="">mainthree</a></li>
<li><a href="">mainfour</a></li>
</ul>
</body>
Then to create the nested list nest another list within the current one like so:
<body>
<ul>
<li><a href="">mainone</a></li>
<ul>
<li><a href="">subone</a></li>
<li><a href="">subtwo</a></li>
</ul>
<li><a href="">maintwo</a></li>
<li><a href="">mainthree</a></li>
<li><a href="">mainfour</a></li>
<ul>
<li><a href="">subone</a></li>
<li><a href="">subtwo</a></li>
</ul>
</ul>
</body>
Something like that. Being I have never done this only read about it I can't really offer much more advice. If you want it to be 'clean' then your best bet is creating it from scratch. otherwise, just use what you have.
If you don't know javascript and the DOM it's quite a inticuite process. So i would just recommend starring clear or just using CSS.
Jackimalyn
08-28-2006, 09:09 PM
If I use behaviors though will it write javascript? I was hoping to do it all CSS, the people who view our website tend to be computer illiterate and when they start hearing words like ActiveX and allowing pop ups they think you're crazy.
If JS is necsessary for this technique... I can do it cuz its the best way to organize all this crap.
btw- Thanks tz
That's just a bunch of javascript mouse rollovers, using Macromedia's Javascript (same scripts used in Dreamweaver). Admitedly, Macromedia Javascript is always messy...
You can find cleaner Jscript for free on the web. Try the DevX Javascript Sourcebank (http://archive.devx.com/sourcebank/directorybrowse.asp?currentPage=&numPerPage=15&dir_id=478&showResType=10&adType=web) or learn how Javascript works at DevX's Project Cool (http://www.devx.com/projectcool/).
Jackimalyn
08-28-2006, 09:17 PM
thanks- ill check it out....
If I use behaviors though will it write javascript? I was hoping to do it all CSS, the people who view our website tend to be computer illiterate and when they start hearing words like ActiveX and allowing pop ups they think you're crazy.
Yeah, behaviours will write Javascript. If you want to do it in CSS, you gotta write it yourself (as far as I know).
JPnyc
08-28-2006, 09:26 PM
You can't do this all with CSS unless you plan to exclude IE6. IE6 doesn't support over on anything but links (anchor tags)
Jackimalyn
08-28-2006, 09:35 PM
you'd think that a browser that dominates the market of your average moron would have a few less bugs than it does. I'll stick with my Firefox.
Thanks everyone. I thought I could use all CSS, I really don't wanna use Javascript on the chance someone had it turned off. grrr. (<-- frustration...)
chris_bcn
08-28-2006, 09:56 PM
http://www.htmldog.com/articles/suckerfish/dropdowns/
degrades beautifully, IE requires a tiny bit of JS, but in the unlikely event that your target audience includes people with JS turned off they will still be able to use the top level links
Anything is better than what you have. That's why you never let a machine do any of your coding!
Jackimalyn
08-28-2006, 10:00 PM
I know, I tried to take a shortcut and whip something up in fireworks. I should have known better. that never works. Guess I'll be writin code tomorrow... Im going home!!!
Thank you everyone- i appreciate the help! But for the next 13 hours I dont care about JS or IE or CSS. Talk to you all in the morning!
I thought I could use all CSS, I really don't wanna use Javascript on the chance someone had it turned off. grrr. (<-- frustration...)
That's rare. According to the latest w3school's browser statistics (http://www.w3schools.com/browsers/browsers_stats.asp), 90% of users have Javascript turned on. With new internet security and better browsers, Javascript is no longer the big security risk.
Thank you everyone- i appreciate the help! But for the next 13 hours I dont care about JS or IE or CSS. Talk to you all in the morning!
Not even SEO? ASP? VBScript? PHP? C'mon, I know you wanna talk about it!! :D
this is so far a very hacked up example but, this is bascially what needs to happen with the addition of figuring out how to get the menus to stay.
<!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">
<head>
<title>Floated column example</title>
<meta http-equiv="content-type"
content="text/html; charset=utf-8" />
<script type="text/javascript">
window.onload = function() {
var links = document.getElementsByTagName('a');
var list = document.getElementsByTagName('menu');
for(x in links) {
links[x].onmouseover = function() {
var el = this.parentNode.nextSibling.nextSibling;
el.style.display='block';
}
links[x].onmouseout = function() {
var el = this.parentNode.nextSibling.nextSibling;
el.style.display = 'none';
}
}
}
</script>
<style type="text/css">
body {
padding: 0;
margin: 0;
}
#menu {
padding: 0;
margin: 0;
list-style-type: none;
border: thin solid black;
width: 150px;
}
#menu li {
padding: 0;
margin: 0;
border-bottom: thin solid black;
}
#menu ul {
border: thin solid black;
margin-top: -17px;
width: 200px;
padding: 0;
position: absolute;
left: 150px;
display: none;
list-style-type: none;
}
#menu ul li {
margin: 0;
padding: 0;
text-decoration: none;
}
#menu li a {
text-decoration: none;
}
</style>
</head>
<body>
<ul id="menu">
<li><a href="">35-200 kW</a></li>
<ul>
<li>WPE Packages</li>
<li>75 dBA Packages</li>
</ul>
<li><a href="">230-2000 kW</a></li>
<ul>
<li>WPH Packages</li>
<li>WPE Packages</li>
<li>l1 SAH Packages</li>
<li>L1 SAE packages</li>
<li>L2 SAH packages</li>
<li>L2 SAE Packages</li>
</ul>
<li><a href="">35-150 kW Nat Gas</a></li>
<ul>
<li>WPE NG Packages</li>
<li>75 dBA NG Packages</li>
</ul>
</ul>
</body>
</html>
JPnyc
08-28-2006, 10:23 PM
Javascript isn't a threat any longer. And as long as you hard code the links into the page there's no loss to SEO at all, nor are audio browsers excluded. That was a problem with the old style of JS menu, it's no problem at all with the method I just described. And if someone chooses to turn JS off in their browser, they should be prepared to live with the consequences.