Hover menu problems after moving main menu - html

#header {
height: 108px;
width: 1140px;
background-color: #faa220;
position: relative;
}
#Logo2 {
height: 108px;
float: left;
}
#header links {
height: 50px;
float: left;
list-style: none;
padding-top: 10px;
}
#container {
overflow: hidden;
background-color: #faa220;
font-family: Arial, Helvetica, sans-serif;
position: absolute;
bottom: 0;
right: 215px;
}
.container a {
float: left;
font-size: 18px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
position: absolute;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 18px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
cursor: pointer;
}
.container a:hover, .dropdown:hover .dropbtn {
background-color: #faa220;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #faa220;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
position: absolute;
}
.dropdown-content a {
float: none;
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
position: absolute;
bottom: 0;
}
.dropdown-content a:hover {
background-color: #faa220;
position: absolute;
bottom: 0;
}
.dropdown:hover .dropdown-content {
position: absolute;
display: block;
bottom: 0;
}
<div id="header">
<img src="../JPEG/i2i logo 2.jpg" align="left" id="Logo2" />
<div id="container">
<div class="dropdown">
<button class="dropbtn">Home</button>
</div><!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">About Us</button>
<div class="dropdown-content">
Bio
News
Partners
</div><!--dropdown-content close div-->
</div><!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">Awards/Certifications</button>
</div>
<div class="dropdown">
<button class="dropbtn">Services</button>
<div class="dropdown-content">
Solar
Water
Housing
Training
Broadband
</div><!--dropdown-content close div-->
</div><!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">How You Can Help</button>
<div class="dropdown-content">
Donate
Volunteer
Intern
</div><!--dropdown-content close div-->
</div><!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">Contact</button>
<div class="dropdown-content">
Email
FAQS
Newsletter
</div><!--dropdown-content-->
</div><!--dropdown close div-->
</div><!--container close div-->
I'm having problems with a hover menu after I moved the main menu. The div it's in is bigger than the menu div because of a logo. When I first coded the menu it was at the top of the div and the hover menu showed fine.
I moved the menu div to the bottom of the parent div using position absolute and relative, setting the bottom to 0 and right 215px. After that the hover menu started overlapping on the main menu. Any help is appreciated.

In order to make the Logo adapt to headers height:
#logo2 {
display: block;
width: auto;
height: auto;
max-height: 108px;
}
You have set the menu container to an absolute position, I had make it inline, so it does not stays over the logo:
- So remove the position: absolute; from the #container, and add following: line-height: 108px;, to center the menu vertically.
In order to make the logo slightly smaller than the header itself, at same time centering it, I've added following to the #logo:
max-height: 70px;
margin: 19px 10px 19px 10px;
#header {
height: 108px;
width: 1140px;
background-color: #faa220;
position: relative;
}
#Logo2 {
float: left;
display: block;
width: auto;
height: auto;
max-height: 70px;
margin: 19px 10px 19px 10px;
}
#header links {
height: 50px;
float: left;
list-style: none;
padding-top: 10px;
}
#container {
overflow: hidden;
background-color: #faa220;
font-family: Arial, Helvetica, sans-serif;
bottom: 0;
right: 215px;
line-height: 108px;
}
.container a {
float: left;
font-size: 18px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
position: absolute;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 18px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
cursor: pointer;
}
.container a:hover,
.dropdown:hover .dropbtn {
background-color: #faa220;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #faa220;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
z-index: 1;
position: absolute;
}
.dropdown-content a {
float: none;
color: white;
padding: 12px 16px;
text-decoration: none;
display: block;
text-align: left;
position: absolute;
bottom: 0;
}
.dropdown-content a:hover {
background-color: #faa220;
position: absolute;
bottom: 0;
}
.dropdown:hover .dropdown-content {
position: absolute;
display: block;
bottom: 0;
}
<div id="header">
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/ce/Coca-Cola_logo.svg/1200px-Coca-Cola_logo.svg.png" align="left" id="Logo2" />
<div id="container">
<div class="dropdown">
<button class="dropbtn">Home</button>
</div>
<!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">About Us</button>
<div class="dropdown-content">
Bio
News
Partners
</div>
<!--dropdown-content close div-->
</div>
<!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">Awards/Certifications</button>
</div>
<div class="dropdown">
<button class="dropbtn">Services</button>
<div class="dropdown-content">
Solar
Water
Housing
Training
Broadband
</div>
<!--dropdown-content close div-->
</div>
<!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">How You Can Help</button>
<div class="dropdown-content">
Donate
Volunteer
Intern
</div>
<!--dropdown-content close div-->
</div>
<!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">Contact</button>
<div class="dropdown-content">
Email
FAQS
Newsletter
</div>
<!--dropdown-content-->
</div>
<!--dropdown close div-->
</div>
<!--container close div-->
ps. i dont know what is up with the menu interaction, but you will know it probably.

Resolved part of the problem and managed to get the drop-down menu to actually show every of its items on top of each other. However I didn't find how to put its sub-menu's on the side (If that's what you wanted?) and make the menu actually drop down. Hopefully that'll put you on the right way.
Parts of the problem came from position and overflow properties.
#header {
height: 108px;
width: 1140px;
background-color: #faa220;
position: relative;
}
#Logo2 {
height: 108px;
float: left;
}
#header links {
height: 50px;
float: left;
list-style: none;
padding-top: 10px;
}
#container {
background-color: #faa220;
font-family: Arial, Helvetica, sans-serif;
position: absolute;
bottom: 0;
right: 215px;
}
.container a {
float: left;
font-size: 18px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
position: absolute;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 18px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
cursor: pointer;
}
.container a:hover, .dropdown:hover .dropbtn {
background-color: #faa220;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #faa220;
min-width: 100px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
color: white;
padding: 12px 16px;
text-decoration: none;
/*display: block;*/
text-align: left;
position: static;
}
.dropdown-content a:hover {
background-color: #faa220;
position: absolute;
bottom: 0;
}
.dropdown:hover .dropdown-content {
position: absolute;
display: block;
bottom: 0;
}
<div id="header">
<img src="../JPEG/i2i logo 2.jpg" align="left" id="Logo2" />
<div id="container">
<div class="dropdown">
<button class="dropbtn">Home</button>
</div><!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">About Us</button>
<div class="dropdown-content">
Bio<br>
News<br>
Partners
</div><!--dropdown-content close div-->
</div><!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">Awards/Certifications</button>
</div>
<div class="dropdown">
<button class="dropbtn">Services</button>
<div class="dropdown-content">
Solar<br>
Water<br>
Housing<br>
Training<br>
Broadband
</div><!--dropdown-content close div-->
</div><!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">How You Can Help</button>
<div class="dropdown-content">
Donate<br>
Volunteer<br>
Intern
</div><!--dropdown-content close div-->
</div><!--dropdown close div-->
<div class="dropdown">
<button class="dropbtn">Contact</button>
<div class="dropdown-content">
Email<br>
FAQS<br>
Newsletter
</div><!--dropdown-content-->
</div><!--dropdown close div-->
</div><!--container close div-->

Related

css mega menu with animation

I am trying to code a menu with a mega menu option.
The top level links have an underline animation.
If the top level nav has a mega class, the mega menu container shows, but the underline animation does not.
If I lower the mega menu container, the animation does show, but as soon as the mouse moves off the top link into the container, the container hides as there is a gap because the un-hover switches it off.
Also, moving right from the top level from Option1 to Option 2, nav hides the mega container and the animation shows(correct), but moving right to the Sign In link does not hide the mega container or do the animation.
body #mainMenu {
background-color: #fff;
height: 80px;
position: absolute;
top: 0px;
left: 0;
width: 100%;
padding: 10px;
align-items: center;
display: flex;
padding-left: 40px;
padding-right: 40px;
}
#menuOptions {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
position: relative;
width: 100%;
padding: 0;
list-style-type: none;
font-size: 12px;
font-weight: 400;
}
#menuOptions li {
display: flex;
}
#menuOptions li a {
color: #000;
}
#menuOptions li a:link {
text-decoration: none;
}
.hover-underline-animation {
display: inline-block;
position: relative;
color: #0087ca;
}
.hover-underline-animation:after {
content: '';
position: absolute;
width: 100%;
transform: scaleX(0);
height: 2px;
bottom: 0;
left: 0;
background-color: red;
transform-origin: bottom right;
transition: transform 0.25s ease-out;
}
.hover-underline-animation:hover:after {
transform: scaleX(1);
transform-origin: bottom left;
}
.mega-container {
display: none;
position: absolute;
top: 0px;
left: 0;
height: 120px;
width: 100%;
}
.mega:hover .mega-container {
display: block;
padding-top: 30px;
}
.mega-menu {
background-color: yellow;
height: 100px;
padding: 60px;
}
<html>
<head>
<title>Mega Menu</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<nav id='mainMenu'>
<ul id='menuOptions'>
<li><a href='#' class='menuTopLevelItem hover-underline-animation'>Sign In</a></li>
<li class='mega'><a href='#' class='menuTopLevelItem hover-underline-animation'>Option 1</a>
<div class='mega-container'>
<div class='mega-menu'>
<p>This is mega menu 1</p>
</div>
</div>
</li>
<li><a href='#' class='menuTopLevelItem hover-underline-animation'>Option 2</a></li>
<li><a href='#' class='menuTopLevelItem hover-underline-animation'>Option 3</a></li>
<li><a href='#' class='menuTopLevelItem hover-underline-animation'>Option 4</a></li>
<li><a href='#' class='menuTopLevelItem hover-underline-animation'>Option 5</a></li>
<li><a href='#' class='menuTopLevelItem hover-underline-animation'>Option 6</a></li>
</ul>
</nav>
</body>
</html>
try below code for animation with mega menu using css only.
set column in menu using float and width property of css or you can use table also.
you can use font.awesome style or html entity for icon of submenu.
* {
box-sizing: border-box;
}
body {
margin: 0;
}
.navbar {
overflow: hidden;
background-color: #333;
font-family: Arial, Helvetica, sans-serif;
}
.navbar a {
float: left;
font-size: 16px;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
font-size: 16px;
border: none;
outline: none;
color: white;
padding: 14px 16px;
background-color: inherit;
font: inherit;
margin: 0;
}
.navbar a:hover, .dropdown:hover .dropbtn {
background-color: red;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f9f9f9;
width: 100%;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content .header {
background: skyblue;
padding: 16px;
color: white;
}
.dropdown:hover .dropdown-content {
display: block;
}
/* Create three equal columns that floats next to each other */
.column {
float: left;
width: 33.33%;
padding: 10px;
background-color: #ccc;
height: 250px;
}
.column a {
float: none;
color: black;
padding: 16px;
text-decoration: none;
display: block;
text-align: left;
}
.column a:hover {
background-color: #ddd;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<body>
<div class="navbar">
Home
News
<div class="dropdown">
<button class="dropbtn">Dropdown
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
<div class="header">
<h4>Mega Menu</h4>
</div>
<div class="row">
<div class="column">
<h3>Category 1</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 2</h3>
Link 1
Link 2
Link 3
</div>
<div class="column">
<h3>Category 3</h3>
Link 1
Link 2
Link 3
</div>
</div>
</div>
</div>
</div>

Same CSS code working for one button but not another

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
}

How to make navigation bar fit all screen sizes in HTML and CSS?

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

How do I center this navbar with links and dropdown items?

I'm trying to figure out how to center this navbar that contains links and dropdown items. I'm able to get the links centered by themselves and the dropdown items centered by themselves but when attempting to get them all centered together they appear centered horizontally but not vertically. Currently they look like this left aligned. When i change the floats to none (and add flex as suggested) i get this one improperly centered.
.navbar {
overflow: hidden;
}
.navbar a {
float: left;
padding: 14px 16px;
background-color: #666666;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
padding: 14px 16px;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
z-index: 1;
}
.dropdown-content a {
float: none;
padding: 12px 16px;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="navbar">
a
<div class="dropdown">
<button class="dropbtn">b</button>
<div class="dropdown-content">
1
2
</div>
</div>
<div class="dropdown">
<button class="dropbtn">c</button>
<div class="dropdown-content">
3
4
</div>
</div>
d
</div>
You can use flex for that matter...
.navbar {
overflow: hidden;
display: flex;
justify-content:center;
}
.navbar a {
float: left;
padding: 14px 16px;
background-color: #666666;
}
.dropdown {
float: left;
overflow: hidden;
}
.dropdown .dropbtn {
padding: 14px 16px;
margin: 0;
}
.dropdown-content {
display: none;
position: absolute;
min-width: 160px;
z-index: 1;
}
.dropdown-content a {
float: none;
padding: 12px 16px;
display: block;
text-align: left;
}
.dropdown:hover .dropdown-content {
display: block;
}
<div class="navbar">
a
<div class="dropdown">
<button class="dropbtn">b</button>
<div class="dropdown-content">
1
2
</div>
</div>
<div class="dropdown">
<button class="dropbtn">c</button>
<div class="dropdown-content">
3
4
</div>
</div>
d
</div>

my CSS is acting wierd and merging two divs into one slightly larger box

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>