issue to place items in a navbar - html

I have a problem with the navbar. I would like the "register" button to be to the right of the "login" button, with a space of xxxpx from the right edge of the window, so that when you have the hover on the "login" button the form with the inputs does not appear off the screen. I tried to put the "register" button inside "" but due to the CSS code I get the login form even when there is hover on the "register" button and not is a desired behavior. How can I place the "register" button to the right of the "login" button?
P.S. This is code for anguar but does the same.
Thanks.
.space {
width: 350px;
}
.dropdown {
float: right;
}
.forminput {
margin: 5px;
}
.formbutton {
margin: 5px;
float: right;
}
/* Add a black background color to the top navigation */
.topnav {
background-color: #333;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Add an active class to highlight the current page */
.active {
background-color: #4CAF50;
color: white;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
/* Dropdown container - needed to position the dropdown content */
.dropdown {
overflow: hidden;
}
/* Style the dropdown button to fit inside the topnav */
.dropdown .dropbtn-login {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
/* Style the dropdown content (hidden by default) */
.dropdown-content-login {
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;
}
/* Style the links inside the dropdown */
.dropdown-content-login a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a dark background on topnav links and the dropdown button on hover */
.topnav a:hover,
.dropdown:hover .dropbtn-login {
background-color: #555;
color: white;
}
/* Add a grey background to dropdown links on hover */
.dropdown-content-login a:hover {
background-color: #ddd;
color: black;
}
/* Show the dropdown menu when the user moves the mouse over the dropdown button */
.dropdown:hover .dropdown-content-login {
display: block;
}
/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
#media screen and (max-width: 600px) {
.topnav a:not(:first-child),
.dropdown .dropbtn-login {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
.space {
width: 0px;
}
.dropdown {
float: left;
}
}
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
#media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {
float: none;
}
.topnav.responsive .dropdown-content-login {
position: relative;
}
.topnav.responsive .dropdown .dropbtn-login {
display: block;
width: 100%;
text-align: left;
}
}
<div class="topnav" id="myTopnav">
<a routerLink="/" class="active">Home</a>
<a routerLink="/gallery">Gallery</a>
<div class="dropdown">
<button class="dropbtn-login">Login</button>
<div class="dropdown-content-login">
<form>
<input class="forminput" placeholder="username">
<input class="forminput" type="password" placeholder="password">
<button class="formbutton" type="submit">Login</button>
</form>
</div>
</div>
<a style="float:right" routerLink="/register">Register</a>
<div style="float:right" class="space"></div>
☰
</div>

Simply place anchor tag for 'Register' button above the 'dropdown' div.
<div class="topnav" id="myTopnav">
<a routerLink="/" class="active">Home</a>
<a routerLink="/gallery">Gallery</a>
<a style="float:right" routerLink="/register">Register</a>
<div class="dropdown">
<button class="dropbtn-login">Login</button>
<div class="dropdown-content-login">
<form>
<input class="forminput" placeholder="username">
<input class="forminput" type="password" placeholder="password">
<button class="formbutton" type="submit">Login</button>
</form>
</div>
</div>
<div style="float:right" class="space"></div>
☰
</div>

Related

Responsive menu with hamburger icon aligned to the left

I have a responsive menu that on large screens you see the drop-down menu centered on the page. But on small screens you see a hamburger menu also centered on the page, and I want the icon to be seen on the left. How can i do that? It looks like this: https://postimg.cc/dLFkHH1Z
On large screens there is no problem but in small screens i want to see the hamburguer icon on the left.
Thanks in advance.
/* Toggle between adding and removing the "responsive" class to topnav when the user clicks on the icon */
function myFunction() {
var x = document.getElementById("myTopnav");
if (x.className === "topnav") {
x.className += " responsive";
} else {
x.className = "topnav";
}
}
/* Add a black background color to the top navigation */
.topnav {
background-color: white;
overflow: hidden;
display:flex;
justify-content: center;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Add an active class to highlight the current page */
.active {
background-color: #4CAF50;
color: white;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
/* Dropdown container - needed to position the dropdown content */
.dropdown {
float: left;
overflow: hidden;
}
/* Style the dropdown button to fit inside the topnav */
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
/* Style the dropdown content (hidden by default) */
.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;
}
/* Style the links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a dark background on topnav links and the dropdown button on hover */
.topnav a:hover, .dropdown:hover .dropbtn {
background-color: #555;
color: white;
}
/* Add a grey background to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
/* Show the dropdown menu when the user moves the mouse over the dropdown button */
.dropdown:hover .dropdown-content {
display: block;
}
/* When the screen is less than 600 pixels wide, hide all links, except for the first one ("Home"). Show the link that contains should open and close the topnav (.icon) */
#media screen and (max-width: 600px) {
.topnav a, .dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
/* The "responsive" class is added to the topnav with JavaScript when the user clicks on the icon. This class makes the topnav look good on small screens (display the links vertically instead of horizontally) */
#media screen and (max-width: 600px) {
.topnav.responsive {position: relative;}
.topnav.responsive a.icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
.topnav.responsive .dropdown {float: none;}
.topnav.responsive .dropdown-content {position: relative;}
.topnav.responsive .dropdown .dropbtn {
display: block;
width: 100%;
text-align: left;
}
}
<html>
<head>
<title>Menú Desplegable Responsive</title>
<LINK REL=StyleSheet HREF="estilos.css" TYPE="text/css">
<script src="menu.js" type="text/javascript"></script>
</head>
<body>
<div class="topnav" id="myTopnav">
Home
News
Contact
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
About
☰
</div>
</body>
</html>
i have found the solution.
document.getElementById("menuBars").onclick = function(e) {
e.preventDefault();
var x = document.getElementById("myTopnav");
x.classList.toggle("responsive");
}
body {
margin: 0;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: white;
text-align: center;
}
/*
.topnav .fl {
float: left;
}
.topnav .fr {
float: right;
}
*/
.topnav .main {
display: inline-block;
}
.topnav .main a {
float: left;
}
.topnav a {
display: inline-block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #4CAF50;
color: white;
}
.topnav .icon {
display: none;
}
main {
padding-left: 16px;
}
#media screen and (max-width: 600px) {
.topnav a, .dropdown .dropbtn {
display: none;
}
.topnav a.icon {
float: right;
display: block;
}
}
#media screen and (max-width: 600px) {
.topnav.responsive {
position: relative;
}
.topnav.responsive .icon {
position: absolute;
right: 0;
top: 0;
}
.topnav.responsive a {
float: none;
display: block;
text-align: left;
}
}
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Menú</title>
<LINK REL=StyleSheet HREF="estilos.css" TYPE="text/css">
<script src="menu.js" type="text/javascript"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<nav class="topnav" id="myTopnav">
Home
<a href="#about" >About</a>
News
Contact
<!--<a href="" class="icon" id="menuBars">-->
☰
<i class="fa fa-bars"></i>
</a>
</nav>
</body>
</html>

Make dropdown menu same width as button/parent

I have a problem where I want the dropdown menu to be the same width as the button to activate it.
I tried:
width: 100% (didn't work)
html {
--main-text-color: white;
--main-background-color: black;
--main-navbar-color: rgb(51, 51, 51);
--main-link-color: rgb(200, 200, 255);
overflow-x: hidden;
background-color:var(--main-background-color);
}
/*Navbar section*/
#font-face {
font-family: arrow;
src: url('https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0');
}
/*Below from w3schools*/
/* Navbar container */
.navbar {
overflow: hidden;
background-color: rgb(51, 51, 51);
font-family: "arrow", "Impact", "Impactincase", serif;
}
.navbar a {
float: left;
font-size: 50px;
color: var(--main-text-color);
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.navbar a:hover {
color: rgb(225, 225, 255);
text-decoration: none;
}
.navbar .dropdown .dropdown-content a:hover {
color: black;
}
/* Links inside the navbar */
.navbar .notlogo {
float: right;
font-size: 16px;
color: var(--main-text-color);
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The dropdown container */
.dropdown {
float: right;
overflow-x: hidden;
}
/* Dropdown button */
.dropdown .dropbtn {
font-size: 50px;
border: none;
outline: none;
color: var(--main-text-color);
padding: 14px 16px;
background-color: inherit;
font-family: inherit; /* Important for vertical align on mobile phones */
margin: 0; /* Important for vertical align on mobile phones */
}
/* Add a blue background color to navbar links on hover */
.navbar .notlogo:hover, .dropdown:hover .dropbtn {
background-color: rgb(51, 51, 100);
}
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
width: inherit;
z-index: 1;
white-space: nowrap;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
display: block;
font-size: 16px;
padding: 12px 16px;
text-decoration: none;
text-align: left;
width: 100%;
}
/* Add a grey background color to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/*End of copying from w3schools*/
#normallogo {
display: inline-block;
}
#smalllogo {
display: none;
}
#media screen and (max-width: 840px) {
#normallogo {
display: none;
}
#smalllogo {
display: inline-block;
}
}
<body style="margin:0;padding:0;">
<div class="navbar" id="loadcorrectly">
<a class="ImpactD" href="index" id="normallogo">JDM Cars Galore</a>
<a class="ImpactD" href="index" id="smalllogo">JDMCG</a>
<div class="dropdown">
<button class="dropbtn">
Enquiries 
</button>
<div class="dropdown-content">
Request a car
About
Contact us
Copyright
</div>
</div>
<div class="dropdown">
<button class="dropbtn">
Cars 
</button>
<div class="dropdown-content">
Sprinter
RX-7
GT-R
Corona
Civic
</div>
</div>
</div>
</body>
This code is essentially the same as https://www.w3schools.com/howto/howto_css_dropdown.asp but changed.
There are several ways to accomplish this depending on your preference. The biggest issue you're facing, is that you assume the dropdown-content should know the width of it's parent. An absolute positioned element can only know the width of it's parent under certain conditions - and those conditions aren't being met.
Option #1. (Simplest) way to make the the drop-down the same width is to set a fixed width to your class (.dropdown-content) that matches the fixed width of your button that activates it.
Option #2. A more (Dynamic) way is to set the parent class (.dropdown) a position:relative. Due to your structure, there are several other changes you'll have to make to get the desired result such as getting rid of the overflow:hidden on .navbar & .dropdown.
Option #3. The (Recommended) way would be changing your structure of the Nav Bar & it's contents completely. The .navbar should be position:absolute or position:fixed (depending on how you want the nav bar to behave.) Then each of the .dropdown buttons can be position:absolute or position:relative. Then, your .dropdown-content can be set to width:100%. (Which is the behavior you're looking for).
Updated your code check :
https://jsfiddle.net/adratarek/7yw6nvka/6/
changes:
.dropdown-content {
position: absolute;
width: 100%;
}
.navbar {
/*overflow: hidden; removed and adding static height */
height: 88px;
}
You need to alter the position of the .dropdown-content class to be relative:
/* Dropdown content (hidden by default) */
.dropdown-content {
display: none;
position: relative;
background-color: #f9f9f9;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
width: inherit;
z-index: 1;
white-space: nowrap;
}

Unable to add in the text colour of my menu navbar

This should be a fairly simple thing, however no matter where I add in color: black; the menu items do not show, you can only see them when I click and highlight over them. Please could someone point out which class needs to color tag to alter the text colour to black? I have tried placing it in .topnav with color: black; but did not change anything?
Also I can't get the active class to change when I'm on a different page, seems to only stay on the Home page?
.topnav {
background-color:white;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Add an active class to highlight the current page */
.active {
background-color: grey;
color: white;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
/* Dropdown container - needed to position the dropdown content */
.dropdown {
float: left;
overflow: hidden;
}
/* Style the dropdown button to fit inside the topnav */
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
/* Style the dropdown content (hidden by default) */
.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;
}
/* Style the links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a dark background on topnav links and the dropdown button on hover */
.topnav a:hover, .dropdown:hover .dropbtn {
background-color: #555;
color: white;
}
/* Add a grey background to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
/* Show the dropdown menu when the user moves the mouse over the dropdown button */
.dropdown:hover .dropdown-content {
display: block;
}
THE MENU CODE:
<!-- NAV BAR homepage-->
<nav>
<!-- https://www.w3schools.com/howto/howto_js_topnav_responsive.asp -->
<div class="topnav" id="myTopnav">
<i class="fas fa-home"> Home</i>
<i class="fas fa-info-circle"> About</i>
<i class="fas fa-envelope"> Contact</i>
<?php
// The below is a small 'if else' statement which depending on whether a user is logged in or not, the menu items will differ
// If logged in, then show the logout and the dashboard item
// If not logged in, then show the login and signup button
if (!isset($_SESSION['studentID'])) {
echo "<a name='login-submit' href='login.php'><i class='fas fa-sign-in-alt'> Login</i></a>";
echo "<a href='signup.php'><i class='fas fa-check-square'> Sign Up</i></a>";
} else if (isset($_SESSION['studentID'])) {
echo "<a href ='dashboard.php'><i class='fas fa-tachometer-alt'> Dashboard</i></a> ";
echo "<a name='logout-submit' href='scripts/logout-script.php'><i class='fas fa-sign-out-alt'> Logout</i></a>";
}
?>
☰
</div>
</nav>
I have right clicked into the console to check the styles tab:
This is what I see on my screen without hovering over an item in the menu:
Then this is what I see when I hover over an item (About):
Just add color: black to yours .topnav a components and get out the text from the fontawesome tag. For example replace that:
<i class="fas fa-envelope"> Contact</i>
to that:
<i class="fas fa-envelope"></i> Contact
You will get something like that:
.topnav {
background-color: white;
overflow: hidden;
}
/* Style the links inside the navigation bar */
.topnav a {
float: left;
display: block;
color: black;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
/* Add an active class to highlight the current page */
.active {
background-color: grey;
color: white;
}
/* Hide the link that should open and close the topnav on small screens */
.topnav .icon {
display: none;
}
/* Dropdown container - needed to position the dropdown content */
.dropdown {
float: left;
overflow: hidden;
}
/* Style the dropdown button to fit inside the topnav */
.dropdown .dropbtn {
font-size: 17px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
/* Style the dropdown content (hidden by default) */
.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;
}
/* Style the links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Add a dark background on topnav links and the dropdown button on hover */
.topnav a:hover,
.dropdown:hover .dropbtn {
background-color: #555;
color: white;
}
/* Add a grey background to dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
color: black;
}
/* Show the dropdown menu when the user moves the mouse over the dropdown button */
.dropdown:hover .dropdown-content {
display: block;
}
<!-- NAV BAR homepage-->
<nav>
<!-- https://www.w3schools.com/howto/howto_js_topnav_responsive.asp -->
<div class="topnav" id="myTopnav">
<i class="fas fa-home"></i> Home
<i class="fas fa-info-circle"></i> About
<i class="fas fa-envelope"></i> Contact
<a name='login-submit' href='login.php'><i class='fas fa-sign-in-alt'></i> Login</a>;
<a href='signup.php'><i class='fas fa-check-square'></i> Sign Up</a>;
<a href='dashboard.php'><i class='fas fa-tachometer-alt'></i> Dashboard</a>;
<a name='logout-submit' href='scripts/logout-script.php'><i class='fas fa-sign-out-alt'></i> Logout</a>;
☰
</div>
</nav>
For a first pitch, I would say that the color of your text is the same as the background of the navbar/body so you could try adding a background-color: color to your navbar.
.topnav a {
background-color: lightgray; //background-color
float: left;
display: block;
color: black; //change color of the text
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
If you decide to not add a background-color you can consider changing the color of the text to any other with color: [color].
a good way to assure if the color is not being overwritten you can put "!important" after the color like the following code below
.top-nav {
color:black !important;
}
in above code if you want to add background full navbar then added
.topnav{
background-color:hotpink;
overflow:hidden;
}
image look like below
if you want to added background only item then added below style code into
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
background: red;// background will be red all menu item
}
image like below

Changing Content of dropdown button when hovering over dropdown elements

I currently have a navigation bar with typical links "Home, About, Resume, Contact".
I currently have code so when you hover over Resume (by default has an arrow pointing down), a dropdown appears and the direction of the arrow changes to point up using two span classes (code is below).
What I want to achieve is while hovering over the dropdown contents, the arrow is still pointing up (currently it reverts to pointing down while hovering over dropdown links).
Here is the current Code:
CSS/HTML:
/* Navbar links besides Resume */
.container1 {
overflow: hidden;
font-family: Cabin,Helvetica,Arial,sans-serif; /*changes font of name, about, contact*/
text-align: center;
}
/*Navbar links besides Resume */
.container1 a {
display: inline;
font-size: 30px;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
display: inline;
vertical-align: middle;
}
/* Affects Resume*/
.dropdown .dropbtn {
display: inline;
font-size: 30px;
font-family: Cabin,Helvetica,Arial,sans-serif;
border: none;
outline: none;
color: inherit;
padding: 14px 16px;
background-color: inherit;
}
/* color of Resume when hovered */
.container a:hover, .dropdown:hover .dropbtn {
background-color: inherit;
}
button .hover { display: none; }
button:hover .no_hover { display: none; }
button:hover .hover { display: inline; }
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
left: 52.3%;
background-color: white;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
<div class="container1">
<a id="home" href="#">Michael Geng</a>
<a id="about" href="#">About</a>
<div class="dropdown">
<a id = "resume" href="#"><button class="dropbtn">
<span class="no_hover">Resume &#9660</span>
<span class="hover">Resume &#9650</span>
</button></a>
<div class="dropdown-content">
<a id = "objective" href="#">Objective</a>
<a id = "education" href="#">Education</a>
<a id = "skills" href="#">Skills</a>
</div> <!-- dropdown-content -->
</div> <!-- dropdown -->
<a id="contact" href="#">Contact</a>
</ul>
</div> <!--container1 -->
My current thought this line of code where when you hover over the dropdown contents to change the display but I have not got it working:
.dropdown-content:hover ~ .no_hover{display: none; }
.dropdown-content:hover ~ .hover{display: inline; }
You need to change the CSS that triggers the appropriate arrow span to be displayed to be based on hovering over .dropdown. See updated snippet.
/* Navbar links besides Resume */
.container1 {
overflow: hidden;
font-family: Cabin,Helvetica,Arial,sans-serif; /*changes font of name, about, contact*/
text-align: center;
}
/*Navbar links besides Resume */
.container1 a {
display: inline;
font-size: 30px;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
display: inline;
vertical-align: middle;
}
/* Affects Resume*/
.dropdown .dropbtn {
display: inline;
font-size: 30px;
font-family: Cabin,Helvetica,Arial,sans-serif;
border: none;
outline: none;
color: inherit;
padding: 14px 16px;
background-color: inherit;
}
/* color of Resume when hovered */
.container a:hover, .dropdown:hover .dropbtn {
background-color: inherit;
}
button .hover { display: none; }
.dropdown:hover .no_hover { display: none; }
.dropdown:hover .hover { display: inline; }
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
left: 52.3%;
background-color: white;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-content a {
float: none;
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: #ddd;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
<div class="container1">
<a id="home" href="#">Michael Geng</a>
<a id="about" href="#">About</a>
<div class="dropdown">
<a id = "resume" href="#"><button class="dropbtn">
<span class="no_hover">Resume &#9660</span>
<span class="hover">Resume &#9650</span>
</button></a>
<div class="dropdown-content">
<a id = "objective" href="#">Objective</a>
<a id = "education" href="#">Education</a>
<a id = "skills" href="#">Skills</a>
</div> <!-- dropdown-content -->
</div> <!-- dropdown -->
<a id="contact" href="#">Contact</a>
</ul>
</div> <!--container1 -->

Drop down menu doesn't work how I want it to

I am trying to make a menu which contains one menu-item with a dropdown, however I can't seem to get it quite right.
I started off with combining my existing menu bar to a piece of code for a dropdown, I have managed to get de drop down item in the menu bar, but I don't know how to get the menu bar back to the top again and it still has a blank on the left.
There is also an extra empty item in my drop down menu and I don't know how to get rid off it?
Can someone please help me I feel like I am overlooking something
.menu-bar {
position: fixed;
width: 100vw;
background-color: #134c95;
color: white;
display: flex;
flex-direction: row;
justify-content: center;
opacity: 0.8;
}
.menu-item {
padding: 10px;
cursor: default;
font-size: 15pt;
margin-left: 15px;
margin-right: 15px;
}
.menu-item:hover,
a:hover {
background-color: white;
cursor: pointer;
color: 234c95;
}
.menu-bar a {
color: white;
}
.menu-bar a:visited {
color: white;
}
.menu-bar a:link,
.menu-bar a:visited {
text-decoration: none;
}
/*
.menu-bar a:hover {
color: #134c95;
}
*/
/* Dropdown Button */
.dropbtn {
background-color: inherit;
color: white;
/* padding: 16px;*/
/* font-size: 16px;*/
border: none;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
/*
.dropdown {
position: fixed;
display: inline-block;
}
*/
/* Dropdown Content (Hidden by Default) */
.dropdown-content {
display: none;
position: absolute;
background-color: white;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
/* z-index: 1;*/
}
/* Links inside the dropdown */
.dropdown-content a {
color: #234c95;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/* Change color of dropdown links on hover */
.dropdown-content a:hover {
background-color: 234c95;
color: white;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-content {
display: block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .dropbtn {
background-color: white;
color: #234c95;
}
<div class="menu-bar">
<a href="instructiestest.html">
<div class="menu-item">Welkom</div>
</a>
<a href="instructie2.html">
<div class="menu-item">Aanmelden Portbase</div>
</a>
<a href="instructie3.html">
<div class="menu-item">De App</div>
</a>
<a href="testing.html">
<div class="dropdown">
<button class="dropbtn">
<div class="menu-item">Het team</div>
<div class="dropdown-content">
Google
Facebook
YouTube
</div>
</button>
</div>
</a>
</div>
Remove the a tag from your dropdown item, like below:
<div class="menu-bar">
<a href="instructiestest.html">
<div class="menu-item">Welkom</div>
</a>
<a href="instructie2.html">
<div class="menu-item">Aanmelden Portbase</div>
</a>
<a href="instructie3.html">
<div class="menu-item">De App</div>
</a>
<div class="dropdown">
<button class="dropbtn">
<div class="menu-item">Het team</div>
<div class="dropdown-content">
Google
Facebook
YouTube
</div>
</button>
</div>
</div>
Also, your .dropdown-content a:hover rule is missing a # in your background-color attribute:
.dropdown-content a:hover {
background-color: #234c95;
color: white;
}
Here is a working Fiddle
Something seems to have an extra margin or similar. Try to load the code, and check with the inspector. It'll show you the different spacing types in nice colours: https://developer.mozilla.org/en-US/docs/Tools/Page_Inspector/How_to/Examine_and_edit_the_box_model
In all honesty, you might be better re structuring this menu completely. I don't mean to be harsh but the code isn't structured well enough and is a little confusing to work with.
Ive just tweaked your code a little to make it easier to work with. I'm not exactly sure what it is your trying to achieve but here is something for you to take a look at:
CSS
#menu-bar {
position: fixed;
width: 100vw;
background-color: #134c95;
padding: 15px;
}
#menu-bar ul {
list-style: none;
padding: 0;
margin: 0;
font-size: 22px;
font-family:sans-serif;
}
#menu-bar ul li {
margin-bottom: 10px;
width: 100%;
}
#menu-bar ul li a {
display: block;
padding: 10px;
color: #fff;
text-decoration: none;
}
#menu-bar ul li a:hover {
color: #134c95;
background-color: #fff;
}
#menu-bar ul li ul {
display: none;
}
#menu-bar ul li:hover ul {
display: block;
}
HTML
<nav id="menu-bar">
<ul>
<li>Welkom</li>
<li>Aanmelden Portbase</li>
<li>De App</li>
<li class="">Het team
<ul>
Google
Facebook
YouTube
</ul>
</li>
</ul>
</nav>
As you can see this is much easier to understand and follow. The ID of the nav element is all you need to style the child elements.
Hope that helps as a starting point!