Click here to Skip to main content
15,889,992 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My problem is that I have a nav section in my page and I want to only show the parent items, on hover the child items need to be displayed. That works but it then moves the remainder of the page down. This is not what I want. Can I make it, using CSS only, to show the child content over what follows?

My page is thus:

HTML
<!DOCTYPE html>
<html lang="en">
	<title>Test Menu</title>
	<meta charset="utf-8">
	<style>
		.drop-menu {
			display: inline-block;
			min-width: 100px;
			text-align: left;
			padding: 10px 10px;
			cursor: pointer;
			border: 1px solid #f6f0e4;
		}

		.drop-menu:hover .sub-menu {
			display: block;
		}

		.sub-menu {
			display: none;
			width: 200px;
			padding: 10px 10px;
			margin-left: -11px;
			margin-top: 10px;
			border: 1px solid #fff;
		}

		.sub-menu li {
			list-style-type: none;
			display: block;
			border-bottom: 1px dotted #eaeaea;
		}

		.sub-menu li:hover {
			border-bottom: 1px dotted #bababa;
		}
	</style>

	<body>

		<header>
			<h1>Test Menu</h1>
		</header>

		<nav>
			<ul>
				<li class="drop-menu">
					<div>Parent</div>
					<ul class="sub-menu">
						<li>Child 2</li>
						<li>Child 1</li>
					</ul>
				</li>
			</ul>
		</nav>
		<section>
			<h2>Content</h2>

			<article>
				<h3>Article</h3>
				<h6>by Author</h6>
				<p>
					Lorem ipsum dolor sit amet, consectetur adipiscing elit.
				</p>
			</article>
		</section>
		<footer>
			<p>Footer</p>
		</footer>
	</body>
</html>


For the .drop-menu:hover, I have tried different display styles, but it appears I'm missing something or other.
Posted
Updated 11-Feb-15 1:11am
v2

1 solution

Try using position, that may help.
CSS
/*add these to the css style*/
.drop-menu {
    position:relative;
}
.sub-menu {
    position:absolute;
    background-color:white;
}

Here is jsfiddle of your example with additions: http://jsfiddle.net/mL28mohg/[^]
 
Share this answer
 
v3
Comments
Nagy Vilmos 11-Feb-15 8:04am    
Looks likely, thanks. The css file shouldn't have been there, it contains all the stuff I don't want to move.
jaket-cp 11-Feb-15 8:08am    
No problem, glad to help :)
I see you storyboard.css has been removed from question, will change solution accordingly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900