I have a site I'm building which has a few dropdown menus. I'm sure this isn't being done in the most efficient way, but I'm curious why this is happening. I have the exact same CSS code for these dropdowns but one of them is nested under the main navigation and the other one is under a mobile menu (so like everything would be one under button).
The code works somewhat because when I've changed the display to be anything but none, the styling works fine and everything.. but for some reason, I just can't find out why the mobile menu dropdown isn't working but the main navbar one is.
Here's the code for the main nav bar dropdown:
#menu .dropdown {
top: -1px;
position: relative;
display: inline-block;
z-index: 9999;
margin-left: -6px;
margin-right: -7px;
}
#menu .dropbtn {
background-color: transparent;
color: white;
border: none;
font-family: 'chivolight';
font-size: 1em;
font-weight: 600;
letter-spacing: 1px;
}
#menu .dropdown-content {
display: none;
position: absolute;
background-color: transparent;
min-width: 10em;
box-shadow: relative rgba(0, 0, 0, 0.2);
margin-top: -0.2em;
margin-left: 0.35em;
top: 2.8em;
z-index: 99;
}
#menu .dropdown-content a {
background: white;
padding: 0.4em 1em;
text-decoration: none;
display: block;
}
#menu .dropdown-content a:hover {
background-color: #ddd;
}
#menu .dropdown:hover .dropdown-content {
display: block;
}
#menu .dropdown:hover .dropbtn {
background-color: transparent;
}
```
<div id="menu" class="chivolight">
<ul>
<li>
<div class="dropdown">
<button class="dropbtn">About Us</button>
<div class="dropdown-content">
Capabilties
Certifications
History
Quality
</div>
</div>
</li>
</ul>
</div>
And the code for the mobile menu dropdown:
#menuicon .icon-dropbtn {
background-color: white;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
#menuicon .icon-dropdown {
position: relative;
display: inline-block;
}
#menuicon .icon-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;
right: 0;
}
#menuicon .icon-dropbtn:hover {
opacity: 0.8;
transition: 0.3s;
}
#menuicon .icon-dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
#menuicon .icon-dropdown-content a:hover {
background-color: #f1f1f1
}
#menuicon .icon-dropbtn:hover .icon-dropdown-content {
display: block;
}
#menuicon .icon-dropdown:hover .icon-dropbtn {
background-color: #3e8e41;
}
<div id="menuicon">
<div class="icon-dropdown">
<button class="icon-dropbtn" style="font-size: 0.8em;"><font color=black><i class="fa fa-bars"></i></font></button>
<div class="icon-dropdown-content">
Link 1
Link 1
Link 1
</div>
</div>
</div>
You have a misnamed hover selector in the mobile css:
#menuicon .icon-dropbtn:hover .icon-dropdown-content {
display: block;
}
should read:
#menuicon .icon-dropdown:hover .icon-dropdown-content {
display: block;
}
Select the mobile display classes:
#menuicon .icon-dropdown .icon-dropbtn{
//CSS for mobile display
}
or
Add same class to both buttons:
Like
Main:
<div id="menu" class="chivolight">
<ul>
<li>
<div class="dropdown">
<button class="dropbtn someclass">About Us</button>
<div class="dropdown-content">
Capabilties
Certifications
History
Quality
</div>
</div>
</li>
</ul>
</div>
Mobile:
<div id="menuicon">
<div class="icon-dropdown">
<button class="icon-dropbtn someclass" style="font-size: 0.8em;"><font
color=black>
<i class="fa fa-bars"></i></font></button>
<div class="icon-dropdown-content">
Link 1
Link 1
Link 1
</div>
</div>
</div>
Now use CSS for the given class:
.someclass{
//Now both buttons have same class
//Add CSS
}
Related
Have a fairly simple menu bar (with hover drop downs) that works fine. See Code below.
<!DOCTYPE html>
<html>
<head>
<style>
html, body {
font-family: Arial, Helvetica, sans-serif;
width: 100%;
height: 100%;
margin: 0px;
}
.text-outline {
color: #ffffff;
font-size: larger;
text-shadow: -1px -1px 0 #663333, 1px -1px 0 #663333, -1px 1px 0 #663333, 1px 1px 0 #663333;
}
#div_menu_main {
position: absolute;
left:0px;
top:135px;
width:1200px;
overflow: visible;
height:26px;
background-color: #996633;
z-index:-1;
}
.navbar {
position: absolute;
left:0px;
top:135px;
width:1200px;
overflow: visible;
height:26px;
z-index:10;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
font-weight: bold;
text-align: center;
padding: 4px 10px;
text-decoration: none;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: #663333;
}
/*
#div_menu_main_overlay {
position: absolute;
left:0px;
top:135px;
width:1200px;
overflow: visible;
height:26px;
z-index:10;
}
#div_menu_main_overlay a {
float: left;
font-size: 16px;
color: white;
font-weight: bold;
text-align: center;
padding: 4px 10px;
text-decoration: none;
}
#div_menu_main_overlay a:hover, .dropdown:hover .dropbtn {
background-color: #663333;
}
*/
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border:none;
outline: none;
color: white;
font-weight: bold;
padding: 4px 10px;
background-color: inherit;
font-family: inherit;
margin-left:5px;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #996633;
min-width: 130px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
margin-left:5px;
}
.dropdown-content a {
float: none;
color: white;
padding: 4px 10px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #663333;
}
.dropdown:hover .dropdown-content {
display: block;
}
</style>
<title>Untitled</title>
</head>
<body>
<div id="div_menu_main"></div>
<div class="navbar text-outline"><!--textonly-->
<!--<div id="div_menu_main_overlay" class="text-outline"><!--textonly-->
HOME
CREATE POST
<div class="dropdown"><button class="dropbtn text-outline">REVISE POST<i class="fa fa-caret-down"></i></button>
<div class="dropdown-content">
LOST PASSWORD
REVISE POST
REVISE POST2
REVISE POST3
</div>
</div>
SEARCH
<div class="dropdown">
<button class="dropbtn text-outline">DONATIONS<i class="fa fa-caret-down"></i></button>
<div class="dropdown-content">
DONATORS
</div>
</div>
<div class="dropdown">
<button class="dropbtn text-outline">HELP<i class="fa fa-caret-down"></i></button>
<div class="dropdown-content">
FAQs
GUIDELINES
LOST PASSWORD
</div>
</div>
NEWS
<div class="dropdown">
<button class="dropbtn text-outline">ABOUT<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
FRIENDS
SITE TRAFFIC
ADVERTISING
WHY?
ABOUT
CONTACT MIA
</div>
</div>
</div>
</body>
</html>
Normally one div would be used for the background and the menu items, however, I have to weave around some graphics so the "menu bar" is in the < div id="div_menu_main" > and the menu items and dropdowns are in the < div class="navbar text-outline" >. All works fine ... dropdowns behave as expected, ie stacked.
However, am integrating this into a larger project where there is already an extensively used "navbar" class, and given there is only one main menu, decided to use < div id=div_menu_main_overlay class="text-outline" > ...basically changing class=navbar for id=div_menu_main_overlay. Converted the .navbar references over to #div_menu_main_overlay ... and then it happens. NOTE: For ease I have both flavors of CSS code in the example, just commenting out the version not being tested.
The unexpected behavior is the dropdown content are now acting as if the anchor element is float: left; vs none;. Played around with several possibilities and even though all I have to do is change the class name to something over than .navbar, this subtlety has piqued my interest on what is the problem.
I need to create menu like shown in this screenshot:
So as you can, the cursor hover opens large sub menu with two sub sections. Will be glad for any similar examples to my issues. Thanks for your answers!
Here is a very simple example to get you started. It needs more styling of course and more content, but this should give you all the tools to have a dropdown on hover in your menu
HTML:
<header>
<a href="/url">
Hover to see dropdown
</a>
<div>
<section></section>
<section></section>
</div>
</header>
CSS:
header {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 50px;
}
header > a {
padding: 0 2em;
height: 50px;
display: grid;
place-content: center;
}
header > div {
display: hidden;
background-color: white;
}
a:hover + div {
display: inherit;
}
Something like this should work. It utilizes the :hover attribute in the navbar tab 'Dropdown' to reveal more content (in this case it'll be just some links).
HTML:
<div class="navbar">
<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>
</div>
CSS:
.navbar {
overflow: hidden;
background-color: #333;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 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;
}
You can find more information on the W3School website for more!
I want to make all buttons in my navigation bar styled using percentages. This is so that it'll look the same in different resolutions. However, for some reason, when I apply the percentages to the same button, some of them provide a different result and looks smaller. I am extremely confused and really need help as it's my ICT project.
I've attempted to make the all the paddings the same percentage, and everything of the sort
HTML:
.topnav{
overflow: hidden;
background-color: #333;
font-family: courier new;
width: 100%;
max-height:100px;
}
.topnav a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 3% 2%;
text-decoration: none;
display: flex;
margin: auto;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
background-color: inherit;
font-family: inherit;
margin: auto;
}
.dropdown a {
padding: 3% 2%;
}
.topnav a:hover, .dropdown:hover .dropbtn {
background-color: #1A93EE;
}
.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;
}
<div class="topnav">
<div class="dropdown">
<button class="dropbtn">About MUN
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
What is MUN?
The STCMUN Team
MUN Procedures
</div>
</div>
<div class="dropdown">
<button class="dropbtn">The UN
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
What is the UN?
The UN Sustainable Goals
</div>
</div>
Current Events
International Affairs
Others
Contact Us
</div>
</div>
</div>
</div>
</div>
I want all the buttons to be of the same size and styled using percentages. I also want the navigation bar to only be one text line in height. Please help!
The most appropriate way to approach responsiveness is leveraging on the power of media queries. Through this approach, you could resize your navigation bar to look exactly as you want it to look like across different screens. Learn more about media queries on MDN
Tip
You could hide the content on the nav bar on small screens and introduce sidebar which should be togglable.
body,html {
margin: 0px;
padding: 0px;
}
.topnav{
overflow: hidden;
background-color: #333;
font-family: courier new;
width: 100%;
max-height:100px;
padding: 3% 2%;
}
.topnav a {
float: left;
font-size: 16px;
color: white;
text-align: center;
text-decoration: none;
display: flex;
margin: auto;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
background-color: inherit;
font-family: inherit;
margin: auto;
}
.dropdown a {
padding: 3% 2%;
}
.topnav a:hover, .dropdown:hover .dropbtn {
background-color: #1A93EE;
}
.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;
}
<body>
<div class="topnav">
<div class="dropdown">
<button class="dropbtn">About MUN
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
What is MUN?
The STCMUN Team
MUN Procedures
</div>
</div>
<div class="dropdown">
<button class="dropbtn">The UN
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
What is the UN?
The UN Sustainable Goals
</div>
</div>
Current Events
International Affairs
Others
Contact Us
</div>
</div>
</div>
</div>
</div>
</body>
is it? if not, please draw the expected behavior so that I can better understand what you want
I am trying to have a drop down menu while having a reptile image as the background, but I can't seem to have the drop down menu working with the image in it? When I take the image out, it works. I'm not sure if it's just because of the that are being mixed up, or maybe it's a typing error, but I've looked and can't find any?
Another question is why my background color gradient (the gradient not reptile.png background one) is only showing only half the page. If you make the window smaller, it shows white and doesn't look good. I've tried using width/height : 100% 100%, cover, and tried stretching the image as height but it's not working. I would like to have the image stretch to the height and width of the page. I think it may be due to something about the body height, but I am not sure how to change that.
Here is the code
header {
text-align: right;
text-shadow: none;
background-color: #a7a7a7;
}
body {
background-image: linear-gradient(#545454, #000000);
background-size: 100% 100%;
background-repeat: no-repeat;
font-family: Gill Sans, "sans-serif";
color: #f2fdec;
font-size: 3em;
text-shadow: 2px 2px 2px #000000;
padding: 0.2em;
}
img {
max-width: 100%;
max-height: 100%;
height: auto;
opacity: 0.5;
}
h3 {
font-size: 18px;
font-family:
}
nav {
font-weight: bold;
float: right;
color: #c1c1c1;
font-size: 18px;
padding: 8px 8px 8px 8px;
}
nav a:link {
color: #f3ffe7;
text-decoration: none;
}
nav a:visited {
color: #f3ffe7;
text-decoration: none;
}
nav a:hover {
color: #f3ffe7;
text-decoration: none;
}
nav ul {
list-style-type: none;
}
nav a {
text-decoration: none;
}
nav ul ul {
position: absolute;
background-color: #474747;
padding: 0;
text-align: center;
display: none;
}
nav ul ul li {
border: 1px solid #00005D;
display: block;
width: 4em;
padding-left: 1em;
margin-left: 0;
}
nav li:hover ul {
display: block;
}
footer {
font-size: 10px;
text-align: center;
background-color: #474747;
padding: 8px;
text-shadow: none;
color: #d2d2d2;
position: absolute;
left: 0;
width: 100%;
bottom: 0;
}
#wrapper {
width: 100%;
height: 100%;
}
header,
nav,
footer {
display: block;
}
.container {
position: relative;
text-align: center;
color: white;
}
.herp {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #4f4f4f;
min-width: 160px;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #696969;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3f5840;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Reptile Website</title>
<link rel="stylesheet" href="home.css">
<meta charset="utf-8">
</head>
<body>
<div id="wrapper">
<header><nav><ul>
<div class="dropdown">
<button class="dropbtn">Home</button>
</div>
<div class="dropdown">
<button class="dropbtn">Lizards</button>
<div class="dropdown-content">
Geckos
Chameleons
Skinks
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Big Lizards</button>
<div class="dropdown-content">
Iguanas
Tegus
Monitors
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Turtles</button>
<div class="dropdown-content">
Turtles
Tortoises
Terrapins
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Snakes</button>
<div class="dropdown-content">
Colubrids
Pythons
Constrictors
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Ambibians</button>
<div class="dropdown-content">
Newts
Salamanders
Frogs and Toads
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Expertise</button>
<div class="dropdown-content">
Beginner
Intermediate
Complex
</div>
</ul></nav></header>
<div class="container">
<img src="reptile.png" alt="Reptile Background">
<div class="herp">Explore Herping<br>
<h3>Your home for Herpetology Information</h3> .
</div>
</div>
<footer>
<p>Sasha Batz | s1467218#student.mcckc.edu</p>
</footer>
</div>
</body>
</html>
First Question:
That image make its parent element .container cover the dropdown menu, so you cannot hover the dropdown menu.
You can use z-index to put it on the top:
.container {
z-index: 10;
}
.container img {
z-index: 11;
}
nav {
z-index: 1001;
}
And don't make the text Your home for Herpetology Information at the top of menu.
Second Question:
In specific, all percentage-based sizes must inherit from parent block elements, and if any of those ancestors fail to specify a size, they are assumed to be sized at 0 x 0 pixels.
So you need to add this to your css code:
html {
height: 100%;
width: 100%;
}
body {
width: 100%;
height: 100%;
}
html {
height: 100%;
}
header {
text-align : right;
text-shadow : none;
background-color : #a7a7a7;
}
body {
background-image : linear-gradient(#545454, #000000);
background-size : 100% 100%;
background-repeat : no-repeat;
font-family : Gill Sans, "sans-serif";
color : #f2fdec;
font-size : 3em;
text-shadow : 2px 2px 2px #000000;
padding: 0.2em;
height: 100%;
}
.container {
z-index: 10;
}
.container img {
z-index: 11;
}
.container .herp {
z-index: 11;
}
.container .herp h3{
z-index: 12;
}
nav {
z-index: 1001;
}
img {
max-width: 100%;
max-height : 100%;
height: auto;
opacity : 0.5;
}
h3 {
font-size : 18px;
font-family :
}
nav {
font-weight : bold;
float : right;
color : #c1c1c1;
font-size : 18px;
padding : 8px 8px 8px 8px;
}
nav a:link {
color : #f3ffe7;
text-decoration : none;
}
nav a:visited {
color : #f3ffe7;
text-decoration : none;
}
nav a:hover {
color : #f3ffe7;
text-decoration : none;
}
nav ul {
list-style-type : none;
}
nav a {
text-decoration : none;
}
nav ul ul {
position : absolute;
background-color : #474747;
padding : 0;
text-align : center;
display : none;
}
nav ul ul li {
border : 1px solid #00005D;
display : block ;
width : 4em;
padding-left : 1em;
margin-left : 0;
}
nav li:hover ul {
display : block;
}
footer {
font-size : 10px;
text-align: center;
background-color: #474747;
padding : 8px;
text-shadow : none;
color : #d2d2d2;
position : absolute;
left : 0;
width : 100%;
bottom : 0;
}
#wrapper {
width: 100%;
height : 100%;
}
header, nav, footer {
display : block;
}
.container {
position: relative;
text-align: center;
color: white;
}
.herp {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 16px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown {
position: relative;
display: inline-block;
z-index: 1005;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #4f4f4f;
min-width: 160px;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #696969;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3f5840;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Reptile Website</title>
<link rel="stylesheet" href="a.css">
<meta charset="utf-8">
</head>
<body>
<div id="wrapper">
<header><nav><ul>
<div class="dropdown">
<button class="dropbtn">Home</button> |
</div>
<div class="dropdown">
<button class="dropbtn">Lizards</button> |
<div class="dropdown-content">
Geckos
Chameleons
Skinks
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Big Lizards</button> |
<div class="dropdown-content">
Iguanas
Tegus
Monitors
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Turtles</button> |
<div class="dropdown-content">
Turtles
Tortoises
Terrapins
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Snakes</button> |
<div class="dropdown-content">
Colubrids
Pythons
Constrictors
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Ambibians</button> |
<div class="dropdown-content">
Newts
Salamanders
Frogs and Toads
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Expertise</button> |
<div class="dropdown-content">
Beginner
Intermediate
Complex
</div>
</div>
<div class="dropdown">
<button class="dropbtn">Care</button>
<div class="dropdown-content">
Leopard Gecko
Bearded Dragon
Kenyan Sand Boa
</div>
</div>
</ul></nav></header>
<div class="container">
<img src="reptile.png" alt="Reptile Background"/>
<!-- <div class="herp">Explore Herping<br>
<h3>Your home for Herpetology Information</h3></div> -->
</div>
<footer>
<p>footer</p>
</footer>
</div>
</body>
</html>
What is wrong with the code I wrote? Below is the snippet.
html {
background-image: url(back.png)
}
#main {
text-align: center;
}
#visible {
display: inline-block;
background-color: #000c21;
width: 80%;
color: #c4c5c6;
font-family: sans-serif;
font-size:20;
}
html,body,#main,#visible { height:100%; }
.topnav {
overflow: hidden;
background-color: #182b3a;
position: fixed;
top: 0;
width: 100%;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover,.dropdown:hover .dropbtn {
background-color: #1a3c56;
color: white;
}
.topnav a.active {
background-color: #1a3c56;
color: white;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #182b3a;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown:hover .dropdown-content {
display: block;
}
<html>
<head>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="topnav">
<a class="active" href="#home">Home</a>
News
Contact
About
herpiderp
<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 id=main>
<div id=visible>
herpiderp
</div>
</div>
</body>
</html>
My drop-down element steals my main div, why is that?
I need it to be a proper drop-down element, but if I find a way around it, I will never know why this occurs in the first place.
I am making a website for robotics and want to make a drop-down menu, but I am getting this weird effect. Can anyone help me?
Is it me or do you hav an open div here ? I think you forgot to close a div. Try this
<div class="topnav">
<a class="active" href="#home">Home</a>
News
Contact
About
herpiderp
<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>
</div>
<div id="main">
<div id="visible">
herpiderp
</div>
</div>
Also as #Romel Indemne suggested u missed double quotes.
Remove the overflow: hidden; attribute in your .topnav class
html {
background-image: url(back.png)
}
#main {
text-align: center;
}
#visible {
display: inline-block;
background-color: #000c21;
width: 80%;
color: #c4c5c6;
font-family: sans-serif;
font-size: 20;
}
html,
body {
min-height: 100vh;
}
#main,
#visible {
height: 100%;
}
.topnav {
background-color: #182b3a;
position: fixed;
top: 0;
width: 100%;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover,
.dropdown:hover .dropbtn {
background-color: #1a3c56;
color: white;
}
.topnav a.active {
background-color: #1a3c56;
color: white;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #182b3a;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 3;
}
.dropdown {
float: left;
position: relative;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font-family: inherit;
margin: 0;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="topnav">
<a class="active" href="#home">Home</a>
News
Contact
About
herpiderp
<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 id="main">
<div id="visible">
herpiderp
</div>
</div>
</div>
</div>