• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[CSS] Submenu problem

Elite Diviner
Joined
May 26, 2009
Messages
428
Reaction score
16
well im just making another template and well i have a little problem with a paragraph and a submenu

i dont want to use javascript, well just cause i know with css alone its possible. so the problem is when i hover a link with a submenu, it shows correctly, and to me it looks great but when it opens the paragraph goes to the right side of it.

i dont know what to do


html:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">

<html>
	<head>
		<title>Layout 1</title>
		<link href="css/style.css" rel="stylesheet" type="text/css" />
	</head>
	
	<body>
		<div id="wrapper">
			<ul id="menu">
				<li><a href="#">home</a></li>
				<li class="hasSubMenu"><a href="#">account</a>
					<ul>
						<li><a href="#1">list item 1</a></li>
						<li><a href="#2">list item 2</a></li>
						<li><a href="#3">list item 3</a></li>
					</ul>
				</li>
				<li class="hasSubMenu"><a href="#">products</a>
					<ul>
						<li><a href="#1">product 1</a></li>
						<li><a href="#2">product 2</a></li>
						<li><a href="#3">product 3</a></li>
					</ul>
				</li>
				<li><a href="#">f.a.q</a></li>
				<li><a href="#">contact us</a></li>
			</ul>
			<p>i can't make this paragraph stop moving together with the submenu?! :[</p>
		</div>
	</body>
</html>

css:
Code:
html, body {
	margin: 0;
	height: 100%;
	padding: 0;
	width: 100%;
}
body {
	color: #000;
	background-color: #fff;
	font-family: Verdana;
	font-size: 11px;
}
#wrapper {
	clear: both;
	margin-right: auto;
	margin-left: auto;
	width: 800px;
}

#menu {
	background-color: #fff;
	background-image: url(../img/menu-background.gif);
	background-position: 0px 35px;
	background-repeat: repeat-x;
	clear: both;
	display: block;
	height: 36px;
	list-style-type: none;
	margin-top: 25px;
	overflow: visible;
	padding-left: 0;
	width: 800px;
}
#menu > li {
	float: left;
	overflow: visible;
}
#menu > li > a {
	border-bottom: 1px #ccc solid;
	color: #666;
	display: block;
	font-size: 12px;
	height: 28px;
	padding: 7px 30px 0px 30px;
	text-decoration: none;
}
#menu > li > ul {
	border: 1px #ccc solid;
	border-top-width: 0px;
	display: none;
	list-style-type: none;
	padding-left: 0;
}
#menu > li > ul > li {
	display: block;
	clear: both;
}
#menu > li > ul > li > a {
	border: 0;
	display: block;
	font-size: 11px;
	padding: 6px 0px;
	text-align: center;
	text-decoration: none;
	color: #666;
}
#menu > li:hover > a {
	color: #000;
}
#menu > li.hasSubMenu:hover > a {
	border-bottom-color: #fff;
}
#menu > li.hasSubMenu:hover > ul {
	display: block;
}
#menu > li:hover > ul > li:hover > a {
	color: #000;
}

thanks all
 
Joined
Sep 10, 2006
Messages
2,817
Reaction score
1,417
submenu needs to be absolutely positioned

kinda like this won't work in IE, but seeing you are using selectors that IE doesn't support at all, it won't bother you
 
Elite Diviner
Joined
May 26, 2009
Messages
428
Reaction score
16
ie doesn't support :hover, :first-child or the '>' ?? wow thats surprising

i tried absolute positioning but the submenu doesn't keep its size
like a text element instead of a block/div

edit: oh waits thats the solution.. silly me
 
Last edited:
Back
Top