Hamburger drop down menu color not transferring - html

Thanks for taking time to read this question! So one minute everything was fine and then I refreshed my code after making too many changes to go back through, and this happened:
drop down menu without color:
None of the color from the header transferred into the dropdown. How do I fix this? Here is my code:
<header id="sticky-header">
<div class="nav">
<label for="toggle">☰</label>
<input type="checkbox" id="toggle" />
<nav>
<ul>
<li>Home</li>
<li>Bio</li>
<li>Music</li>
<li>Shows</li>
<li>Media</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>
header {
height: 67px;
background-color: #2b2b2b;
width: 100%;
position: fixed;
text-align: center;
}
nav ul {
margin-top: 13px;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
margin: 0.8em;
}
nav a {
font-weight: 800;
text-decoration: none;
text-transform: uppercase;
font-size: 0.95em;
padding: 0.5em;
color: #FFF;
}
nav a:hover,
nav a:focus {
color: #048575;
font-size: 1em;
}
label {
font-size: 2rem;
color: #FFF;
padding: 0.5em;
display: none;
width: 1em;
float: center;
}
#toggle {
display: none;
}
#media only screen and (max-width:650px) {
header {
padding-top: 0em;
padding-bottom: 0em;
background-color: #2b2b2b;
}
label {
display: block;
cursor: pointer;
}
nav li {
display: block;
display: none;
}
nav a {
display: block;
padding-top: 1em;
padding-bottom: 1em;
border-bottom: 1px solid black;
}
#toggle:checked + nav li {
display: block;
}
}
Sorry the formatting is a bit weird, copy and paste didn't quite work. Thanks for reading and if you can help, please do! (Other feedback is also appreciated).

I take it you want the black background applied to your header to be reflected in your dropdown menu? In this case, you'll need to apply the background to nav inside of your media query. Note that you'll also want to set a margin-top to bring your navbar up a bit to be 'flush' with your header:
nav {
background-color: #2b2b2b;
margin-top: -20px;
}
Which can be seen in the following:
header {
height: 67px;
background-color: #2b2b2b;
width: 100%;
position: fixed;
text-align: center;
}
nav ul {
margin-top: 13px;
padding: 0;
list-style: none;
}
nav li {
display: inline-block;
margin: 0.8em;
}
nav a {
font-weight: 800;
text-decoration: none;
text-transform: uppercase;
font-size: 0.95em;
padding: 0.5em;
color: #FFF;
}
nav a:hover,
nav a:focus {
color: #048575;
font-size: 1em;
}
label {
font-size: 2rem;
color: #FFF;
padding: 0.5em;
display: none;
width: 1em;
float: center;
}
#toggle {
display: none;
}
#media only screen and (max-width:650px) {
header {
padding-top: 0em;
padding-bottom: 0em;
background-color: #2b2b2b;
}
label {
display: block;
cursor: pointer;
}
nav {
background-color: #2b2b2b;
margin-top: -20px;
}
nav li {
display: block;
display: none;
}
nav a {
display: block;
padding-top: 1em;
padding-bottom: 1em;
border-bottom: 1px solid black;
}
#toggle:checked+nav li {
display: block;
}
}
<header id="sticky-header">
<div class="nav">
<label for="toggle">☰</label>
<input type="checkbox" id="toggle" />
<nav>
<ul>
<li>Home</li>
<li>Bio</li>
<li>Music</li>
<li>Shows</li>
<li>Media</li>
<li>Contact</li>
</ul>
</nav>
</div>
</header>

Related

how to add a dropdown to my current style of navigation

I need to add a dropdown to my "contact" section and I'm wondering if anyone could help me out with it. I've tried to use: https://www.w3schools.com/howto/howto_css_dropdown_navbar.asp
but with my ongoing style it is not 100% working correctly. Is there any other way I could implement a dropdown to my "contact" section without adding a "Button" property?
<nav>
<div id="logo"><img src="images/logow.png"></div>
<label for="drop" class="toggle"><i class="fas fa-bars"></i></label>
<input type="checkbox" id="drop"/>
<ul class="menu">
<li>Home</li>
<li>Pricing</li>
<li>Faq</li>
<li>Contact</li>
</div>
</ul>
</nav>
.toggle, [id=drop] {
display: none;
}
nav {
margin:0;
padding: 0;
background-color: black;
}
#logo {
display: block;
padding: 10px 0 0 30px;
width: 10%;
float: left;
}
nav img{
width: 200px;
}
nav:after {
content: "";
display: table;
clear: both;
}
nav ul {
float: right;
list-style: none;
padding: 0;
margin: 0;
line-height: 32px;
}
nav ul li {
display: inline-block;
float: left;
}
nav a {
display: block;
padding: 14px 20px;
color: white;
font-size: 17px;
text-decoration: none;
}
nav a:hover {
color: #FF4E00;
}
#media (max-width :768px) {
#logo {
display: block;
padding: 20px 0 10px 0;
width: 100%;
text-align: center;
float: none;
}
nav {
margin: 0;
}
nav ul {
float: left;
width: 100%;
text-align: center;
}
.toggle + a,
.menu {
display: none;
}
.toggle {
display: block;
background-color: white;
padding:14px 20px;
color:black;
font-size:17px;
text-decoration:none;
border:none;
cursor: pointer;
text-align: center;
}
[id^=drop]:checked + ul {
display: block;
}
nav ul li {
display: block;
width: 100%;
}
}
I think It is necessary to add button...
check my code i have done some changes for you in you code by clicking "Run code snippet" and then "view full page".
.toggle,
[id=drop] {
display: none;
}
nav {
margin: 0;
padding: 0;
background-color: black;
}
#logo {
display: block;
padding: 10px 0 0 30px;
width: 10%;
float: left;
}
nav img {
width: 200px;
}
nav:after {
content: "";
display: table;
clear: both;
}
nav ul {
float: right;
list-style: none;
padding: 0;
margin: 0;
line-height: 32px;
}
nav ul li {
display: inline-block;
float: left;
}
nav a {
display: block;
padding: 14px 20px;
color: white;
font-size: 17px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 20px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.navbar a:hover,
.dropdown:hover .dropbtn {
background-color: red;
}
.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 {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
.dropdown-content a:hover {
background-color: #ddd;
}
.dropdown:hover .dropdown-content {
display: block;
}
nav a:hover {
color: #FF4E00;
}
#media (max-width :768px) {
#logo {
display: block;
padding: 20px 0 10px 0;
width: 100%;
text-align: center;
float: none;
}
nav {
margin: 0;
}
nav ul {
float: left;
width: 100%;
text-align: center;
}
.toggle+a,
.menu {
display: none;
}
.toggle {
display: block;
background-color: white;
padding: 14px 20px;
color: black;
font-size: 17px;
text-decoration: none;
border: none;
cursor: pointer;
text-align: center;
}
[id^=drop]:checked+ul {
display: block;
}
nav ul li {
display: block;
width: 100%;
}
<body>
<nav>
<div id="logo"><img src="images/logow.png"></div>
<label for="drop" class="toggle"><i class="fas fa-bars"></i></label>
<input type="checkbox" id="drop" />
<ul class="menu">
<li>Home</li>
<li>Pricing</li>
<li>Faq</li>
<li>
<div class="dropdown">
<button class="dropbtn">Contact
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</li>
</div>
</ul>
</nav>
</body>

Unwanted spacing under buttons in navigation bar

I'm new to coding websites and currently doing an assignment.
My issue is that when mousing over my navigation bar, the hover color does not fully cover the entire item. How do I solve this? Is it occurring due to my logo?
My html code:
.navigation {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(134, 35, 35);
font-family: Megrim, cursive;
font-weight: bold;
}
/* floats navigation buttons to the right */
.naviright {
float: right;
}
/*makes elements start from the left*/
.navigation li {
float: left;
}
.navigation li a {
display: block;
color: white;
text-align: center;
padding: 12px 16px;
text-decoration: none;
}
/* Change the link color to #111 (black) on hover */
.navigation li a:hover:not(.active) {
background-color: #111;
}
.navigation li a:hover:active {
background-color: #4CAF50;
}
/*TopNav End*/
/*logo*/
#logo {
width: 40px;
height: 40px;
overflow: hidden;
padding-left: 20px;
padding-bottom: 5px;
padding-top: 2px;
}
#logoname {
color: rgb(255, 255, 255);
font-size: 20px;
}
<nav>
<ul class="navigation">
<li id="logo"><img src="images\logo.svg"></li>
<li id="logoname"><a>Stationery Haven</a></li>
<div class="naviright">
<li>Home</li>
<li>Categories</li>
<li>Feedback</li>
<li>Contact Us</li>
</div>`enter code here`
</ul>
</nav>
Add line-height to li a
.navigation li a {
display: block;
color: white;
text-align: center;
padding: 12px 16px;
text-decoration: none;
line-height:22px;
}
.navigation {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: rgb(134, 35, 35);
font-family: Megrim, cursive;
font-weight: bold;
}
/* floats navigation buttons to the right */
.naviright {
float: right;
}
/*makes elements start from the left*/
.navigation li {
float: left;
}
.navigation li a {
display: block;
color: white;
text-align: center;
padding: 12px 16px;
text-decoration: none;
line-height:22px;
}
/* Change the link color to #111 (black) on hover */
.navigation li a:hover:not(.active) {
background-color: #111;
}
.navigation li a:hover:active {
background-color: #4CAF50;
}
/*TopNav End*/
/*logo*/
#logo {
width: 40px;
height: 40px;
overflow: hidden;
padding-left: 20px;
padding-bottom: 5px;
padding-top: 2px;
}
#logoname {
color: rgb(255, 255, 255);
font-size: 20px;
}
<nav>
<ul class="navigation">
<li id="logo"><img src="images\logo.svg"></li>
<li id="logoname"><a>Stationery Haven</a></li>
<div class="naviright">
<li>Home</li>
<li>Categories</li>
<li>Feedback</li>
<li>Contact Us</li>
</div>`enter code here`
</ul>
</nav>
OK I reviewed you code I think if you add or change following css code then it will be work for you:
#logo {
width: 40px;
height: 40px;
overflow: hidden;
padding-left: 20px;
padding-bottom: 4px; // Changed here 5px to 4px
padding-top: 2px;
}
.navigation li a {
display: block;
color: white;
text-align: center;
padding: 12px 16px;
line-height: 22px; // Logo test font-size: 20px; so this line need to be added
text-decoration: none;
}
1) You could solve this by increasing the size of
.naviright li a {font-size: 20px;}
2) or you could just give the line-height to -
.navigation li a {line-height: 22px;}
Here is the flex based solution I've tried Fiddle

How can I put a logo image in the middle of bootstrap fixed nav?

I am trying to create a website using bootstrap and I have used bootstrap before. This time I am making a site with a fixed nav and the logo will be in the middle of the nav links. I also want the logo to be on top of the nav links.
This image will show what I am trying to do:
The code I have now is this:
html, body {
margin: 0;
padding: 0;
background: #fff;
color: #000;
font-size: 14px;
font-family: 'Helvetica', serif;
}
.navbar {
background: none;
border: none;
margin-top: 20px;
}
.container-fluid {
padding-left: 0px;
padding-right: 0px;
margin-left: -40px;
}
.navbar ul li {
display: block;
text-align: center;
float: left;
width: 20%;
}
.fourth-color {
background-color: #ffecec;
padding-top: 30px;
padding-bottom: 30px;
}
.third-color {
background-color: #122212;
padding-top: 30px;
padding-bottom: 30px;
}
.second-color {
background-color: #aaa;
padding-top: 30px;
padding-bottom: 30px;
}
.first-color {
background-color: #f25727;
padding-top: 30px;
padding-bottom: 30px;
}
<!-- Start of Nav Bar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<ul>
<li class="first-color">First</li>
<li class="second-color">Second</li>
<li>Logo</li>
<li class="third-color">Third</li>
<li class="fourth-color">Fourth</li>
</ul>
</div>
</nav>
When I try to link an image, it doesn't fit properly and screws with the whole nav bar. Any help is appreciated!
Your problem here is you only have padding on the li's that have classes. (which is why the anchor that says logo is not centered is because it doesn't have a class with padding)
ex.
.navbar ul li {
display: block;
text-align: center;
float: left;
width: 20%;
}
.fourth-color, .third-color, .second-color, .first-color {
padding-top: 30px;
padding-bottom: 30px;
}
Apply the padding to all the lists and you're problem is fixed.
.navbar ul li {
padding-top: 30px;
padding-bottom: 30px;
}
As for the middle logo. You have to use position relative and then add your additional styles to that either by class or in my case :nth-child as seen below.
#import url("http://fonts.googleapis.com/css?family=Raleway&subset=latin,latin-ext");
html, body {
margin: 0;
padding: 0;
background: #fff;
color: #000;
font-size: 14px;
font-family: 'Helvetica', serif;
}
.navbar {
margin-top: 1em;
text-align: center;
}
.navbar ul {
padding: 0;
text-decoration: none;
list-style: none;
}
.navbar li {
display: block;
float: left;
width: calc(20% - 1px - 0.906752000000002em);
padding: 1.16em 1em;
font: 100 21px "Raleway", sans-serif;
background: #000;
color: #fff;
opacity: 1;
transition: all 0.1s linear;
}
.navbar li:nth-child(1) {
background: #ff410e;
}
.navbar li:nth-child(2) {
background: #f4ca00;
}
.navbar li:nth-child(3) {
background: #fff;
color: #000;
border: 1px solid #000;
border-radius: 2.84em;
padding: 1.76em 0;
width: 20%;
position: relative;
margin: -0.64em -2.16em;
z-index: 1;
}
.navbar li:nth-child(3) a {
color: #000;
}
.navbar li:nth-child(4) {
background: #99d81b;
}
.navbar li:nth-child(5) {
background: #00abf3;
}
.navbar li:hover:not(:nth-child(3)) {
opacity: 0.7;
}
.navbar a {
color: #fff;
text-decoration: none;
}
.navbar .active {
text-decoration: underline;
}
<!-- Start of Nav Bar -->
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<ul>
<li><a class="active" href="#">First</a></li>
<li>Second</li>
<li>Logo</li>
<li>Third</li>
<li>Fourth</li>
</ul>
</div>
</nav>
Unless you plan on creating a dropdown list I wouldn't recommend using a list for this menubar. Instead you can just style the anchors to fit your needs. (Remember to keep your code DRY):

Broke My Media Query Some How

[link]http://ramadaan.rocks/test.html?nocache=1
Somehow I broke my media query. Trying to make a nav and now when under 600px, the media query seems to not be working.
So where is the media query being broken? Is the nav too long? Too many list items?
Any help? Thanks,
.nav ul {
list-style: none;
background-color: #000;
text-align: center;
padding: 0;
margin: 0;
}
.nav li {
font-family: 'Francois One', sans-serif;
font-size: 20px;
text-transform: uppercase;
line-height: 40px;
height: 40px; /* line-height and height set at same value centers the content vertically in the middle */
border-bottom: 1px solid #888;
color: #fff;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
transition: .3s background-color;
}
.nav a:hover {
background-color: #e17143;
}
.nav a.active {
background-color: #fff;
color: #e17143;
cursor: default;
}
#media screen and (min-width: 600px) {
.nav li {
width: 120px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 14px;
}
}
.nav li {
float: left;
}
.nav ul {
overflow: auto;
width: 600px;
margin: 0 auto;
}
.nav {
background-color: #444;
}
<div class="nav">
<nav>
<ul>
<li><a class="active" href="#">Home</a></li>
<li>What Is Ramadan?</li>
<li>How Do I Fast?</li>
<li>Who Can Fast?</li>
<li>Prophetic Commentary</li>
<li>Tarawih Prayer</li>
<li>30 Ajza' of Qur'an</li>
<li>Commonly Asked Questions</li>
<li>Contact</li>
</ul>
</nav>

inline h3 moves ul to the right

I'd like to have the navigation bar centered and the text placed to left as it is, but when I add the h3-tag the navigation bar moves to the right. How can I do this?
html,
body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
#toptext {
margin: 5px 0px 0px 10px;
padding: 0;
display: inline-block;
float: left;
font-style: bold;
font-size: 2em;
color: white;
}
.nav ul {
list-style: none;
background-color: #444;
text-align: center;
padding: 0;
margin: 0;
}
.nav li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
line-height: 40px;
text-align: left;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
padding-left: 15px;
border-bottom: 1px solid #888;
transition: .3s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #aaa;
color: #444;
cursor: default;
}
/* Sub Menus */
.nav li li {
font-size: .8em;
}
/*******************************************
Style menu for larger screens
Using 650px (130px each * 5 items), but ems
or other values could be used depending on other factors
********************************************/
#media screen and (min-width: 650px) {
.nav li {
width: 130px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1em;
display: inline-block;
margin-right: -4px;
}
.nav a {
border-bottom: none;
}
.nav > ul > li {
text-align: center;
}
.nav > ul > li > a {
padding-left: 0;
}
/* Sub Menus */
.nav li ul {
position: absolute;
display: none;
width: inherit;
}
.nav li:hover ul {
display: block;
}
.nav li ul li {
display: block;
}
}
<div class="nav">
<h3 id="toptext">Text text text text</h3>
<ul>
<li class="home"><a class="active" href="#">Home</a>
</li>
<li class="about">About
</li>
<li>Other
<ul>
<li>Site1
</li>
<li>Site2
</li>
</ul>
</li>
<li class="contact">Contact
</li>
</ul>
</div>
I used the navigation bar from: http://css-snippets.com/drop-down-navigation/
Anything that is in the document flow is going to affect the position of the menu. So you would would have to take the h3 out of the flow by positioning it absolutely.
#toptext {
margin: 5px 0px 0px 10px;
padding: 0;
font-style: bold;
font-size: 2em;
color: white;
position: absolute;
}
This has other issues but solves your initial problem.
html,
body {
height: 100%;
margin: 0;
padding: 0;
width: 100%;
}
#toptext {
margin: 5px 0px 0px 10px;
padding: 0;
/*
display: inline-block;
float: left;
*/
font-style: bold;
font-size: 2em;
color: white;
position: absolute;
}
.nav ul {
list-style: none;
background-color: #444;
text-align: center;
padding: 0;
margin: 0;
}
.nav li {
font-family: 'Oswald', sans-serif;
font-size: 1.2em;
line-height: 40px;
text-align: left;
}
.nav a {
text-decoration: none;
color: #fff;
display: block;
padding-left: 15px;
border-bottom: 1px solid #888;
transition: .3s background-color;
}
.nav a:hover {
background-color: #005f5f;
}
.nav a.active {
background-color: #aaa;
color: #444;
cursor: default;
}
/* Sub Menus */
.nav li li {
font-size: .8em;
}
/*******************************************
Style menu for larger screens
Using 650px (130px each * 5 items), but ems
or other values could be used depending on other factors
********************************************/
#media screen and (min-width: 650px) {
.nav li {
width: 130px;
border-bottom: none;
height: 50px;
line-height: 50px;
font-size: 1em;
display: inline-block;
margin-right: -4px;
}
.nav a {
border-bottom: none;
}
.nav > ul > li {
text-align: center;
}
.nav > ul > li > a {
padding-left: 0;
}
/* Sub Menus */
.nav li ul {
position: absolute;
display: none;
width: inherit;
}
.nav li:hover ul {
display: block;
}
.nav li ul li {
display: block;
}
}
<div class="nav">
<h3 id="toptext">Text text text text</h3>
<ul>
<li class="home"><a class="active" href="#">Home</a>
</li>
<li class="about">About
</li>
<li>Other
<ul>
<li>Site1
</li>
<li>Site2
</li>
</ul>
</li>
<li class="contact">Contact
</li>
</ul>
</div>
Its because your h3 is inside the nav div. try making the h3 absolute positioned and your .nav class relatively positioned.