I working on making a drop-down menu and it seems when I put the display to none it goes away completely. And when you click on it you can type in the box but I don't want that. I am trying to make so the drop-down list pops up when you hover over it. Does anyone know how to fix this?
body {
margin:0;
padding: 0;
font-family: "Open Sans", sans-serif;
}
.navbar {
border-bottom: 2px solid #0C133C;
}
#nav {
background-color: #fff;
color: white;
width: 100%;
}
.nav {
float: right;
text-align: left;
margin: 0;
}
.nav > li {
display:Inline-block;
padding: 20px 50px 10px 9px;
}
.nav > li a {
text-decoration: none;
color: #0C133C;
font-size: 18px;
border-bottom: 3px solid transparent;
}
.clearer {
clear:both;
}
.subnav class{
margin: 0;
position:relative;
}
.subnav > div a {
text-decoration: none;
color: #0C133C;
font-size: 18px;
padding: 20px 30px 10px 9px;
}
.logo {
margin-top: 1rem;
}
.subnav {
display: flex;
justify-content: space-between;
align-items: center;
margin-right: 1rem;
}
.split {
height: 70%;
width: 50%;
position: fixed;
z-index: 1;
top: -50;
overflow-x: hidden;
padding-top: 20px;
}
.centered {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
text-align: center;
}
.left {
left: 0;
background-color: #282C41;
color: white;
margin-top: .5rem;
font-size: 15px;
}
.right {
right: 0;
background-color: #CDCDCD;
margin-top: .5rem;
font-size: 18px;
}
.dropdown {
position: relative;
margin-top: 20px;
width: 375px;
height: 35px;
}
.dropdown:: before {
content: '';
position: absolute;
right: 20px;
top: 15px;
width: 8px;
height: 8 px;
}
.dropdown input {
position: absolute;
top: 0;
left: 80px;
width: 100%;
height: 100%;
cursor: pointer;
border: none;
outline: none;
box-shadow: 0 2px 5px;
padding: 8px 20px;
border-radius: 10px;
}
.dropdown .option {
position: absolute;
top: 52px;
width: 100%;
box-shadow: 0 2px 5px;
border-radius: 10px;
overflow: hidden;
left: 83px;
display: none;
}
.dropdown .option div {
padding: 12px 20px;
cursor: pointer;
}
.dropdown .option div:hover
{
background: #62baea;
}
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Navbar</title>
<link rel="stylesheet" href="styles.css"
</head>
<body>
<div >
<ul >
<li >
<a aria-current="page" href="#">Contact Us</a>
</li>
<li >
<a aria-current="page" href="#">Sign In</a>
</li>
</ul>
<div ></div>
</div>
<subnav >
<img src="universallogo.jpg" />
<div >
<a href="#">
<a aria-current="page" href="#">Bonds</a>
</a>
<a aria-current="page" href="#">Report a Claim</a>
<a aria-current="page" href="#">About Us</a>
<a aria-current="page" href="#">Search</a>
</div>
</subnav>
<div >
<div >
<h1>GET YOUR LICENSE & PERMIT BONDS FAST & EASY</h1>
<p>We provide our Customers with a fast, easy, and secure way to get bonded. Get your Free Quote in minutes.
</p>
</div>
</div>
<div >
<div >
<input type="text"
placeholder="Select Your State">
<div >
<div >
<div onclick="show('California')">California</div>
<div onclick="show('Illinois')">Illionis</div>
<div onclick="show('Michigan')">Michigan</div>
<div onclick="show('Ohio')">Ohio</div>
</div>
</div>
</body>
</html>
[![My droplist wont apear][1]][1] [1]: https://i.stack.imgur.com/TGmxt.png
CodePudding user response:
Add this to your CSS
.dropdown:hover .option {
display: block;
}
CodePudding user response:
Use a container element to create the dropdown menu and add the dropdown links inside it.
Wrap a <div> element around the button and the to position the dropdown menu correctly with CSS.
<div >
<button >Dropdown</button>
<div >
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
.dropbtn {
background-color: #04AA6D;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}
.dropdown {
position: relative;
display: inline-block;
}
.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 160px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {background-color: #ddd;}
.dropdown:hover .dropdown-content {display: block;}
.dropdown:hover .dropbtn {background-color: #3e8e41;}
CodePudding user response:
body {
font-family: Arial, Helvetica, sans-serif;
}
.navbar {
overflow: hidden;
background-color: #333;
}
.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-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;
}
<div >
<a href="#home">Home</a>
<a href="#news">News</a>
<div >
<button >Dropdown
<i ></i>
</button>
<div >
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>
</div>
