...

View Full Version : dropdown menu pushing text down



chelvis
12-07-2006, 11:20 PM
I got this dropdown menu script. When I hover over the menu to drop it, what ever the text drops is pushing the rest of the page text either down or tothe side. Is there a way to drop the menu on top of the page text?

Here is the code:

<body>
<script type="text/javascript">
<!-- Start of Javascript do not touch this
function mOver(id) {
if (document.getElementById) {
document.getElementById(id).style.display="block";
} else if (document.all) {
document.all[id].style.display="block";
} else if (document.layers) {
document.layers[id].display="block";
} }

function mOut(id) {
if (document.getElementById) {
document.getElementById(id).style.display="none";
} else if (document.all) {
document.all[id].style.display="none";
} else if (document.layers) {
document.layers[id].display="none";
} }

function dropMenu(id) {
var SM = document.getElementById(id);
for (var i = 1; i<=10; i++) {
if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
}
if (SM) {SM.style.display='block';}
}

// End of Javascript -->
</script>

<style type="text/css">
<!--
ul, li {
list-style-type: none;
margin: 0;
padding: 0;

}
div.menu {
margin-top: 150px;
}

div.menu li {
float: left;
}

div.menu a {
margin: 0 1px;
width: 175px;
height: 20px;
display: block;
text-align: center;
border: 1px solid #88040A;
text-decoration: none;
font-family: Arial, sans-serif;
font-size: 12px;
color: #fff;
background: #88040A;
}

div.menu a:hover {
border: 1px solid #88040A;
}

div.menu a:active {
background: #88040A;
border: 1px solid #88040A;
color: #FFFF00;
}
#smenu1, #smenu2 {
margin-left: 0px;
padding: 0 0px;
float: left;
display: none;
font-size: 12px;
font-family: Arial, sans-serif;
width: 175px;

background: #FFFFFF;
color: #000;
}

#smenu1 a, #smenu2 a {
margin-left: 0px;
padding: 0 0px;
float: left;
font-size: 12px;
font-family: Arial, sans-serif;
width: 175px;
background: #FFFFFF;
color: #000;
}

#smenu1 a:hover, #smenu2 a:hover {
margin-left: 0px;
padding: 0 0px;
float: left;
background: #FEBFC2;
font-size: 12px;
font-family: Arial, sans-serif;
width: 175px;
color: #000;
}

#smenu1 a:active, #smenu2 a:active {
margin-left: 0px;
padding: 0 0px;
float: left;
font-size: 12px;
font-family: Arial, sans-serif;
width: 175px;
background: #FFFFFF;
color: #000;
}
-->
</style>

</head>

<body>

<div class="menu">
<ul><li><a onmouseover="mOver('smenu1');" onmouseout="mOut('smenu1');">Home</a> <ul id="smenu1" onmouseover="mOver('smenu1');" onmouseout="mOut('smenu1');">
<li><a href="http://www.google.com">About Us</a></li>
<li><a href="http://www.google.com">Our Philosophy</a></li>
<li><a href="http://www.google.com">Our Partners</a></li>
<li><a href="http://www.google.com">Why Choose Us</a></li>
<li><a href="http://www.google.com">Free Consultation</a></li>
</ul></li>

<li><a onmouseover="mOver('smenu2');" onmouseout="mOut('smenu2');">Project Management</a><ul id="smenu2" onmouseover="mOver('smenu2');" onmouseout="mOut('smenu2');">
<li><a href="http://www.google.com">IPM</a></li>
<li><a href="http://www.google.com">Product Optimization</a></li>
<li><a href="http://www.google.com">Maintenance Optimization</a></li>
</ul></li>

</ul>
</div>

</body>
</html>

1212jtraceur
12-08-2006, 07:23 PM
The basic problem was that the menu was still part of the document flow. Here is some code which works in Firefox 2:



<html>
<body>
<script type="text/javascript">
<!-- Start of Javascript do not touch this
function mOver(id) {
getElementById(id).style.display = 'block';
}

function mOut(id) {
getElementById(id).style.display = 'none';
}

function getElementById(id) {
var element;
if (document.getElementById) element = document.getElementById(id);
else if (document.all) element = document.all[id];
else if (document.layers) element = document.layers[id];
return element;
}
// End of Javascript -->
</script>

<style type="text/css">
ul, li {
list-style-type: none;
margin: 0;
padding: 0;
float: left;
}

div.menu {
margin-top: 150px;
}

div.menu > ul
{
position: relative;
}

div.menu > ul > li {
margin: 0 1px;
}

div.menu a {
width: 175px;
height: 20px;
display: block;
text-align: center;
border: 1px solid #88040A;
text-decoration: none;
font-family: Arial, sans-serif;
font-size: 12px;
color: #fff;
background: #88040A;
}

div.menu a:hover {
border: 1px solid #88040A;
}

div.menu a:active {
background: #88040A;
border: 1px solid #88040A;
color: #FFFF00;
}

#smenu1, #smenu2 {
position: absolute;
padding: 0 0px;
display: none;
font-size: 12px;
font-family: Arial, sans-serif;
width: 175px;
background: #FFFFFF;
color: #000;
}

#smenu1 a, #smenu2 a {
margin-left: 0px;
padding: 0 0px;
font-size: 12px;
font-family: Arial, sans-serif;
width: 175px;
background: #FFFFFF;
color: #000;
}

#smenu1 a:hover, #smenu2 a:hover {
background: #FEBFC2;
}

/*
#smenu1 a:active, #smenu2 a:active {
margin-left: 0px;
padding: 0 0px;
font-size: 12px;
font-family: Arial, sans-serif;
width: 175px;
background: #FFFFFF;
color: #000;
}
*/
</style>

</head>

<body>

<div class="menu">
<ul><li><a onmouseover="mOver('smenu1');" onmouseout="mOut('smenu1');">Home</a> <ul id="smenu1" onmouseover="mOver('smenu1');" onmouseout="mOut('smenu1');">
<li><a href="http://www.google.com">About Us</a></li>
<li><a href="http://www.google.com">Our Philosophy</a></li>
<li><a href="http://www.google.com">Our Partners</a></li>
<li><a href="http://www.google.com">Why Choose Us</a></li>
<li><a href="http://www.google.com">Free Consultation</a></li>
</ul></li>

<li><a onmouseover="mOver('smenu2');" onmouseout="mOut('smenu2');">Project Management</a><ul id="smenu2" onmouseover="mOver('smenu2');" onmouseout="mOut('smenu2');">
<li><a href="http://www.google.com">IPM</a></li>
<li><a href="http://www.google.com">Product Optimization</a></li>
<li><a href="http://www.google.com">Maintenance Optimization</a></li>
</ul></li>

</ul>
</div><br />
<div style="clear: left;">
asldfkjalsdjkfa;sldfjalsdkfj
</div>
</body>
</html>


As you will see, I made a few other changes.

1212jtraceur

chelvis
12-08-2006, 07:34 PM
Thanks so much 1212jtraceur. Its good.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum