I made this page
* {
box-sizing: border-box;
}
/* Navbar */
nav {
background: #4D636F;
max-height: 51px;
margin: 0;
overflow: hidden;
padding: 0;
}
nav a {
text-decoration: none;
}
nav span.badge {
position: absolute;
font-size: 12px;
top: 5px;
right: 6;
background-color: #4CAF50;
padding: 1px 4px;
border-radius: 50%;
}
nav .logo {
background: #3A4B53;
float: left;
font-size: 18px;
padding: 12px 18px;
color: #fff;
cursor: pointer;
}
nav .logo i {
margin-right: 13px;
}
nav ul {
list-style-type: none;
margin: 0;
padding-top: 12px;
}
nav ul li {
display: inline;
}
nav ul li a {
color: #fff;
padding: 12px 18px;
font-size: 18px;
transition: all 0.2s ease;
}
nav ul li a:hover {
color: #444;
background-color: white;
}
nav .right {
float: right;
}
nav .right a img {
width: 25px;
height: 25px;
border-radius: 50%;
margin-bottom: 8px;
}
li.dropdown {
position: relative;
}
.dropdown-menu {
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
padding: 0;
top: 20px;
z-index: 1;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2)
}
.dropdown-menu a {
color: #444;
text-align: left;
padding: 0;
display: block;
}
/* Navbar ends */
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<nav id="myNav">
<div class="logo">
<span><i class="fa fa-home" aria-hidden="true"></i>Logo</span>
</div>
<ul>
<li><i class="fa fa-globe" aria-hidden="true"></i></li>
<li><i class="fa fa-user" aria-hidden="true"></i></li>
<li><i class="fa fa-envelope" aria-hidden="true"></i></li>
<li class="dropdown">
<a href="#" style="position: relative;"><i class="fa fa-bell"></i>
<span class="badge">3</span>
</a>
<div class="dropdown-menu">
One
One
One
</div>
</li>
<li class="right"><img src="images/profile.png" align="middle"></li>
</ul>
</nav>
The problem as viewed is that the dropdown-menu does not appear correctly.
I made it it absolute and it has z-index : 1 :(
I know that I didn't make it hoverable but I want it to appear then I will handle it.
I don't feel anything wrong with the code, but the output says otherwise.
What I did wrong? And what should I do to make it right?
Your problem is the overflow: hidden in the nav
* {
box-sizing: border-box;
}
/* Navbar */
nav {
background: #4D636F;
max-height: 71px;
margin: 0;
padding: 0;
}
nav a {
text-decoration: none;
}
nav span.badge {
position: relative;
font-size: 12px;
top: -11px;
height: 15px;
background-color: #4CAF50;
padding: 2px 6px;
border-radius: 50%;
}
nav .logo {
background: #3A4B53;
float: left;
font-size: 18px;
padding: 12px 18px;
color: #fff;
cursor: pointer;
}
nav .logo i {
margin-right: 13px;
}
nav ul {
list-style-type: none;
margin: 0;
line-height: 45px
}
nav ul li {
display: inline;
}
nav ul li a {
color: #fff;
padding: 12px 18px;
font-size: 18px;
transition: all 0.2s ease;
}
nav ul li a:hover {
color: #444;
background-color: white;
}
nav .right {
float: right;
}
nav .right a img {
width: 25px;
height: 25px;
border-radius: 50%;
margin-bottom: 8px;
}
li.dropdown {
position: relative;
}
.dropdown-menu {
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
padding: 0;
top: 31px;
z-index: 1;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2)
}
.dropdown-menu a {
color: #444;
text-align: left;
padding: 0;
display: block;
}
/* Navbar ends */
<link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<nav id="myNav">
<div class="logo">
<span><i class="fa fa-home" aria-hidden="true"></i>Logo</span>
</div>
<ul>
<li><i class="fa fa-globe" aria-hidden="true"></i></li>
<li><i class="fa fa-user" aria-hidden="true"></i></li>
<li><i class="fa fa-envelope" aria-hidden="true"></i></li>
<li class="dropdown">
<a href="#" style="position: relative;"><i class="fa fa-bell"></i>
<span class="badge">3</span>
</a>
<div class="dropdown-menu">
One
One
One
</div>
</li>
<li class="right"><img src="images/profile.png" align="middle"></li>
</ul>
</nav>
.dropdown-menu {
position: absolute;
background-color: #f9f9f9;
min-width: 160px;
padding: 0;
top: 31px;
z-index: 1;
left: 0;
box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
max-height: 71px;
overflow-y: hidden;
}
.dropdown-menu :hover {
overflow-y: visible;
}
I used that a couple of times on my web page.
Related
I have a navbar on my Django application. The code for it is below.
.nav-header {
height: 75px;
width: 100%;
float: left;
background: #2e2e2e;
padding: 0 20px;
color: #fff;
margin-bottom: 25px;
border-bottom: 2px solid black;
}
.brand-logo {
max-width: 75px;
float: left;
padding: 14px 0px;
}
.brand-logo img {
max-width: 100%;
}
.navigation {
margin: 0px;
float: right;
}
.navigation li {
list-style: none;
float: left;
}
.navigation li a {
color: #fff;
padding: 28px 15px;
text-transform: uppercase;
text-align: center;
display: block;
text-decoration: none;
}
.navigation li a i {
width: 100%;
font-size: 20px;
margin-bottom: 7px;
}
.show-menu-btn,
.hide-menu-btn {
transition: 0.4s;
font-size: 30px;
cursor: pointer;
display: none;
z-index: 2;
}
.show-menu-btn {
margin: 0px;
margin-top: 15px;
float: right;
}
.show-menu-btn i {
line-height: 100px;
}
.navigation a:hover,
.show-menu-btn:hover,
.hide-menu-btn:hover {
color: #00ff0a;
}
#toggle-btn {
position: absolute;
visibility: hidden;
z-index: -1111;
}
#media screen and (max-width: 767px) {
.show-menu-btn,
.hide-menu-btn {
display: block;
}
.navigation {
position: fixed;
width: 100%;
height: 100vh;
background: #2e2e2e;
top: -100%;
left: 0;
padding: 50px 0px;
transition: 1s;
z-index: 1;
}
.navigation li {
width: 100%;
}
.navigation li a {
padding: 15px 15px;
text-align: left;
}
.navigation li a i {
width: auto;
font-size: 20px;
}
.hide-menu-btn {
position: absolute;
top: 15px;
right: 20px;
}
#toggle-btn:checked ~ nav .navigation {
top: 0px;
}
}
<div class="container">
<input type="checkbox" id="toggle-btn">
<label for="toggle-btn" class="show-menu-btn"><i class="fas fa-bars"></i></label>
<nav>
<ul class="navigation">
<li><i class="fas fa-house-damage"></i> Home</li>
{% if request.user.is_authenticated %}
<li><i class="fas fa-sign-out-alt"></i> Sign Out</li>
{% else %}
<li><i class="fas fa-sign-in-alt"></i> Sign In</li>
<li><i class="fas fa-user-plus"></i> Sign Up</li>
{% endif %}
<label for="toggle-btn" class="hide-menu-btn"><i class="fas fa-times"></i></label>
</ul>
</nav>
</div>
When I test it locally in google chrome on my PC using the device toolbar, it works completely fine. When I deploy it to my Heroku server, the hamburger icon does not show.
The label is there it just is not visible. When I try to randomly tap the screen in the area where it is supposed to be, it works but still does not show.
I have no idea why my drop down menu that im trying to include is not appearing and i cant seem to find whats wrong, i saw that the only way for it to appear is to remove hidden but if i do that i doesnt look how i want it to, yet if i have the hidden when i hover over the servicios tab its not showing anything which i cannot find the reason on why it doesnt appear there
{
margin: 0;
padding: 0;
font-family: sans-serif;
}
.hero{
height: 100vh;
background-image: linear-gradient(rgba(0,0,0,0.8), rgba(0,0,0,0.6)), url(bp.jpg);
background-position: center;
background-size: cover;
overflow-x: hidden;
position: relative;
}
.nav_bar{
display: flex;
padding: 40px 120px;
}
.nav-logo img{
width: 135px;
}
.nav_links{
flex: 1;
}
.nav_links ul{
margin-left: 50px;
display: inline;
list-style: none;
}
.nav_links ul li{
list-style: none;
display: inline-block;
padding: 8px 25px;
}
.nav_links ul a{
color: #fff;
text-decoration: none;
font-size: 18px;
}
.nav_links ul li::after{
content: '';
width: 0;
height: 2px;
background: red;
display: block;
margin: auto;
transition: 0.45s;
}
.nav_links ul li:hover::after{
width: 100%;
}
.btn{
padding: 10px 10px;
border: 0;
background: red;
font-weight: bold;
cursor: pointer;
}
.nav_links .btn{
float: center;
}
.frase{
margin: 100px 130px;
color: #fff;
}
.frase h1{
font-size: 56px;
margin-bottom: 30px;
}
.vertical_bar{
height: 100%;
background: red;
top: 0;
left: 0;
position: absolute;
}
.icono_busqueda{
height: 60%;
width: 80px;
}
.icono_busqueda .fa{
margin: 45px 23px;
display: block;
color: white;
font-size: 30px;
cursor: pointer;
}
.iconos_sociales{
height: 60%;
width: 80px;
}
.iconos_sociales .fa{
margin: 45px 23px;
display: block;
color:black;
font-size: 30px;
cursor: pointer;
}
.iconos_sociales{
height: 35%;
width: 80px;
background: white;
text-align: center;
padding-top: 27%;
bottom: 0;
position: absolute;
}
.iconos_sociales .fa{
margin: 15px 15px;
display: block;
padding: 8px;
border: 1px solid black;
border-radius: 0;
cursor: pointer;
}
*{
margin: 0;
padding: 0;
}
.sub_menu_ser
{
display: none;
}
.nav_links ul li:hover .sub_menu_ser
{
display: block;
position: absolute;
background: red;
margin-top: 15px;
margin-left: -15px;
}
.nav_links ul li:hover .sub_menu_ser ul
{
display: block;
margin: 10px;
}
.nav_links ul li:hover .sub_menu_ser li
{
width: 150px;
padding: 10px;
border-bottom: 1px dotted white;
background: transparent;
border-radius: 0;
text-align: left;
}
:last-child
{
border-bottom: none;
}
.nav_links ul li:hover .sub_menu_ser ul li a:hover
{
color: red;
}
<html>
<head>
<title> Animal Care</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="hero">
<div class="nav_bar">
<div class="nav_logo">
<img src="logo.png">
</div>
<div class="nav_links">
<ul>
<li>Sobre Nosotros</li>
<li>Servicios</li>
<div class="sub_menu_ser">
<ul>
<li>Peluqueria</li>
<li>Veterinario</li>
<li>Cirugia</li>
<li>Limpieza</li>
</ul>
</div>
<li>Contacto</li>
</ul>
<button type="button" class="btn">Registrarse</button>
</div>
<div class="frase">
<h1>Cuidando a Nuestros <br> Mas Queridos</h1>
<button type="button" class="btn">Explorar</button>
</div>
<div class="vertical_bar">
<div class="icono_busqueda">
<i class="fa fa-search"></i>
<i class="fa fa-list"></i>
</div>
<div class="iconos_sociales">
<i class="fa fa-facebook"></i>
<i class="fa fa-instagram"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-envelope-o"></i>
</div>
</div>
</div>
</body>
</html>
Code to hide the element:
#element {
display: none;
}
Code to show the element:
#element:hover {
display: block;
}
I am not able to click on HOME, CATEGORIES and LOGIN link.
The links which are not collapsing with image, they're clickable. Otherwise it won't click.
It was working fine initially when there wasn't any content.
I tried adding javascript and doing it the other way but I was still facing the same issue.
nav {
background: #14213d;
height: 80px;
width: 100%;
}
label.logo {
color: #ffffff;
font-size: 30px;
line-height: 80px;
padding: 0 140px;
font-weight: 600;
font-family: 'Poppins', sans-serif;
}
nav ul {
float: right;
margin-right: 60px;
}
nav ul li {
display: inline-block;
line-height: 80px;
margin: 0 2px;
}
nav ul li a {
color: #d1d1d1;
font-weight: 500;
font-size: 15px;
padding: 7px 13px;
border-radius: 3px;
/* text-transform: uppercase; */
font-family: 'Poppins', sans-serif;
}
a.active,
a:hover {
background: #263e72;
transition: .5s;
}
.checkbtn {
font-size: 30px;
color: white;
float: right;
line-height: 80px;
margin-right: 40px;
cursor: pointer;
display: none;
}
#check {
display: none;
}
#media (max-width: 952px) {
label.logo {
font-size: 27px;
padding-left: 25px;
}
nav ul li a {
font-size: 16px;
}
.text {
font-size: 21px
}
}
#media (max-width: 858px) {
.checkbtn {
display: block;
margin-right: 40px;
}
ul {
position: fixed;
width: 100%;
height: 100vh;
background: #e5e5e5;
top: 80px;
left: -100%;
text-align: center;
transition: all .5s;
}
nav ul li {
display: block;
margin: 50px 0;
line-height: 30px;
}
nav ul li a {
font-size: 20px;
color: #4d4a46;
}
a:hover,
a.active {
background: none;
color: #4d4a46;
background: #c8d1e4;
}
#check:checked~ul {
left: 0;
}
.text {
font-size: 11px
}
}
<nav>
<input type="checkbox" id="check">
<label for="check" class="checkbtn">
<i class="fa fa-bars"></i>
</label>
<label class="logo"><i id="logo" class="fa fa-book"></i> Book Shoppers</label>
<ul>
<li><a class="active" href="#"><i class="fa fa-home"></i> HOME</a></li>
<li><i class="fa fa-chevron-circle-down"></i> CATEGORIES</li>
<li><i class="fa fa-sign-in"></i> LOGIN</li>
<li><i class="fa fa-heart"></i> WISHLIST</li>
<li><i class="fa fa-phone"></i> CUSTOMER SUPPORT</li>
</ul>
</nav>
Try adding z-index in the nav of the css file.
This will solve the problem
nav {
background: #14213d;
height: 80px;
width: 100%;
z-index: 2;
}
Editing and adding code to snippet .This is the full code extraced from the below two links.
body {
font-family: 'Alegreya Sans', sans-serif;
overflow-x: hidden;
background: gray;
color: white;
}
#content {
padding: 15px;
transition: margin-left 0.7s;
overflow: hidden;
width: 100%;
}
.slide a {
color: #000;
font-size: 36px;
}
.nav .close {
position: absolute;
top: 8px;
right: 22px;
margin-left: 50px;
font-size: 30px;
color: #ccc;
}
.nav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #282828;
overflow-x: hidden;
padding-top: 60px;
transition: 0.7s;
}
.nav a.item {
display: flex;
flex-direction: row;
padding: 18px 30px;
font-size: 30px;
text-decoration: none;
color: #ccc;
background-color: #3d3d3d;
border-top: 1px solid #ccc;
}
.nav .last {
border-bottom: 1px solid #ccc;
}
.nav a.item:hover {
color: #fff;
background-color: #cf0000;
transition: 0.4s;
}
.nav .icon {
padding-right: 10px;
font-size: 35px;
}
.nav ul {
display: flex;
position: absolute;
width: 100%;
margin-top: 50px;
}
.nav ul li {
list-style: none;
}
.nav ul li a.inline {
font-size: 26px;
color: #ccc;
padding: 6px 5px 3px;
}
.nav ul li a.inline:hover {
color: #cf0000;
}
.content p{
font-size: 18px;
text-align: center;
margin-left: 310px;
}
.footer-home{
position: fixed;
left: 0;
bottom: 0;
width:100%;
height: auto;
background-color:#282828;
color: white;
padding: 10px;
text-align: center;
}
* {
box-sizing: border-box;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<script src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script>
<link rel="stylesheet" href="style.css">
<script>
function openSlideMenu(){
document.getElementById('menu').style.width = '250px';
document.getElementById('content').style.marginLeft = '250px';
}
function closeSlideMenu(){
document.getElementById('menu').style.width = '0';
document.getElementById('content').style.marginLeft = '0';
}
</script>
</head>
<body>
<div id="content">
<span class="slide">
<a href="#" onclick="openSlideMenu()">
<i class="fas fa-bars"></i>
</a>
</span>
<div id="menu" class="nav">
<a href="#" class="close" onclick="closeSlideMenu()">
<i class="fas fa-times"></i>
</a>
<img src="#" alt="" width="150" height="100">
<i class="fas fa-home icon"></i>Home
<i class="fas fa-desktop icon"></i>Dashboards
<i class="fas fa-map-marker icon"></i>Engagements
<i class="fab fa-wpforms icon"></i>Contact
<ul>
Can't get dropdown to work.
Tried several ways to make dropdown active.
html - http://textsnip.com/nau26f
css - http://textsnip.com/dyk75z
Trying to make dropdown active when hovering over dashboards. Any help would be greatly appreciated.
Here's my solution
function openSlideMenu(){
document.getElementById('menu').style.width = '250px';
document.getElementById('content').style.marginLeft = '250px';
}
function closeSlideMenu(){
document.getElementById('menu').style.width = '0';
document.getElementById('content').style.marginLeft = '0';
}
body {
font-family: 'Alegreya Sans', sans-serif;
overflow-x: hidden;
background: gray;
color: white;
}
#content {
padding: 15px;
transition: margin-left 0.7s;
overflow: hidden;
width: 100%;
}
.slide a {
color: #000;
font-size: 36px;
}
.nav .close {
position: absolute;
top: 8px;
right: 22px;
margin-left: 50px;
font-size: 30px;
color: #ccc;
}
.nav {
height: 100%;
width: 0;
position: fixed;
z-index: 1;
top: 0;
left: 0;
background-color: #282828;
overflow-x: hidden;
padding-top: 60px;
transition: 0.7s;
}
.nav a.item {
display: flex;
flex-direction: row;
padding: 18px 30px;
font-size: 30px;
text-decoration: none;
color: #ccc;
background-color: #3d3d3d;
border-top: 1px solid #ccc;
}
.nav .last {
border-bottom: 1px solid #ccc;
}
.nav a.item:hover {
color: #fff;
background-color: #cf0000;
transition: 0.4s;
}
.nav .icon {
padding-right: 10px;
font-size: 35px;
}
.nav ul {
display: flex;
position: absolute;
width: 100%;
margin-top: 50px;
}
.nav ul li {
list-style: none;
}
.nav ul li a.inline {
font-size: 26px;
color: #ccc;
padding: 6px 5px 3px;
}
.nav ul li a.inline:hover {
color: #cf0000;
}
.content p{
font-size: 18px;
text-align: center;
margin-left: 310px;
}
.footer-home{
position: fixed;
left: 0;
bottom: 0;
width:100%;
height: auto;
background-color:#282828;
color: white;
padding: 10px;
text-align: center;
}
* {
box-sizing: border-box;
}
.column {
float: left;
width: 33.33%;
padding: 5px;
}
/* Clearfix (clear floats) */
.row::after {
content: "";
clear: both;
display: table;
}
.dropbtn {
display: flex;
flex-direction: row;
padding: 18px 30px;
font-size: 30px;
text-decoration: none;
color: #ccc;
background-color: #3d3d3d;
border-top: 1px solid #ccc;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
width: 100%;
}
.dropdown-content a {
display: flex;
width: 100%;
flex-direction: row;
padding: 18px 30px;
font-size: 30px;
text-decoration: none;
color: #ccc;
background-color: #3d3d3d;
border-top: 1px solid #ccc;
}
.dropdown-content a:hover {background-color: #cf0000;}
.dropdown:hover .dropdown-content {display: block;}
.dropdown:hover .dropbtn {background-color: #cf0000;}
<script src="https://use.fontawesome.com/releases/v5.0.7/js/all.js"></script>
<div id="content">
<span class="slide">
<a href="#" onclick="openSlideMenu()">
<i class="fas fa-bars"></i>
</a>
</span>
<div id="menu" class="nav">
<a href="#" class="close" onclick="closeSlideMenu()">
<i class="fas fa-times"></i>
</a>
<img src="#" alt="" width="150" height="100">
<i class="fas fa-home icon"></i>Home
<div class="dropdown">
<a class="dropbtn">
<i class="fas fa-desktop icon"></i>
Dashboards
</a>
<div class="dropdown-content">
Link 1
Link 2
Link 3
</div>
</div>
<a href="maps.html" class="item">
<i class="fas fa-map-marker icon"></i>
Engagements
</a>
<a href="contact.html" class="item last">
<i class="fab fa-wpforms icon"></i>
Contact
</a>
</div>
</div>
I am a new learner of CSS and I have a problem with the position of dropdown menu, does not stay on hover. I have done some testing and I found that the problem is the position of left element because when I chance the value of left, the dropdown stay on hover and it lets do it but it is not in its position.
I do not know how to fix it, I will appreciate any help of anyone.
/* Grid View*/
* {
box-sizing: border-box;
}
/* Body Size*/
body {
background-color: white;
position: relative;
margin-right: 150px;
margin-left: 150px;
margin-top: 20px;
}
/*Header*/
header {
position: fixed;
top: 0;
margin: 80%;
height: 100px;
background-color: whitesmoke;
color: black;
padding: 10px;
text-align: center;
}
/* Header <Logo> */
logo {
position: fixed;
left: 180px;
top: 0px;
width: 250px;
height: 140px;
}
/* Header < Social Bar>*/
.icon-bar {
width: 100px;
overflow: auto;
}
/* Social Icons */
.icon-bar {
float: right;
width: 30%;
text-align: center;
padding: 12px 0;
transition: all 0.3s ease;
color: white;
font-size: 36px;
top: 100px;
}
.icon-bar a:hover {
background-color: yellow;
}
/* Header <Menu>*/
.menu-button1 {
position: relative;
left: 300px;
top: -48px;
background-color: #47037A;
border: none;
color: #cccc00;
padding: 8px 40px 8px 40px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
font-family: Arial;
margin: 4px 2px;
cursor: pointer;
border-radius: 6px;
}
.menu-button2 {
position: relative;
left: 293px;
top: -48px;
background-color: #47037A;
border: none;
color: #cccc00;
padding: 8px 40px 8px 40px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
font-family: Arial;
margin: 4px 2px;
cursor: pointer;
border-radius: 6px;
}
.menu-button3 {
position: relative;
left: 286px;
top: -48px;
background-color: #47037A;
border: none;
color: #cccc00;
padding: 8px 40px 8px 40px;
text-align: center;
text-decoration: none;
font-size: 20px;
font-family: Arial;
margin: 4px 2px;
border-radius: 6px;
cursor: pointer;
}
/* The container <div> - needed to position the dropdown content */
.dropdown {
display: inline-block;
position: relative;
}
.dropdown-menu {
display: none;
position: absolute;
top: 0px;
left: 256px;
margin: 4px 2px;
padding: 4px 28px 4px 28px;
text-align: center;
text-decoration: none;
font-size: 20px;
font-family: Arial;
border-radius: 6px;
z-index: 1;
}
/* Links inside the dropdown */
.dropdown-menu a {
background-color: #cccc00;
color: #47037A;
text-decoration: none;
display: block;
padding: 4px 28px 4px 28px;
border-radius: 6px;
margin-bottom: 1px;
}
/* Change color of dropdown links on hover */
.dropdown-menu a:hover {
display: block;
background-color: #47037A;
color: #cccc00;
padding: 4px 28px 4px 28px;
border-radius: 6px;
}
/* Show the dropdown menu on hover */
.dropdown:hover .dropdown-menu {
display: inline-block;
}
/* Change the background color of the dropdown button when the dropdown content is shown */
.dropdown:hover .menu-button3 {
background-color: #cccc00;
}
.menu-button4 {
position: relative;
left: 280px;
top: -48px;
background-color: #47037A;
border: none;
color: #cccc00;
padding: 8px 40px 8px 40px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
font-family: Arial;
margin: 4px 2px;
cursor: pointer;
border-radius: 6px;
}
.menu-button5 {
position: relative;
left: 273px;
top: -48px;
background-color: #47037A;
border: none;
color: #cccc00;
padding: 8px 40px 8px 40px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
font-family: Arial;
margin: 4px 2px;
cursor: pointer;
border-radius: 6px;
}
.menu-button6 {
position: relative;
left: 266px;
top: -48px;
background-color: #47037A;
border: none;
color: #cccc00;
padding: 8px 40px 8px 40px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
font-family: Arial;
margin: 4px 2px;
cursor: pointer;
border-radius: 6px;
}
.menu-button7 {
position: relative;
left: 260px;
top: -48px;
background-color: #cccc00;
border: none;
color: #47037A;
padding: 8px 40px 8px 40px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
font-family: Arial;
margin: 4px 2px;
cursor: pointer;
border-radius: 6px;
}
.menu-button1:hover {
background-color: #cccc00;
color: #47037A;
}
.menu-button2:hover {
background-color: #cccc00;
color: #47037A;
}
.dropdown:hover .menu-button3 {
background-color: #cccc00;
color: #47037A;
}
.menu-button4:hover {
background-color: #cccc00;
color: #47037A;
}
.menu-button5:hover {
background-color: #cccc00;
color: #47037A;
}
.menu-button6:hover {
background-color: #cccc00;
color: #47037A;
}
.menu-button7:hover {
background-color: #47037A;
color: #cccc00;
}
.dropdown-content-menu-button3 {
display: none;
position: absolute;
background-color: #47037A;
min-width: 160px;
}
/* Line separate header */
.hr-header {
position: fixed;
top: 218px;
height: 3px;
left: 0px;
right: 0%;
background-color: #47037A;
}
/* Content of Body */
.content {
position: fixed;
overflow: auto;
float: left;
width: 800px;
margin: 0;
padding: 10px;
}
h1 {
color: darkblue;
}
p {
color: navy;
}
#footer {
position: fixed;
left: 0px;
bottom: 0;
height: 150px;
width: 100%;
color: #47037A;
background-color: whitesmoke;
padding: 10px;
font-family: Arial;
}
.footer-contactus {
text-align: left;
}
.footer-copyrights {
text-align: center;
}
.footer-socialm {
text-align: right;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="header">
<div>
<div class="logo">
<img src="images/logo.jpg" alt="logo" />
<div class="icon-bar">
<a class="active" href="#"><i class="fa fa-search"></i></a>
<i class="fa fa-facebook"></i>
<i class="fa fa-instagram"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-youtube"></i>
</div>
<div>
<button class="menu-button1">Menu1</button>
<button class="menu-button2">Menu2</button>
<!-- dropdown container -->
<div class="dropdown">
<!-- trigger button -->
<button class="menu-button3">Menu3</button>
<!-- dropdown menu -->
<div class="dropdown-menu">
Item1
Item2
Item3
Item4
Item5
</div>
</div>
<button class="menu-button4">Menu4</button>
<button class="menu-button5">Menu5</button>
<button class="menu-button6">Menu6</button>
<button class="menu-button7">Menu7</button>
</div>
</div>
<div class="hr-header"></div>
</div>
<div class="content">
Body
</div>
<div id="footer">
<div class="footer-contactus">
email: phone: address
</div>
<div class="footer-copyrights">
Copyright © website 1
</div>
<div class="footer-socialm">
<div class="icon-bar">
<a class="active" href="#"><i class="fa fa-search"></i></a>
<i class="fa fa-facebook"></i>
<i class="fa fa-instagram"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-youtube"></i>
</div>
</div>
</div>
</div>
There were a lot of bugs in the html structure and css.
1. Never use position to set every element.
2. Your Menu was made up of button which was causing the problem, Always use unorder list (ul li) to make menus.
3. Some divs were not closed properly.
4. No need to write css for repeating elements. You can make a common class and use it again and again.
Below is the correct code structure and css. Also added some animation
to your dropdown so you can now learn some new things too :)
/* Grid View*/
* {
box-sizing: border-box;
}
/* Body Size*/
body {
background-color: white;
//position: relative;
margin-right: 150px;
margin-left: 150px;
margin-top: 20px;
}
/*Header*/
header {
position: fixed;
top: 0;
margin: 80%;
height: 100px;
background-color: whitesmoke;
color: black;
padding: 10px;
text-align: center;
}
/* Header <Logo> Fixed- No Need to make it fix positon as parent already fixed*/
.logo {
float: left;
max-width: 250px;
}
/* Header < Social Bar>*/
.icon-bar {
width: 100px;
overflow: auto;
}
/* Social Icons */
.icon-bar {
float: right;
width: 30%;
text-align: center;
padding: 12px 0;
transition: all 0.3s ease;
color: white;
font-size: 36px;
top: 100px;
}
.icon-bar a:hover {
background-color: yellow;
}
/* Header <Menu>*/
.menu {
float: left;
width: 65%;
padding: 0px;
margin: 0px;
}
.menu li {
border: none;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 20px;
font-family: Arial;
margin: 4px 2px;
cursor: pointer;
border-radius: 6px;
position: relative;
}
.menu li a {
text-decoration: none;
color: #cccc00;
padding: 8px 20px;
display: block;
border-radius: 6px;
background-color: #47037A;
}
.menu li a:hover {
background-color: #cccc00;
color: #47037A;
}
.dropdown {
position: absolute;
top: 37px;
left: 0px;
padding: 0px;
margin: 0px;
visibility: hidden;
opacity: 0;
transform: translateY(-2em);
z-index: -1;
transition: all 0.3s ease-in-out 0s, visibility 0s linear 0.3s, z-index 0s linear 0.01s;
}
.dropdown li {
width: 100%;
margin: 4px 0;
}
.dropdown li a {
background-color: #cccc00;
color: #47037A;
}
.menu li:hover>.dropdown {
visibility: visible;
/* shows sub-menu */
opacity: 1;
z-index: 1;
transform: translateY(0%);
transition-delay: 0s, 0s, 0.3s;
}
/* Line separate header */
.hr-header {
float: left;
height: auto;
background-color: #47037A;
}
/* Content of Body */
.content {
float: left;
float: left;
width: 800px;
margin: 0 auto;
padding: 10px;
}
h1 {
color: darkblue;
}
p {
color: navy;
}
#footer {
position: fixed;
left: 0px;
bottom: 0;
height: 150px;
width: 100%;
color: #47037A;
background-color: whitesmoke;
padding: 10px;
font-family: Arial;
}
.footer-contactus {
text-align: left;
}
.footer-copyrights {
text-align: center;
}
.footer-socialm {
text-align: right;
}
<link rel="stylesheet" type="text/css" href="css/styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="js/functions.js" type="text/javascript"></script>
<div class="header">
<div class="logo">
<img src="images/logo.jpg" alt="logo" />
</div>
<div class="icon-bar">
<a class="active" href="#"><i class="fa fa-search"></i></a>
<i class="fa fa-facebook"></i>
<i class="fa fa-instagram"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-youtube"></i>
</div>
<ul class="menu">
<li>Menu 1</li>
<li>Menu 2</li>
<li>Menu 3
<!---DropDown On hover----->
<ul class="dropdown">
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
<li>item 4</li>
<li>item 5</li>
<li>item 6</li>
</ul>
</li>
<li>Menu 4</li>
<li>Menu 5</li>
<li>Menu 6</li>
<li>Menu 7</li>
</ul>
<div class="hr-header"></div>
</div>
<div class="content">
Body
</div>
<div id="footer">
<div class="footer-contactus">
email: phone: address
</div>
<div class="footer-copyrights">
Copyright © website 1
</div>
<div class="footer-socialm">
<div class="icon-bar">
<a class="active" href="#"><i class="fa fa-search"></i></a>
<i class="fa fa-facebook"></i>
<i class="fa fa-instagram"></i>
<i class="fa fa-twitter"></i>
<i class="fa fa-youtube"></i>
</div>
</div>
</div>
</div>