I am trying to create a Navbar in my react app and the Navbar's dropdown doesn't appear over everything like a normal Dropdown. Excuse my CSS, I've been fooling around with the position and the z-index for a while now so I'm sure there's some thing's in there that don't make any sense lol.
Whenever I try and and inspect the code on the chrome console, I can tell that the z-index should be placing them on top of the NavBar and the position is relative so, shouldn't that do it? Any help would be greatly appreciated!
I attached a photo of the problem below as well.
Here is my DropDown HTML:
<ul className="topnav" id="myTopnav">
<li>
<img src={logo} id="logo" />
</li>
<li>
Barbershop Apparel
</li>
<li>
Politics
</li>
<li>
Business
</li>
<li className="dropdown">
<a href="#">
Dropdown <i className="Dropdown-div"></i>
</a>
<div className="dropdown-content">
<a id="dropdown-items" href="#">
Link 1
</a>
<a id="dropdown-items" href="#">
Link 2
</a>
<a id="dropdown-items" href="#">
Link 3
</a>
</div>
</li>
<li>
Entertainment
</li>
<li>
More
</li>
<li>
<img
src={facebookLogo}
id="logoFacebook"
href="https://www.facebook.com/Barbershoptalk.posts"
/>
</li>
<li>
<img
src={instaLogo}
id="logoInsta"
href="https://www.instagram.com/thebarbershop.talk/"
/>
</li>
</ul>
Here is my CSS:
/* navbar */
#logo {
height: 90px;
width: auto;
padding-top: 5px;
padding-bottom: 5px;
}
#logoInsta {
height: 65px;
width: auto;
padding-top: 5px;
padding-bottom: 5px;
}
#logoFacebook {
height: 65px;
width: auto;
padding-top: 5px;
padding-bottom: 5px;
}
ul {
position: relative;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: #0062b2;
border-bottom: 2px solid #dd3333;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 30px 16px;
text-decoration: none;
font-family: "Titillium Web", sans-serif;
font-size: 20px;
position: relative;
z-index: 10;
}
/* Change the link color on hover */
li a:hover {
background-color: #dd3333;
color: white;
}
.dropdown-content {
display: none;
background-color: #dd3333;
width: 100%;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
padding: 12px 16px;
position: relative;
z-index: 10;
}
.dropdown:hover .dropdown-content {
display: block;
position: relative;
border: solid 1px white;
z-index: 10;
}
.dropdown-items:hover {
position: relative;
list-style-type: inside;
z-index: 10;
}
#media screen and (max-width: 600px) {
.topnav a:not(:first-child) {
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;
}
}
Picture of the problem
Yeah use position:absolute for your dropdown and try follow the DRY principle while coding
try setting the dropdown to position:absolute then it will stop pushing your nav down and lay on top of it
Related
I have an unordered linked list. I'm trying to shift one of the items in the navigation all the way to the right (Order) as if it had text-align: right;. I tried using float: right; and text-align: right;, but none of them seemed to work. If I set the margin-left to a really high number (such as 100px) it does shift to the right, but if I resize my window then I can't see it anymore or it's not on the right side of the page. Here is the HTML:
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
position: relative;
margin: 15px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
padding-left: 5em;
}
.navbar a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<div class="navigation-links-no-style">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li>
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
Any help would be greatly appreciated. Thanks!
Assuming you're looking to move your .order element, you'll want to apply the float: right rule to the parent (<li>) element. I've added a class to this, .order-container, to make this easier to achieve in the following example.
Note also that once you float to the right, it will be off the screen by default. You'll want to set a negative margin-right to circumvent this. I've gone with margin-right: -10em in the following, to match the offset from the image on the left.
Ultimately, you may wish to consider using a framework to achieve responsive design, ensuring that the offset is correct regardless of screen size.
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
position: relative;
margin: 15px;
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
li {
float: left;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
padding-left: 5em;
}
.navbar a {
float: left;
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
float: right;
}
.order-container {
float: right;
margin-right: 10em;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<div class="navigation-links-no-style">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li class="order-container">
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
MDN still advises that <div> is not a valid child of <ul>. Furthermore float adds a whole heap of side effects by removing the items from the natural flow of the document. To modernize this we can make use of display:flex
/*Normalise body*/
body {
margin:0;
}
/*Set flex on the nabar top position logo and links*/
.navbar {
display: flex;
}
/*Ad a maring to the logo link*/
.navbar > a:first-of-type {
margin-left: 5em;
}
nav {
position: fixed;
}
.navigation-links-no-style a {
text-decoration: none;
}
.navbar ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
width: 100%;
/*Ad flex to the nav link element*/
display: flex;
/*Vertically center the links*/
align-items:center;
}
/*Push the last element right but give it a little margin to the right*/
.navbar ul>li:last-of-type {
margin-left: auto;
margin-right:1em;
}
.navigation-links li {
padding-top: 1.3em;
}
.navbar {
overflow: hidden;
position: fixed;
top: 0;
width: 100%;
border-bottom: solid 1px black;
background: white;
}
.navbar a {
display: block;
text-align: center;
padding: 14px 16px;
text-decoration: none;
margin-left: 20px;
color: black;
font-size: 14pt;
}
.order {
color: #FFFFFF !important;
background: #1419e2;
text-decoration: none;
padding: 8px;
border-radius: 5px;
margin-top: 15px;
}
<div class="navbar">
<a class="glacier-hills" href="glacier_hills.html">
<img src="Images/Glacier-Hills-Logo.svg" alt="" width="182" height="90">
</a>
<ul class="navigation-links">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
<li>
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
You should use media queries for making navbar responsive.
a {
text-decoration: none;
color: black;
}
.navbar {
width: 100%;
overflow: hidden;
position: fixed;
top: 0;
display: flex;
justify-content: space-between;
border-bottom: solid 1px black;
}
.div-links {
display: flex;
align-items: center;
width: 70%;
}
.nav-links {
width: 100%;
display: flex;
justify-content: end;
align-items: center;
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
}
.nav-links li {
padding: 2rem;
}
.nav-items {
width: 30%;
display: flex;
justify-content: space-around;
}
.order {
overflow: hidden;
color: #ffffff !important;
background: #1419e2;
text-decoration: none;
padding: 0.8rem;
border-radius: 5px;
}
<div class="navbar">
<a href="glacier_hills.html">
<img
src="Images/Glacier-Hills-Logo.svg"
alt=""
width="182"
height="90"
/>
</a>
<div class="div-links">
<ul class="nav-links">
<div class="nav-items">
<li>
<a class="menu" href="menu.html">Menu</a>
</li>
<li>
<a class="location" href="location.html">Hours and Location</a>
</li>
</div>
<li class="btn">
<a class="order" href="order.html">Order</a>
</li>
</ul>
</div>
</div>
I have been working on a site and am wondering how I can center this dropdown,
My code as a code pen is codepen
here is the css
I have tried many things including changing the position tag to different values and adding in padding and other gaps
<nav class="navbar">
<div class="logo">
<a href=index.html>
<img src="Addy Schroeders.png" width="60px" height="60px">
</a>
</div>
<div class="menu">
<li>
<a href="/">
Home
</a>
</li>
<li>
<a href="/">
About
</a>
</li>
<li>
<a href="/">
help and resources
</a>
</li>
<li class="services">
<a href="/">
pages
</a>
<!-- DROPDOWN MENU -->
<ul class="dropdown">
<li>
<a href="template.html">
Dropdown 1
</a>
</li>
<li>
<a href="/">
Dropdown 2
</a>
</li>
<li>
<a href="/">
Dropdown 2
</a>
</li>
<li>
<a href="/">
Dropdown 3
</a>
</li>
<li>
<a href="/">
Dropdown 4
</a>
</li>
</ul>
<li>
<a href="/">
Contact
</a>
</li>
</div>
</ul>
</nav>
body {
font-family: opendyslexic, sans-serif;
text-align: center;
font-size: 24px;
line-height: 1.2;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
a {
text-decoration: none;
color: #f7abff /* pink */;
}
li {
list-style: none;
}
.navbar {
display: flex; /* stops the logo being on top of everything else */
align-items: center; /* centres them vertically */
justify-content: space-between; /* puts navbar at right */
padding: 20px; /* adds space at the top */
background-color: rgb(85, 96, 255)/* blue */; /* the background color */
}
.services {
position: relative;
float: right;
}
.dropdown {
background-color: #5560ff/* pink */; /* this makes the dropdown menu colored */
padding: 1em 0;
position: absolute;
display: none;
border-radius: 8px;
top: 30px;
padding-right: 20px;
padding-left: 20px;
}
.services:hover .dropdown {
display: block;
}
.image{
border-radius: 50%;
}
body {
font-family: opendyslexic, sans-serif;
text-align: center;
font-size: 24px;
line-height: 1.2;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
a {
text-decoration: none;
color: #f7abff /* pink */;
}
li {
list-style: none;
}
.navbar {
display: flex; /* stops the logo being on top of everything else */
align-items: center; /* centres them vertically */
justify-content: space-between; /* puts navbar at right */
padding: 20px; /* adds space at the top */
background-color: rgb(85, 96, 255)/* blue */; /* the background color */
}
.services {
position: relative;
float: right;
}
.dropdown {
background-color: #5560ff/* pink */; /* this makes the dropdown menu colored */
padding: 1em 0;
position: absolute;
display: none;
border-radius: 8px;
top: 30px;
padding-right: 20px;
padding-left: 20px;
}
.services:hover .dropdown {
display: block;
}
.image{
border-radius: 50%;
}
I have been looking up many other things and gone through heaps of questions but as a begginer I dont know what I need to do with the answers
If i can just have the CSS code and where it goes with a small description of what it does that will be greately appreciated
#amauryHanser gave me the answer
I added this
.dropdown {
left: -50%; }
it has fixed it and moves it left a bit, I can ajust the numbers until it works
.services {
position: relative;
}
.dropdown {
background-color: #5560ff/* pink */;
padding: 1em 0;
position: absolute;
border-radius: 8px;
top: 2rem;
padding-right: 20px;
padding-left: 20px;
left: 50%;
transform: translateX(-50%);
}
Try this :D
I am trying to create one link, Buying Tips, in my navigation menu as a drop down menu. I am running into a few problems and nothing I do seems to fix these issues.
For some reason when I scroll over Buying Tips, the first option of my drop down menu overlaps the navigation menu. I am not sure why this is happening and how to correct this.
I would like the drop down arrow to show but not sure how to code this in CSS.
I would like the navigation links to be equally spaced out and Buying Tips is all on one line. (please view image to see problem) I tried changing the width of the navbar and change the font sizes of navigation links but that does not help.
Printscreen of navigation issues on webpage
.navbar {
width: 100%;
background-color: black;
overflow: auto;
}
.navbar a {
float: left;
padding: 5px;
color: white;
text-align: center;
text-decoration: none;
font-size: 20px;
width: 24%;
}
.navbar a:hover {
color: #FFA500
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .BuyTip {
float: left;
color: white;
text-align: center;
text-decoration: none;
font-size: 20px;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 200px;
}
.dropdown-content a {
float: none;
color: black;
display: block;
text-align: left;
font-size: 10px;
}
.dropdown:hover .dropdown-content {
display: block;
}
#media screen and (max-width: 480px) {
.navbar a {
float: none;
display: block;
width: 100%;
}
}
<div class="navbar">
Chade's Bicycle Company
<div class="dropdown">
<a class="BuyTip">Buying Tips</a>
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Choosing The Correct Bike
Setting A Budget
Test-Ride Before Buying
Choosing The Correct Size
The Essential Accessories
</div>
</div>
Company Calendar
Contact Us
</div>
I've changed your code to achieve the desired result.
As for the questions you've asked:
Since you've made the element bearing the .dropdown class absolutely positioned it will stick to the top since it has no relative parent.
I've used a CSS border property to create an arrow. You can customize it as you wish. (even replace it with the caret class you've used originally, as long as you position it appropriately.)
You can control the spacing between the navigation links using CSS margin or padding properties. read-more about padding and margin.
.navbar {
width: 100%;
background-color: black;
overflow: auto;
font-size: 0;
}
.navbar li {
display: inline-block;
margin: 0 10px;
}
.navbar li a {
display: block;
padding: 5px;
color: white;
text-align: center;
text-decoration: none;
font-size: 20px;
}
.navbar a:hover {
color: #FFA500
}
.dropdown>a {
position: relative;
padding-right: 10px;
}
.dropdown>a:after {
content: "";
display: block;
border-width: 6px;
border-style: solid;
border-right: 6px solid transparent;
border-color: red transparent transparent;
width: 0;
height: 0;
position: absolute;
right: -14px;
top: 14px;
}
.dropdown-content {
display: none;
position: absolute;
padding: 10px 0;
}
.navbar li .dropdown-content a {
color: black;
display: block;
text-align: left;
font-size: 10px;
}
.dropdown:hover .dropdown-content {
display: block;
}
#media screen and (max-width: 800px) {
.navbar li a {
font-size: 16px;
}
.dropdown>a:after {
border-width: 5px;
border-right: 5px solid transparent;
right: -10px;
top: 12px;
}
}
<div class="navbar">
<ul>
<li>Chade's Bicycle Company</li>
<li class="dropdown">
<a>Buying Tips</a>
<div class="dropdown-content">
Choosing The Correct Bike
Setting A Budget
Test-Ride Before Buying
Choosing The Correct Size
The Essential Accessories
</div>
</li>
<li>Company Calendar</li>
<li>Contact Us </li>
</ul>
</div>
I am currently trying to make a (responsive) navigation bar, and while I have already troubleshooted with it a lot I can't find my way through it. :(
I have 2 issues at the moment.
1) In wide screen, I want to center the dropdown under its "button" title.
2) In smartphone/tablet screen, I want to make the dropdown, when appearing, push down the rest of the "button" titles and not covering them.
About 1, I have tried changing right and left attributes of the dropdown list but it justs sticks to the side of the screen no matter the changes I make to the position of dropdown list and parent element.
About 2, I have messed around with position but still I can't make it work as if it was static.
Ideally I would like to use just HTML and CSS.
Here is a demo: https://jsfiddle.net/SteliosKts/01o6cem5/10/
PS.I am sorry if it's a repost, it's just that I can't solve my prolbem although I have checked most of the relative threads
You need to:
remove position:absolute; from the .dropdownItem:hover .dropdownList.
change display: block; to display: inline-block; in .dropdownList.
remove max-height: 55px in li:nth-child(n + 2)
Add flex-basis: 30px; for mobile view.
html,
body {
font-size: 100%;
margin: 0px;
padding: 0px;
height: 100vh;
width: 100vw;
align-content: center;
text-align: center;
overflow-y: auto;
}
* {
box-sizing: border-box;
}
/*------------Top Header & Logo------------*/
#background_Header {
display: inline-block;
background-color: #9a999b;
width: 350px;
height: 100px;
}
#vertical_top_header_placeHolder {
float: left;
background-color: #9a999b;
width: 100%;
height: 45px;
position: absolute;
}
/*------------------------------------------*/
/*-------------------Navgiation Bar---------------*/
ul {
list-style-type: none;
display: flex;
justify-content: center;
/*border: 1px solid black;*/
padding-left: 0px;
}
li {
/* required for logo positioned in center */
flex-basis: 90px;
padding-top: 10px;
padding-right: 0px;
/*border: 1px solid black;*/
}
li a:hover {
background-color: #f1f1f1
}
li:first-child,
li:nth-child(n + 5) {
order: 3;
}
li:first-child {
flex-basis: auto;
z-index: 1;
}
li:nth-child(n + 2) {
padding-top: 65px;
}
li:nth-child(6) {
padding-top: 55px;
}
.dropdownItem:hover .dropdownList {
display: inline-block;
}
.dropdownButton {
display: inline-block;
text-align: center;
text-decoration: none;
color: black;
}
.dropdownList {
display: none;
position: relative;
background-color: #d6d6d6;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
}
.dropdownList a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
/*---------------------------------------------------*/
/*---------------Smartphone Header Style---------------*/
#media only screen and (max-width: 600px) {
li:first-child {
background-color: #9a999b;
}
li {
flex-basis: 30px;
}
#vertical_top_header_placeHolder {
display: none;
}
}
/*-----------------------------------------------------*/
/*---------------Vertical Navigation Style---------------*/
#media only screen and (max-width: 900px) {
ul {
flex-direction: column;
}
.dropdownItem {}
.dropdownButton {}
.dropdownList {
margin: 0 auto;
width: 100%;
}
li {
flex-basis: 30px;
}
li:first-child,
li:nth-child(n + 5) {
order: 0;
}
li:nth-child(n + 2) {
padding-top: 10px;
}
}
/*--------------------------------------------------------*/
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="http://fonts.googleapis.com/css?family=Open+Sans+Condensed:300,700&subset=latin,greek" rel="stylesheet" type="text/css" />
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600&subset=latin,greek-ext,greek" rel="stylesheet" type="text/css" />
</head>
<body>
<!--<div id="vertical_Conteiner">-->
<div id="vertical_top_header_placeHolder"></div>
<nav>
<ul>
<li>
<div id="background_Header">
</div>
</li>
<li class="dropdownItem">
<a class="dropdownButton" href="javascript:void(0)">
Team 1
</a>
<div class="dropdownList">
T1I1
T1I2
T1I3
T1I4
</div>
</li>
<li class="dropdownItem">
<a class="dropdownButton" href="javascript:void(0)">
Team 2
</a>
<div class="dropdownList">
T2I1
T2I2
T2I3
T2I4
T2I5
</div>
</li>
<li class="dropdownItem">
<a class="dropdownButton" href="javascript:void(0)">
Team 3
</a>
<div class="dropdownList">
T3I1
T3I2
T3I3
T3I4
</div>
</li>
<li class="dropdownItem">
<a class="dropdownButton" href="javascript:void(0)">
Team 4
</a>
<div class="dropdownList">
T4I1
T4I2
</div>
</li>
<li class="dropdownItem">
<a class="dropdownButton" href="javascript:void(0)">
Team 5 BigWord
</a>
<div class="dropdownList">
T5I1
T5I2
</div>
</li>
<li class="dropdownItem">
<a class="dropdownButton" href="javascript:void(0)">
Team 6
</a>
<div class="dropdownList">
T6I1
Team6_BigItem2
T6I3
T6I4
T6I5
</div>
</li>
</ul>
</nav>
<article>
<div>
</div>
</article>
</body>
</html>
Just remove the absolute from here and you will see the dropdown list in large screen some below your button and in small screen too it will come below the button:
.dropdownItem:hover .dropdownList {display: block;/* position: absolute; */}
I have the following Html file, together with the CSS file. When I hover over the Main Navigation bar to open the drop-down menu, the parent width enlarges together with the drop-down menu. How can I fix this? If I set position: absolute to the dropdown menu, it will not work at all.(hovering doesn't trigger the dropdown). I have put my code here: https://jsfiddle.net/L67oxmqc/2/ .
Thank you!
Code:
body {
background-image: url("background.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
h1 {
color: navy;
margin-left: 20px;
}
/* SECTION WITH THE heading text */
#boldtext {
color: Black;
border-radius: 15px;
background: #a9bcba;
padding: 10px;
width: 200px;
height: 50px;
}
/* SECTION WITH BILL GATES QUOTE */
#quotetext {
color: Black;
font-size: 18px;
border-radius: 15px;
padding: 30px;
width: 400px;
height: 150px;
}
div.quote {
position: absolute;
bottom: 5px;
right: 50px;
width: 30px;
/* border: 2px solid rgb(150,245,255);
opacity: 0.8;*/
}
/* SECTION WITH THE MENU FOR THE MAIN PAGE */
div.menu ul {
border-radius: 05px;
position: relative;
list-style-type: none;
margin: 0px;
padding: 0px;
overflow: hidden;
background-color: #a9bcba;
/*z-index: -1; */
}
div.menu li {
float: left;
}
div.menu li a {
display: inline-block;
text-align: center;
margin: 0px;
padding: 10px 10px;
color: white;
}
div.menu li a:hover {
background-color: #879694;
color: blue;
}
/* SECTION WITH THE DROPDOWN CONTENT FOR THE MENU */
.dropdowncontent a:hover {
background-color: #cbd6d5
}
.dropdown:hover .dropdowncontent {
display: block;
}
div.dropdowncontent {
display: none;
/* position: absolute; */
background-color: #a9bcba;
width: 115px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
div.dropdowncontent a {
color: red;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: right;
overflow: auto;
}
<br>
<!-- Header -->
<b id="boldtext">Welcome</b>
<br>
<br>
<br>
<!-- Menu bar-->
<div class="menu">
<ul>
<li class="dropdown">Boeing Family
<div class="dropdowncontent">
Boeing 737 class
Boeing 747 class
Boeing 787 class
</div>
</li>
<li>Airbus Family
</li>
<li>Others
</li>
<li style="float:right">Contact
</li>
<!-- The Contact button is set to be on the right side of the Navigation bar-->
</ul>
</div>
<div class="quote" id="quotetext">
<p><q><cite>A generic quote.</q>
</cite>
— Author.</p>
</div>
<!-- Boeing planes image that triggers the Boeing menu-->
<a href="Boeing.htm" </a>
<img src="Boeing-777-Generic-Nice.jpg" alt="Boeing picture" style="width:350px;height:150px;">
<!-- Airbus planes image that triggers the Airbus menu-->
<a href="Airbus.htm" </a>
<img src="A320-generic.jpg" alt="Airbus picture" style="width:350px;height:150px;">
<!-- ATR planes image that triggers the ATR menu-->
<a href="https://en.wikipedia.org/wiki/ATR_(aircraft_manufacturer)" </a>
<img src="ATR_generic.jpg" alt="Airbus picture" style="width:350px;height:150px;">
<!-- Link to the Frequently asked questions page-->
<a href=#>
<img src="question.jpg" alt="question image" style="width:350px;height:150px;">
</a>
<br>
<br>
Just update in your style may it works for you
div.menu ul {
background-color: #a9bcba;
border-radius: 5px;
float: left;
list-style-type: none;
margin: 0;
padding: 0;
position: relative;
width: 100%;
}
div.dropdowncontent {
background-color: #a9bcba;
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
display: none;
position: absolute;
width: 115px;
}
Here is a JSFiddle of the solution I mention below: https://jsfiddle.net/2sy0dn6w/
Fixing your solution is incredibly simple. You want to use position: absolute; for your div.dropdowncontent CSS class. You also want to make your parent li tag have position: relative; to keep your div.dropdowncontent constrained within the parent li. And then you have an issue with your primary ul tag with using overflow: hidden. This would prevent your dropdown from being seen. And I understand why you are using overflow: hidden; - you're using it as a clearfix. But in this case, it is a problem because it hides your dropdown. So instead we would want to use :before with the ul for the clearfix. The steps for applying the fixes are below.
First, remove overflow: hidden; from your css for div.menu ul {}. This will create the following:
div.menu ul {
border-radius: 05px;
position: relative;
list-style-type: none;
margin: 0px;
padding: 0px;
/* overflow: hidden; */
background-color: #a9bcba;
/*z-index: -1; */
}
Next, right after the div.menu ul {} CSS, add:
div.menu > ul::after {
clear: both;
display: table;
content: ' ';
overflow: hidden;
}
Lastly, at the very bottom of your CSS, add the following (you can even move each of the below to their designated declarations you already have in your CSS. The reason I'm adding this separate is so that it's more obvious what I included to give you the outcome you're looking for):
div.menu > ul > li {
position: relative;
}
.dropdowncontent {
position: absolute;
top: 100%;
}
li.dropdown:hover div.dropdowncontent {
display: block;
}
You have to use position absolute, you cant see it working because ul has overflow:hidden;
add this css :
.menu ul{
overflow:visible;
}
.menu ul li.dropdown{
position : relative;
}
.menu ul li.dropdown .dropdowncontent{
position : absolute;
top:38px;
left:0;
}
try this in your css:
add .menu class and remove bg-color from ul
.menu {
background-color: #a9bcba;
height: 45px;
}
div.menu ul {
border-radius: 05px;
position: relative;
list-style-type: none;
margin: 0px;
padding: 0px;
overflow: hidden;
//background-color: #a9bcba; <--- remove background
/*z-index: -1; */
}
Try this code below
Remove overflow hidden
div.menu ul{
...
overflow: hidden;
}
Add position absolute
div.dropdowncontent {
...
position: absolute;
}
replace float left
div.menu li{
/* float: left; */
display: inline-block;
}
body {
background-image: url("background.jpg");
background-repeat: no-repeat;
background-attachment: fixed;
background-size: cover;
}
h1 {
color: navy;
margin-left: 20px;
}
/* SECTION WITH THE heading text */
#boldtext {
color: Black;
border-radius: 15px;
background: #a9bcba;
padding: 10px;
width: 200px;
height: 50px;
}
/* SECTION WITH BILL GATES QUOTE */
#quotetext {
color: Black;
font-size: 18px;
border-radius: 15px;
padding: 30px;
width: 400px;
height: 150px;
}
div.quote {
position: absolute;
bottom: 5px;
right: 50px;
width: 30px;
/* border: 2px solid rgb(150,245,255);
opacity: 0.8;*/
}
/* SECTION WITH THE MENU FOR THE MAIN PAGE */
div.menu ul {
border-radius: 05px;
position: relative;
list-style-type: none;
margin: 0px;
padding: 0px;
background-color: #a9bcba;
/*z-index: -1; */
}
div.menu li {
display: inline-block;
}
div.menu li a {
display: inline-block;
text-align: center;
margin: 0px;
padding: 10px 10px;
color: white;
}
div.menu li a:hover {
background-color: #879694;
color: blue;
}
/* SECTION WITH THE DROPDOWN CONTENT FOR THE MENU */
.dropdowncontent a:hover {
background-color: #cbd6d5
}
.dropdown:hover .dropdowncontent {
display: block;
}
div.dropdowncontent {
display: none;
position: absolute;
background-color: #a9bcba;
width: 115px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
}
div.dropdowncontent a {
color: red;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: right;
overflow: auto;
}
<br>
<!-- Header -->
<b id="boldtext">Welcome</b>
<br>
<br>
<br>
<!-- Menu bar-->
<div class="menu">
<ul>
<li class="dropdown">Boeing Family
<div class="dropdowncontent">
Boeing 737 class
Boeing 747 class
Boeing 787 class
</div>
</li>
<li>Airbus Family
</li>
<li>Others
</li>
<li style="float:right">Contact
</li>
<!-- The Contact button is set to be on the right side of the Navigation bar-->
</ul>
</div>
<div class="quote" id="quotetext">
<p><q><cite>A generic quote.</q>
</cite>
— Author.</p>
</div>
<!-- Boeing planes image that triggers the Boeing menu-->
<a href="Boeing.htm" </a>
<img src="Boeing-777-Generic-Nice.jpg" alt="Boeing picture" style="width:350px;height:150px;">
<!-- Airbus planes image that triggers the Airbus menu-->
<a href="Airbus.htm" </a>
<img src="A320-generic.jpg" alt="Airbus picture" style="width:350px;height:150px;">
<!-- ATR planes image that triggers the ATR menu-->
<a href="https://en.wikipedia.org/wiki/ATR_(aircraft_manufacturer)" </a>
<img src="ATR_generic.jpg" alt="Airbus picture" style="width:350px;height:150px;">
<!-- Link to the Frequently asked questions page-->
<a href=#>
<img src="question.jpg" alt="question image" style="width:350px;height:150px;">
</a>
<br>
<br>