5

This is my first ever post to Stack Overflow and I'm not familiar with forum regulations with posting. So please let me know anything that I have done wrong. I have researched this issue in the forums and nothing I've come across gives me a clear answer.

I am trying to create a dropdown menu from the "News" element, but I never get any visible result when running the code. I tried to change the .dropdown-content's display value to block to see if it would make the list visible, but nothing showed. What am I missing?

body{
	background-image: url("images/seamless-panda-bear-pattern.jpg");
	font-size: 100%;
	width: 80%;
	margin: auto;
	font-family: Palatino,"Palatino", Arial;

}

#top{
	background-color: black;
	color: white;
	padding-left: 10px;
	border: 2px solid white;
	font-family: Copperplate,"Copperplate Gothic Light",fantasy;
	opacity: 0.85;
	padding-left: 25px;
}

#menu{
	list-style-type: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
	background-color: #333;
	position: fixed;
	width: 80%;
}
li{
	float: left;
}

#login{
	float: right;
	padding-right: 20px;
}

li a{
	display: block;
	color: white;
	text-decoration: none;
	text-align: center;
	padding: 14px 16px;

}
li a:hover{
	background-color: white;
	color: black;
}

li.dropdown{
	display: inline-block;
}

.dropdown-content{
	display: none;
	position: absolute;
	background-color: #f9f9f9;
	min-width: 160px;
	box-shadow: 0px 8px 16px 0px rgba(0,0,0,0,2);
	padding: 12px 16px;
	z-index: 1;
}

.dropdown-content a{
	display: block;
	text-decoration: none;
	padding: 12px 16px;
	color: black;
}

.dropdown:hover .dropdown-content{
	display: block;
}


#bio{

}

#bottom{

}
<div id="nav">
<ul style="list-style-type: none" id="menu">
	<li><a href="home.html">Home</a></li>
	<li class="dropdown"><a class="dropbtn" href="#">News</a>
		<div class="dropdown-content">
			<a href="#">Games</a>
			<a href="#">Web Design</a>
			<a href="#">Travel</a>
		</div>
	</li>
	<!-- create a link to a part of the same page for contact info -->
	<li><a href="#bottom">Contact info</a></li>
	<li id="login"><a href="login.html">Log In</a></li>
</ul>
</div>

8
  • what you want to do? Commented Apr 22, 2016 at 3:06
  • 3
    When I run the code snippet it works just as you want it to, is there something I'm missing? P.S. your post is GREAT! Commented Apr 22, 2016 at 3:07
  • 1
    You actually did what most people dont and provided enough code. YAY!!! It works on my browser, CHROME by the way as well. Commented Apr 22, 2016 at 3:13
  • 1
    Seems to be working in Safari Commented Apr 22, 2016 at 3:16
  • 1
    I have updated the css code to show everything I have (I know I shouldn't normally do this, but seeing as I can't pinpoint the issue...). I have tried on Chrome and Internet Explorer. Commented Apr 22, 2016 at 3:20

1 Answer 1

4

To solve your position fixed issue. You can add position: fixed; to #nav and change the width on #menu from width: 80%; to width: 100%;

Here's a JS Fiddle.

Hope that helped!

Sign up to request clarification or add additional context in comments.

9 Comments

Only issue I find is the Log In element no longer floats to the right of the screen. It sits next to Contact Info. Is there a way to fix this?
It was due to the padding for #login, if you change it from padding-right: 20px; to padding-left: 20px; that should fix your issue! See updated JS Fiddle!
Actually, just remove that padding altogether! (See updated JS Fiddle)
Hmm, what I meant was I wanted the navigation bar's width to match the 'body' selector's width and have the 'Log In' element to sit at the right end. I'm noticing with increased padding-left, I could get the results I want. However, wouldn't a percentage of the screen fit better for the webpage to look equal to all screen resolutions?
Whether this is better or not is quite subjective, but I had fun playing with the CSS a bit and got this fiddle
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.