Why wont my nav display dropdown-links vertically? - html

I have been sitting for 4 hours now trying to make my nav display dropdown-links vetically but it continues to show them horizontally instead. I can´t figure out why this is happening or how to fix it.
I would appreciate it very much if some kind soul could tell me what I am doing wrong. I have a sneaking suspecion this is caused due to my settings for the nav (it changes size at a certain width) but I am not sure...
I have ripped my nav from my website and thrown everything into codepen, but even after several attempts to figure out where the problem starts - nothing! It displays "link1" right below and then just adds "link2" and "link3" to the right of it, instead of under
Please help?
Codepen: https://codepen.io/Pinchofginger/pen/BJJQgZ
If there are any oddities in the CSS it´s because I have a dropdown menu for mobile that display when you press an icon... it is not currently working either, but that a question for another time.
My HTML
<header class="mainheader">
<section id="baggrund">
<div id="mainlogo">
Sønderborg
<p> og omegns</p> Kattelaug<br />
<img class="vector" src="billeder/udklip.png" alt="Kattesilhuet"></div>
<nav>
<input type="checkbox" id="menu-checkbox" role="button" />
<label for="menu-checkbox" id="menu-button">
<span class="bar"></span>
<span class="bar"></span>
<span class="bar"></span>
</label>
<div id="nav_wrap">
<ul id="menu">
<li>Forside</li>
<li>Adopter en kat</li>
<li>Tilløber katte</li>
<li> Kattens pleje</li>
<li class="dropdown">
<a href="javascript:void(0)" class="dropbtn">
Kontakt</a><div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
</ul></div>
</nav>
</section>
</header>
MY CSS
/* small nav */
#media screen and (max-width: 61em) {
#menu li {
width: 20%;
}
#menu li a {
font-size: 0.9em;
width:100%;
color:red;}
#menu ul {width:100%;}
/*sidebar*/
body#index .sidemenu .sidebar1 {padding: 0 0 0 0;}
body#index #Mega {width: 96%; height:80px;}
body#index .sidemenu .sidebar1 h3 {font-size: 0.9em;}
}
/* stor nav*/
#media screen and (min-width: 61em) {
#menu li {
width: 20%;
}
#menu li a {
font-size: 1.2em;
width:100%;
color: #505050;
}} /*slut, stor*/
#menu li {
display: inline-block;
background: none;
padding: 5px 5px 5px 5px;
}
#menu li a {
text-transform: uppercase;
transition: all .5s ease;
text-decoration: none;
text-align: center;
line-height: 55px;
display: inline-block;}
.sidemenu .pleje {font-size: 0.9em; display:inline-block }
.sidemenu .pleje h3 {color: orange;}
#mainlogo {
display: block;
}
.mainheader {
width: 100%;
}
#bannerkat { display: none;}
#menu-button { display: none;}
#menu {
display: block;
border-radius: 0;
text-align: center;
position: relative;
}
/* Navigations menuen (links osv) */
#nav_wrap {
background: #f9f4ea;
width: 100%;
white-space: nowrap;
float: left;
height: 60px;
position: relative;
margin-top: 144px;
bottom: 0;
/* overflox:hidden; */
z-index: 9999;
opacity: .9;
box-shadow: 0px 1px 4px beige;
padding: 0;
}
li a, .dropbtn {
display: inline-block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
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);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {background-color: #f1f1f1}
.dropdown:hover .dropdown-content {
display: block;
}
/* højde for billed-sektion*/
.mainheader section {
min-height: 204px;
}
#mainlogo {
font-size: 37px;
color: white;
border: 7px solid white;
display: inline-block;
padding: 10px;
position: absolute;
height: 123px;
/* hvid boks*/
line-height: 25px;
top: 202px;
margin-top: -180px;
left: 50%;
width: 600px;
text-align: center;
margin-left: -300px;
text-shadow: 1px 2px 1px #000;
box-shadow: 1px 2px 1px #000;
}
/* og omegns */
#mainlogo p {
font-size: 20px;
padding: 5px;
}
.vector {
width: 60px;
margin-left: -450px;
margin-top: -36px;
}
.mainheader {
margin-top: 10px;
}

Change line 42 in css: "menu li a" to Display: block instead of Display: inline-block:
#menu li a {
text-transform: uppercase;
transition: all .5s ease;
text-decoration: none;
text-align: center;
line-height: 55px;
display: block;
}

Related

White space around bordered elements in navigation?

I'm asking on here because I'm thoroughly fed up of trying to resolve this myself and getting absolutely nowhere. The only solution I've found so far is to remove the border itself but it's probably best to explain the problem first...
So I'm building a navigation bar for a website and I've done absolutely dozens of these, re-used the same code across multiple projects because... it's a navigation bar! It's incredibly simple, the only difference is that I have an extra nested navigation sub-category. However this occurs regardless whether or not that sub-category exists. When I've built it, it looked absolutely fine but I noticed that there was a small white gap between the elements inside the menu element between them and the border. This gap is incredibly inconsistent however - in the small JS fiddle screen on my old monitor it doesn't appear at all but move it onto my laptop widescreen display and the gaps appear.
I've checked all of my CSS and code, nothing is amiss compared to my other websites and according to Chrome's Computed tab, there isn't actually a gap there at all. There's nothing but the border?! How does it appear then when the Computed tab tells me it's not there? Am I losing my mind?
Regardless, I've posted a JSFiddle to try and get some input on this. I'm using SCSS compiled by Scout App and it appears to only happen on Chrome as far as I can see. Anybody got any ideas?
*,
body {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: auto;
background-color: #D0E9FD;
}
body {
color: #1D1E2C;
font-size: 18px;
font-family: "Kodchasan", sans-serif;
}
a {
text-decoration: underline;
color: #713031;
}
img {
max-width: 100%;
}
h1,
h2,
h3,
h4,
h5 {
color: #2AA6A6;
}
h1 {
font-size: 32px;
margin-top: 10px;
}
h2 {
font-size: 28px;
}
hr {
border: 4px solid #2AA6A6;
}
input,
textarea,
select {
border: 2px solid #2AA6A6;
padding: 10px;
color: #991B1D;
}
input:focus,
textarea:focus,
select:focus {
outline: none;
border: 2px solid #991B1D;
}
input:disabled,
textarea:disabled,
select:disabled {
background-color: #d9f6f6;
border-color: #d9f6f6;
text-align: center;
-webkit-appearance: none;
-moz-appearance: none;
font-family: "Kodchasan", sans-serif;
font-size: 18px;
opacity: 1;
}
input:disabled:-ms-expand,
textarea:disabled:-ms-expand,
select:disabled:-ms-expand {
display: none;
}
form {
border: 2px solid #2AA6A6;
padding: 10px;
}
form input,
form textarea,
form label {
margin-bottom: 10px;
width: 49%;
display: inline-block;
}
form input,
form textarea {
border: 2px solid #2AA6A6;
padding: 10px;
color: #991B1D;
}
form input:focus,
form textarea:focus {
outline: none;
border: 2px solid #991B1D;
}
form input[type="submit"] {
width: 100%;
margin: 0;
}
form button {
background-color: #2AA6A6;
color: #FFFFFF;
border: 2px solid #2AA6A6;
}
form a {
width: 90%;
display: block;
text-align: center;
}
form>p {
width: 50%;
display: block;
margin: 0 auto;
text-align: center;
}
#navigation {
padding: 2px 0;
background-color: #2AA6A6;
}
#navigation ul {
list-style-type: none;
margin: 0;
padding: 0;
}
#navigation li a {
display: block;
color: #FFFFFF;
font-weight: 700;
font-size: 24px;
text-decoration: none;
width: 100%;
padding: 15px;
}
#navigation li.parent-cat ul {
background-color: #FFFFFF;
margin: 10px 0;
margin-left: 20px;
}
#navigation li.parent-cat ul a {
color: #713031;
}
#navigation li ul {
background-color: #FFFFFF;
margin: 10px 0;
margin-left: 20px;
}
#navigation li ul a {
color: #713031;
}
#navigation #nav {
display: none;
border-top: 5px solid #FFFFFF;
}
#navigation #menu {
display: block;
text-align: center;
background-color: #2AA6A6;
cursor: pointer;
padding: 10px 0;
font-size: 24px;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
color: #FFFFFF;
}
#navigation #menu.open {
background-color: #713031;
color: #FFFFFF;
}
#navigation li {
display: inline-block;
}
#navigation li a {
font-size: 18px;
padding: 20px 30px;
}
#navigation li a:hover {
background-color: #FFFFFF;
color: #2AA6A6;
}
#navigation li.parent-cat {
position: relative;
}
#navigation li.parent-cat:hover a {
background-color: #FFFFFF;
color: #2AA6A6;
}
#navigation li.parent-cat:hover ul {
display: block;
position: absolute;
width: 100%;
margin-top: 0;
z-index: 99;
margin-left: 0;
border: 2px solid #713031;
margin-bottom: 0;
}
#navigation li.parent-cat:hover ul li {
width: 100%;
}
#navigation li.parent-cat:hover ul a:hover {
background-color: #713031;
color: #FFFFFF;
}
#navigation li.parent-cat:hover .parent-cat:hover ul {
display: block;
margin-left: 100%;
margin-top: -32%;
}
#navigation li.parent-cat:hover .parent-cat ul {
display: none;
}
#navigation li.parent-cat ul {
display: none;
}
#navigation #menu {
display: none;
}
#navigation #nav {
display: block;
border: none;
}
/* EOS */
<div id="navigation">
<ul id="nav">
<li id="one"><span>Home</span></li>
<li id="two" class="parent-cat"><span>Our Workshop</span> <i class="fas fa-level-down-alt"></i>
<ul>
<li id="three"><span>Our Solutions</span></li>
<li id="four" class="parent-cat">
<span>Our Products</span> <i class="fas fa-level-down-alt"></i>
<ul>
<li id="five"><span>Lighting Components</span></li>
<li id="six"><span>Motorcycle Parts</span></li>
<li id="seven"><span>RC Buggy Parts</span></li>
</ul>
</li>
</ul>
</li>
<li id="five"><span>Careers</span></li>
<li id="six"><span>Latest News</span></li>
<li id="seven"><span>Contact Us</span></li>
</ul>
<a id="menu"><i class="fas fa-bars"></i></a>
</div>

how to add drop-down menu?

I have horizontal menu bar, and I trying to add sub menu for one of item, but I am not able to add it, Its appending to my main menu, please someone help me to where i missing
thanks
HTML
<div id="talltabs-maroon">
<ul>
<li class="first">Home <span>Page</span></li>
<li class="active"><span>About us</span></li>
<li class="dropdown"><a class="dropbtn" href="#"> <span> Report </span></a>
<ul class="dropdown-content" style="left:0">
<li>
<a href="">
<p>Valve Report</p>
</a>
</li>
<li>
<a href="">
<p>Cylinder Report</p>
</a>
</li>
</ul>
</li>
<li class="last">Contact <span>Us</span></li>
</ul>
</div>
CSS for Main menu
#talltabs-maroon {
clear: left;
float: left;
padding: 0;
border-top: 3px solid #CD324F;
width: 100%;
overflow: hidden;
font-family: Georgia, serif;
height: 90px;
position: inherit;
}
#talltabs-maroon ul {
float: left;
margin: 0;
padding: 0;
list-style: none;
position: relative;
left: 50%;
text-align: center;
}
#talltabs-maroon ul li {
display: block;
float: left;
list-style: none;
margin: 0;
padding: 0;
position: relative;
right: 50%;
}
#talltabs-maroon ul li a {
display: block;
float: left;
margin: 0 3px 0 0;
padding: 0px 10px 6px 10px;
background: #CD324F;
text-decoration: none;
color: #fff;
}
#talltabs-maroon ul li a p:hover {
color: aqua;
}
#talltabs-maroon ul li a:hover {
padding: 20px 10px 6px 10px;
color: black
}
#talltabs-maroon ul li.active a,
#talltabs-maroon ul li.active a:hover {
padding: 25px 10px 6px 10px;
border-width: 5px;
border-color: aqua;
color: aqua;
}
CSS for drop down menu i tried.
.dropbtn {
list-style-type: none;
color: white;
padding: 14px;
font-size: 14px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: block;
}
.dropdown-content {
list-style-type: none;
display: none;
position: absolute;
right: 0;
/*background-color: black;*/
background-image: url('../../Images/black-olive.jpg'); /*dropdowm popup*/
min-width: 160px;
box-shadow: 0px 8px 16px 5px rgba(0,0,0,0.2);
z-index: 1;
padding-right: 2px;
margin-right: 2px;
}
.dropdown-content a {
color: white;
padding: 10px 14px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
/*background-color: gray;*/
color: black;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
/*background-color: #3e8e41;*/
}
pleas help me.
thanks
tink.
Here is my answer for same example, I changed complete css,
body {
font-family: 'Lucida Grande', 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
ul {
text-align: left;
display: inline;
margin: 0;
padding: 15px 4px 17px 0;
list-style: none;
}
ul li {
display: inline-block;
margin-right: -1px;
position: relative;
padding: 15px 20px;
background: #CD324F;
cursor: pointer;
color: black;
height: 40px;
width: auto;
text-align:center;
}
ul li a{
color:black;
}
ul li:hover {
background: #CD324F;
color: #fff;
height: 45px;
}
ul li a:hover {
color: #fff;
}
ul li ul {
padding: 0;
position: absolute;
top: 68px;
left: 0;
width: 160px;
-webkit-box-shadow: none;
-moz-box-shadow: none;
box-shadow: none;
display: none;
opacity: 0;
visibility: hidden;
}
ul li ul li {
background: #ce5068;
display: block;
color: #CD324F;
height: 35px;
}
ul li ul li:hover {
background: #CD324F;
height: 35px;
}
ul li:hover ul {
display: block;
opacity: 1;
visibility: visible;
}
<div style="height: 77px; width:100%; margin-top:65px;text-align:center; border-top:solid; border-top-color:#CD324F">
<ul><li>Home</li>
<li>About</li>
<li>
Portfolio
<ul>
<li>Web Design</li>
<li>Web Development</li>
<li>Illustrations</li>
</ul>
</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</div>
Result: on hover portfolio, drop down will appear
Working example on JSFiddle.
I really recommend to look at bootstrap's drop down menu. It is easy to use and most things are already done for you. good luck
Here is the link: https://www.w3schools.com/bootstrap/bootstrap_dropdowns.asp
your code is bit confusing , i have created a simple demo for you how to do it.
here is my HTML code
body {
background: #212121;
font-size:22px;
line-height: 32px;
color: #ffffff;
word-wrap:break-word !important;
font-family: 'Open Sans', sans-serif;
}
h1 {
font-size: 60px;
text-align: center;
color: #FFF;
}
h3 {
font-size: 30px;
text-align: center;
color: #FFF;
}
h3 a {
color: #FFF;
}
a {
color: #FFF;
}
h1 {
margin-top: 100px;
text-align:center;
font-size:60px;
font-family: 'Bree Serif', 'serif';
}
#container {
margin: 0 auto;
}
p {
text-align: center;
}
nav {
margin: 50px 0;
background-color: #E64A19;
}
nav ul {
padding: 0;
margin: 0;
list-style: none;
position: relative;
}
nav ul li {
display:inline-block;
background-color: #E64A19;
}
nav a {
display:block;
padding:0 10px;
color:#FFF;
font-size:20px;
line-height: 60px;
text-decoration:none;
}
nav a:hover {
background-color: #000000;
}
/* Hide Dropdowns by Default */
nav ul ul {
display: none;
position: absolute;
top: 60px; /* the height of the main nav */
}
/* Display Dropdowns on Hover */
nav ul li:hover > ul {
display:inherit;
}
/* Fisrt Tier Dropdown */
nav ul ul li {
width:170px;
float:none;
display:list-item;
position: relative;
}
<div id="container">
<nav>
<ul>
<li>Home</li>
<li>WordPress
<!-- First Tier Drop Down -->
<ul>
<li>Themes</li>
<li>Plugins</li>
<li>Tutorials</li>
</ul>
</li>
<li>Web Design
<!-- First Tier Drop Down -->
<ul>
<li>Resources</li>
<li>Links</li>
<li>Tutorials
</ul>
</nav>
</div>

How to make a responsive navbar without bootstrap?

How to make a responsive make the navbar collapse into a hamburger menu bar after a certain width without bootstrap, but from scratch?
Here is the fiddlehttps://jsfiddle.net/6951Lscu/
#myNavbar{
position: fixed;
width: 100%;
background: white;
border-style: solid;
border-width: 0 0 1px 0;
border-color: #E8E8E8;
text-decoration: none;
}
ul{
list-style: none;
}
.medium{
font-family: "Roboto", sans-serif;
font-weight: 500;
}
.right-nav{
padding: 8px 15px;
float: right;
}
div.container{
font-family: Raleway;
margin: 0 auto;
padding: 6px 3em;
text-align: center;
}
div.container a
{
color: #000;
text-decoration: none;
margin: 0px 20px;
padding: 5px 5px;
position: relative;
}
<div id="myNavbar">
<div class="container">
<ul>
<li style="float:left"><img class="navlogo" src="svg/navlogo.svg" alt=""></li>
<li class="right-nav"><span class="medium">KONTAKT</span></li>
<li class="right-nav"><span class="medium">PRIS</span></li>
<li class="right-nav"><span class="medium">GARANTIER</span></li>
<li class="right-nav"><span class="medium">OM MEG</span></li>
</ul>
</div>
</div>
body {
font-family: sans-serif;
}
* {
box-sizing: border-box;
}
header {
background: #181818;
height: 200px;
padding-top: 40px;
}
.inner {
max-width: 1000px;
margin: 0 auto;
padding: 0px 20px;
position: relative;
}
.logo {
text-decoration: none;
color: #777;
font-weight: 800;
font-size: 30px;
line-height: 40px;
}
h1 {
text-align: center;
width: 100%;
margin-top: 120px;
color: #eee;
font-weight: 800;
font-size: 40px;
}
nav > ul {
float: right;
}
nav > ul > li {
text-align: center;
line-height: 40px;
margin-left: 70px;
}
nav > ul li ul li {
width: 100%;
text-align: left;
}
nav ul li:hover {
cursor: pointer;
position: relative;
}
nav ul li:hover > ul {
display: block;
}
nav ul li:hover > a {
color: #777;
}
nav > ul > li > a {
cursor: pointer;
display: block;
outline: none;
width: 100%;
text-decoration: none;
}
nav > ul > li {
float: left;
}
nav a {
color: white;
}
nav > ul li ul {
display: none;
position: absolute;
left: 0;
top: 100%;
width: 100%;
z-index: 2000;
}
nav > ul li ul li > a {
text-decoration: none;
}
[type="checkbox"],
label {
display: none;
}
#media screen and (max-width: 768px) {
nav ul {
display: none;
}
label {
display: block;
background: #222;
width: 40px;
height: 40px;
cursor: pointer;
position: absolute;
right: 20px;
top: 0px;
}
label:after {
content: '';
display: block;
width: 30px;
height: 5px;
background: #777;
margin: 7px 5px;
box-shadow: 0px 10px 0px #777, 0px 20px 0px #777
}
[type="checkbox"]:checked ~ ul {
display: block;
z-index: 9999;
position: absolute;
right: 20px;
left: 20px;
}
nav a {
color: #777;
}
nav ul li {
display: block;
float: none;
width: 100%;
text-align: left;
background: #222;
text-indent: 20px;
}
nav > ul > li {
margin-left: 0px;
}
nav > ul li ul li {
display: block;
float: none;
}
nav > ul li ul {
display: block;
position: relative;
width: 100%;
z-index: 9999;
float: none;
}
h1 {
font-size: 26px;
}
}
<header>
<div class="inner">
<nav>
Logo
<input type="checkbox" id="nav" /><label for="nav"></label>
<ul>
<li>Home</li>
<li>
Work
<ul>
<li>Web</li>
<li>Print</li>
</ul>
</li>
<li>Service</li>
<li>Blog</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
You should refer to Hanlin Chong's CodePen which utilizes #media queries to handle responsive behavior based on max-width of the screen.
Or start with the basic W3Schools Responsive Navbar tutorial: https://www.w3schools.com/howto/howto_js_topnav_responsive.asp
You should read about #media rule in CSS3. Here is url Click. There is no other way to do that without bootstrap. Good luck!

Why isn't my nav class expanding to 100% of the width?

So I'm trying to understand why when I specify the width for my .thenav class it is not expanding to the entire width of the page.
I UNDERSTAND that it is taking the characteristics of the .container class, but I don't understand why and what is the solution seeing that i specified the width? PLEASE HELP!
Here is my picture of what's happening (I attached an image of what's happening because the jsfiddle makes the div appear at 100% and it's not):
http://imgur.com/a/zsBqC
Here is my jsfiddle:
https://jsfiddle.net/CheckLife/yox7Ln1b/3/
Here's the code for reference:
HTML:
<div class="header">
<div class="container">
<h1 id="box" onload="changed()"><image src="nbaone.png" width="40px" height="55px" class="nba">NBA Legends</h1>
<div class="thenav" onload="changed()">
<ul>
<li><a href="http://www.nba.com"/>Home</a></li>
<li onclick="changeP()">About</li>
<li>Players
<ul>
<li onmouseover="slow()"></li>
<li><a href="#kobesec"/>Kobe</a></li>
<li><a href="#"/>Kevin Durant</a></li>
<li><a href="#"/>The Goat</a></li>
</ul>
</li>
<li onclick="slow()">News</li>
</ul>
</div>
</div>
</div>
CSS:
* {
margin: 0;
padding: 0;
list-style-type: none;
text-decoration: none;
}
header, nav, section, aside, footer, article {
display: block;
}
body {
background-image: url(backwood.png);
width: 100%;
margin: auto;
}
.container {
margin: 0px auto;
background-size: cover;
width: 1300px;
height: 100%;
}
.header {
background:linear-gradient(to right, #5092f4, #f29641);
margin-top: 0px;
width: 100%;
}
.header h1{
text-align: center;
width: 100%;
padding-bottom: 15px;
font-family: Arial, Helvetica, sans-serif;
color: #f4ca1f;
}
.tmacw {
display:inline;
position: relative;
padding: 0px;
top: 5px;
}
.nba {
margin-right: 10px;
}
.thenav {
background-color: #7886a3;
width: 100%;
height: 85px;
position: relative;
z-index: 1;
}
/* Style for the Nav Bar */
.thenav ul {
padding: 0;
margin: 0;
}
.thenav ul li {
float: left;
width: 90px;
text-align: center;
border-right: 1px groove #141e38;
position: relative;
}
.thenav ul li a {
display: block;
color: white;
font-weight: bold;
padding: 33px 10px;
}
.thenav ul li a:hover {
background-color: #47e586;
transition: all 0.90s;
}
/*Dropdown Nav */
.thenav li ul li{
background-color: #7886a3;
border: 2px groove grey;
border-radius: 4px;
position: relative;
}
.thenav li ul li a {
padding: 8px;
text-align:left;
}
.thenav li ul li:nth-child(1) a:hover {
background-color: #F47575;
}
.thenav li ul li:nth-child(2) a:hover {
background-color: #f7d759 ;
}
.thenav li ul li a:hover{
background-color: red;
}
.thenav ul li ul {
display: none;
}
.thenav li:hover ul{
position:absolute;
}
.thenav li:hover ul{
display: block;
}
/* End of Dropdown */
.userlogin {
font-size: 12px;
top:2px;
color: white;
}
input[type=text], input[type=password] {
font-weight: bold;
margin: 0;
font-size: 8px;
height: 10px;
padding: 3px 5px 3px 5px;
color: 162354;
}
/* Stats Button */
.stat input[type=button] {
background-color: #6cd171;
color: blue;
border-radius: 6px;
font-weight: bold;
border: none;
float: left;
margin-top: 20px;
margin-left: 20px;
padding: 2px 2px;
font-family: Verdana, Geneva, sans-serif;
}
.log[type=button] {
background-color: white;
color: #008cff;
border-radius: 4px;
font-weight: bold;
border: none;
padding: 1px 2px 2px 2px;
position: relative;
left: 5px;
top: 3px;
}
A child div that does not have absolute positioning and has a width of 100% (unnecessary if it's display is the default of block) will be set to it's containers width. Your div.container has a width setting of 1300px and it is the parent element of div.thenav, therefore div.thenav's width will also be 1300px.
You can either remove width on the container:
.container {
margin: 0px auto;
background-size: cover;
/*width: 1300px; remove this */
height: 100%;
}
or:
Move div.thenav outside of div.container as in this code:
(https://jsfiddle.net/nod19rze/)
<div class="header">
<h1 id="box" onload="changed()"><image src="nbaone.png" width="40px" height="55px" class="nba">NBA Legends</h1>
<div class="thenav" onload="changed()">
<!-- contents of thenav here -->
</div>
<div class="container">
</div>
</div>
Either the container should be the first wrapper and then comes the header, which could solve the issue. I am not sure if this is what u need. Please check this fiddle:
https://jsfiddle.net/estgLn1q/1/
<div class="container">
<div class="header">
</div>
</div>
Or if you want to maintain the same html structure, then remove width:1300px from '.container' which will cause the container to take the same width as of its parent.
I would just move #box and .thenav out of .container and start that class after those elements.
* {
margin: 0;
padding: 0;
list-style-type: none;
text-decoration: none;
}
header,
nav,
section,
aside,
footer,
article {
display: block;
}
body {
background-image: url(backwood.png);
width: 100%;
margin: auto;
}
.container {
margin: 0px auto;
background-size: cover;
width: 1300px;
height: 100%;
}
.header {
background: linear-gradient(to right, #5092f4, #f29641);
margin-top: 0px;
width: 100%;
}
.header h1 {
text-align: center;
width: 100%;
padding-bottom: 15px;
font-family: Arial, Helvetica, sans-serif;
color: #f4ca1f;
}
.tmacw {
display: inline;
position: relative;
padding: 0px;
top: 5px;
}
.nba {
margin-right: 10px;
}
.thenav {
background-color: #7886a3;
width: 100%;
height: 85px;
position: relative;
z-index: 1;
}
/* Style for the Nav Bar */
.thenav ul {
padding: 0;
margin: 0;
}
.thenav ul li {
float: left;
width: 90px;
text-align: center;
border-right: 1px groove #141e38;
position: relative;
}
.thenav ul li a {
display: block;
color: white;
font-weight: bold;
padding: 33px 10px;
}
.thenav ul li a:hover {
background-color: #47e586;
transition: all 0.90s;
}
/*Dropdown Nav */
.thenav li ul li {
background-color: #7886a3;
border: 2px groove grey;
border-radius: 4px;
position: relative;
}
.thenav li ul li a {
padding: 8px;
text-align: left;
}
.thenav li ul li:nth-child(1) a:hover {
background-color: #F47575;
}
.thenav li ul li:nth-child(2) a:hover {
background-color: #f7d759;
}
.thenav li ul li a:hover {
background-color: red;
}
.thenav ul li ul {
display: none;
}
.thenav li:hover ul {
position: absolute;
}
.thenav li:hover ul {
display: block;
}
/* End of Dropdown */
.userlogin {
font-size: 12px;
top: 2px;
color: white;
}
input[type=text],
input[type=password] {
font-weight: bold;
margin: 0;
font-size: 8px;
height: 10px;
padding: 3px 5px 3px 5px;
color: 162354;
}
/* Stats Button */
.stat input[type=button] {
background-color: #6cd171;
color: blue;
border-radius: 6px;
font-weight: bold;
border: none;
float: left;
margin-top: 20px;
margin-left: 20px;
padding: 2px 2px;
font-family: Verdana, Geneva, sans-serif;
}
.log[type=button] {
background-color: white;
color: #008cff;
border-radius: 4px;
font-weight: bold;
border: none;
padding: 1px 2px 2px 2px;
position: relative;
left: 5px;
top: 3px;
<div class="header">
<h1 id="box" onload="changed()"><image src="nbaone.png" width="40px" height="55px" class="nba">NBA Legends</h1>
<div class="thenav" onload="changed()">
<ul>
<li><a href="http://www.nba.com" />Home</a>
</li>
<li onclick="changeP()">About</li>
<li>Players
<ul>
<li onmouseover="slow()">
</li>
<li><a href="#kobesec" />Kobe</a>
</li>
<li><a href="#" />Kevin Durant</a>
</li>
<li><a href="#" />The Goat</a>
</li>
</ul>
</li>
<li onclick="slow()">News</li>
</ul>
</div>
<div class="container">
</div>
</div>

html/css dropdown not appearing

Been working on a navbar in html/css and the dropdown doesn't appear. I've been playing around with the code but nothing seems to work. Once I delete the display: none from the .dropdown-content class, it seems to appear...
Could anyone please take a look? I've been at it for hours and reading every thread on this issue, but cannot figure it out. Thx in advance!
Here are my css and html snippets:
body {
width: 100%;
background-image: url("https://images.unsplash.com/photo-1458682625221-3a45f8a844c7?ixlib=rb0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&s=05e92845cd4b48607787e676d0d7d2e5");
background-size: cover;
}
#navdiv {
opacity: 0.70;
filter: (opacity=70;
)
}
#navdiv ul {
list-style-type: none;
width: 100%;
background: white;
line-height: 3rem;
float: right;
overflow: hidden;
}
#navdiv ul a {
text-decoration: none;
color: black;
padding: 2em;
}
#navdiv ul li {
float: right;
margin-right: 1em;
}
#logo {
float: left !important;
font-size: 2em;
margin-left: 1em;
}
#navdiv ul #logo:hover {
background: none;
}
#navdiv ul li a:hover,
dropdown:hover #dropbtn {
background: #B266FF;
transition: all 0.8s;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: center;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
.dropdown:hover .dropdown-content {
display: inline-block;
}
<body>
<div id="maindiv">
<div id="navdiv">
<ul>
<li id="logo">Potayto-Potatoh</li>
<li class="dropdown">About</li>
<li>Portfolio
<div class="dropdown-content">
work 1
work 2
work 3
</div>
</li>
<li>Contact</li>
</ul>
</div>
</div>
</body>
You need to Add dropdown for portfolio li not for about as it doesnt have dropdown-content
Demo
HTML:
<li class="dropdown">Portfolio
The dropdown-content div is not under dropdown div, the parent <li> element lacks the dropdown class specification.
Add the trigger class to the li element. Your CSS was also incorrect for the trigger, you wre refering to .dropdown (which is actually a class on the li for "about"!)
See https://jsfiddle.net/qxjbtot1/ for a working example.
body {
width: 100%;
background-image: url("https://images.unsplash.com/photo-1458682625221-3a45f8a844c7?ixlib=rb0.3.5&q=80&fm=jpg&crop=entropy&cs=tinysrgb&s=05e92845cd4b48607787e676d0d7d2e5");
background-size: cover;
}
#navdiv {
opacity: 0.70;
filter: (opacity=70;
)
}
#navdiv ul {
list-style-type: none;
width: 100%;
background: white;
line-height: 3rem;
float: right;
}
#navdiv ul a {
text-decoration: none;
color: black;
padding: 2em;
}
#navdiv ul li {
float: right;
margin-right: 1em;
}
#logo {
float: left !important;
font-size: 2em;
margin-left: 1em;
}
#navdiv ul #logo:hover {
background: none;
}
#navdiv ul li a:hover,
dropdown:hover #dropbtn {
background: #B266FF;
transition: all 0.8s;
}
li.dropdown {
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: center;
}
.dropdown-content a:hover {
background-color: #f1f1f1
}
li:hover div.dropdown-content {
display: block;
}
<body>
<div id="maindiv">
<div id="navdiv">
<ul>
<li id="logo">Potayto-Potatoh</li>
<li class="dropdown">About</li>
<li>Portfolio
<div class="dropdown-content">
work 1
work 2
work 3
</div>
</li>
<li>Contact</li>
</ul>
</div>
</div>
</body>