Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-07-2006, 10:20 PM   PM User | #1
chelvis
Regular Coder

 
Join Date: Jun 2002
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
chelvis is an unknown quantity at this point
dropdown menu pushing text down

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:
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>
chelvis is offline   Reply With Quote
Old 12-08-2006, 06:23 PM   PM User | #2
1212jtraceur
Regular Coder

 
Join Date: Oct 2006
Posts: 206
Thanks: 1
Thanked 0 Times in 0 Posts
1212jtraceur is an unknown quantity at this point
The basic problem was that the menu was still part of the document flow. Here is some code which works in Firefox 2:

Code:
<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
1212jtraceur is offline   Reply With Quote
Old 12-08-2006, 06:34 PM   PM User | #3
chelvis
Regular Coder

 
Join Date: Jun 2002
Posts: 406
Thanks: 0
Thanked 0 Times in 0 Posts
chelvis is an unknown quantity at this point
Thanks so much 1212jtraceur. Its good.
chelvis is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:33 AM.


Advertisement
Log in to turn off these ads.