How to hide submenu until it is hovered over by mouse - html

I am currently working on a navigation bar for a website, but I am having trouble with the submenu. I have figured out how to position the submenu relative to it's parent ul, but I am having trouble on making the submenu disappear until the user hovers over the parent.
So when I hover over the "Crisis and Support" I expect not to see the secondary submenu until I hover over the "Resources" tab. Can anyone help figure out what am I doing wrong?
Here is a [live example][1]
/* Navigation Bar */
/* Styles color and interaction, as well as continuous position on scroll. */
.nav {
position: relative;
color: white;
background: -webkit-linear-gradient(#182B52, #1D355E);
/* For Safari 5.1 to 6.0 */
background: -o-linear-gradient(#182B52, #1D355E);
/* For Opera 11.1 to 12.0 */
background: -moz-linear-gradient(#182B52, #1D355E);
/* For Firefox 3.6 to 15 */
background: linear-gradient(#182B52, #1D355E);
/* Standard syntax (must be last) */
box-shadow: 0 0 10px 0px black;
position: -webkit-sticky;
z-index: 1;
}
.nav button {
padding: 10px;
background: #182B52;
color: white;
border-style: solid;
border-top-style: none;
border-color: white;
border-width: 1px;
margin-left: 47%;
margin-bottom: 15px;
}
.nav button:hover {
background: #D3B663;
}
.nav-wrapper {
width: 100%;
margin: 0 auto;
text-align: left;
}
.nav ul {
list-style-type: none;
padding: 0;
margin: 0;
position: relative;
}
.nav ul li {
display: inline-block;
}
.nav ul li:hover {
background-color: #1D355E;
}
.nav ul li a,
visited {
color: white;
display: block;
padding: 15px;
text-decoration: none;
}
.nav ul li a:hover {
color: white;
text-decoration: none;
}
.nav ul li:hover ul {
display: block;
}
.nav ul ul {
display: none;
position: absolute;
background-color: rgba(29, 53, 94, .75);
}
.nav ul ul li {
display: block;
text-align: left;
}
.nav ul ul li a,
visited {
color: white;
}
.nav ul ul li a:hover {
color: #D3B663;
display: block;
}
.nav ul.submenu {
display: none;
position: absolute;
left: 153px;
top: 147px;
width: 150px;
text-align: center;
}
.nav ul.submenu li {
text-align: left;
color: white;
}
.nav li:hover ul.submenu:hover {
color: #D3B663;
display: block;
}
.nav-wrapper img {
float: right;
height: 75px;
padding-right: 70px;
}
.sticky {
position: fixed;
width: 100%;
left: 0;
top: 0;
z-index: 100;
border-top: 0;
}
.nav form {
position: absolute;
right: 0;
padding-right: 75px;
margin-top: -18px;
}
.nav input {
border: solid;
border-color: white;
border-width: 1px;
color: white;
background-color: #182B52;
padding: 6px;
padding-top: 8px;
}
.nav input:hover {
background: #1D355E;
}
<!-- Navigation Bar -->
<div class="nav">
<!-- Quick Close -->
<button id="get-away">QUICK CLOSE</button>
<!-- Search Bar
<form action="./search.php" method="get">
<input type="text" name="input" size="40px"/>
<input type="submit" value="SEARCH"/>
</form> -->
<!-- Sticky Navigation -->
<div class="nav-wrapper">
<ul>
<li>
ABOUT US
<ul>
<li>OUR HER-STORY</li>
<li>WHY A WOMEN'S CENTER?</li>
<li>LEARN ABOUT OUR SPACE</li>
<li>MEET OUR STAFF
<li>CONTACT US</li>
</ul>
</li>
<li>
CRISIS & SUPPORT
<ul>
<li>FIND COMMUNITY</li>
<li>BASIC RIGHTS</li>
<li>HEALTH</li>
<li>RESOURCES FOR</li>
<ul class="submenu">
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<li>Category 4</li>
<li>Category 5</li>
</ul>
</li>
<li>FOR EDUCATORS</li>
</ul>
</li>
<li>
GET INVOLVED
<ul>
<li>VOLUNTEER</li>
<li>JOIN PEER EDUCATION</li>
<li>BECOME A SAGE AFFILIATE</li>
<li>GET WRRC UPDATES</li>
<li>STUDENT STAFF POSITIONS</li>
</ul>
</li>
<li>
</li>
</ul>
</div>
</div>
Thank you for your time!

On you stylesheet (line 72) change
.nav ul li:hover ul {
display: block;
}
to
.nav ul li:hover > ul {
display: block;
}
You also have a submenu improperly nested. The closing tag for "Resources For" should come after the submenu -- you probably know that.
Codepen: http://codepen.io/SteveClason/pen/oxRyxY

Related

How to create sub menu in side menu in html & css

I have 1 side menu in my main page of website. And some of the list have have sub menu. And on hover i want to display it. Firstly i am display it none and then on display it on hover but it is not displaying.
#menu {
width: 15%;
height: 100%;
background: #424242;
color: white;
float: left;
}
#menu ul {
margin: 0;
padding: 0;
}
#menu li {
list-style: none;
font-size: 20px;
padding: 15px 20px;
cursor: pointer;
}
#menu li:hover {
background-color: #90CAF9;
}
#menu li.active {
background-color: #2196F3;
}
#menu li ul {
display: none;
}
#menu li:hover ul {
display: block;
position: absolute;
left:100%
}
<div id="menu">
<ul>
<li onClick="Dashboard();">Dashboard</li>
<li>Employee >
<ul>
<li>Add Employee</li>
<li>Employee View</li>
</ul>
</li>
<li>Leave</li>
<li>Salary</li>
<li>Change Password</li>
</ul>
</div>
#menu {
width: 150px;
height: 100%;
background: #424242;
color: white;
float: left;
}
#menu ul {
margin: 0;
padding: 0;
}
#menu li {
list-style: none;
font-size: 20px;
padding: 15px 20px;
cursor: pointer;
}
#menu li:hover {
background-color: #90CAF9;
}
#menu li.active {
background-color: #2196F3;
}
#menu ul li ul {
display: none;
}
#menu ul li.submenu {
position: relative
}
#menu ul li.submenu ul {
position: absolute;
left: 150px;
width: 200px;
top: 0;
background: #333
}
#menu ul li.submenu:hover ul {
display: inline-block
}
<div id="menu">
<ul>
<li onClick="Dashboard();">Dashboard</li>
<li class="submenu">Employee >
<ul>
<li>Add Employee</li>
<li>Employee View</li>
</ul>
</li>
<li>Leave</li>
<li class="submenu">Salary
<ul>
<li>Add Employee</li>
<li>Employee View</li>
</ul>
</li>
<li>Change Password</li>
</ul>
</div>
Also Add .submenu class to submenu dropdown parent li.

html css ul and button issue

Hi so in this my explore more button and my ul list so whenever I move my explore button line height the ul and button both move together side..and I want the explore more button downward. what should I do?? I tried using other attributes but nothing worked. I am making this website for my dad's academy.
Here is my HTML code
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<div class="row">
<div>
<ul class="main-nav">
<li>Home</li>
<li>About</li>
<li>Study Visa
<ul>
<li>Australia</li>
<li>Canada</li>
<li>New Zealand</li>
</ul>
</li>
<li>Courses
<ul>
<li>Ielts</li>
<li>PTE</li>
<li>Spoken English</li>
</ul>
</li>
<li>Contact Us
</li>
<li> Login </li>
<li>Reviews</li>
</ul>
</div>
<div class="button">
Explore More
</div>
</div>
</header>
</header>
</body>
this is my CSS code
body {
background: url(abc.jpg) no-repeat;
background-size: none;
background-position : none;
background-size : cover;
margin-left: 20%;
}
.main-nav
{
margin: 0px;
padding: 0px;
list-style: none;
font-family: arial;
position: absolute
top : 20px;
}
.main-nav li {
float: left;
width: 145px;
height: 67px;
background-color: black;
opacity: 0.8;
line-height: 67px;
text-align: center;
font-size: 22px;
margin-left : px;
}
.main-nav li a {
text-decoration: none;
color: white;
display: block;
line-height : 100 px ;
}
.main-nav li a:hover {
background-color: orange;
}
.main-nav li ul li{
display: none;
}
.main-nav li:hover ul li {
display: block;
}.button
{
margin-top: 350px;
margin-left: 320px;
}
.btn
{
border: 1px solid white;
padding: 10px 30px;
color: white;
text-decoration: none;
margin-right: 89px;
font-size: 13px;
text-transform: uppercase;
}
.btn-two
{
font-family: "Roboto", sans-serif;
}
.btn-two:hover
{
background-color: darkorange;
transition: all 0.5s ease-in;
}
so I want the menu above near k academy logo.. and explore more button where it is. thanks!!
I changed up your HTML structure since there were empty tags and random closing tags. CSS i basically just removed the float on the li, since that takes it out of the flow, and instead added flexbox to the ul. Hope that helps flexbox ftw. Idk how your button ended up in that location but I would use position: absolute on that top,right,bottom,left:0 margin: auto;
body {
background: url(abc.jpg) no-repeat;
background-size: none;
background-position: none;
background-size: cover;
}
.main-nav {
display: flex;
justify-content: space-between;
alig margin: 0px;
padding: 0px;
list-style: none;
font-family: arial;
}
.main-nav li {
width: 145px;
height: 67px;
background-color: black;
opacity: 0.8;
line-height: 67px;
text-align: center;
font-size: 22px;
margin-left: px;
}
.main-nav li a {
text-decoration: none;
color: white;
display: block;
line-height: 100 px;
}
.main-nav li a:hover {
background-color: orange;
}
.main-nav li ul li {
display: none;
}
.main-nav li:hover ul li {
display: block;
}
.button {
margin-top: 350px;
margin-left: 320px;
}
.btn {
border: 1px solid white;
padding: 10px 30px;
color: white;
text-decoration: none;
margin-right: 89px;
font-size: 13px;
text-transform: uppercase;
}
.btn-two {
font-family: "Roboto", sans-serif;
}
.btn-two:hover {
background-color: darkorange;
transition: all 0.5s ease-in;
}
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<header>
<ul class="main-nav">
<li>Home</li>
<li>About</li>
<li>Study Visa
<ul>
<li>Australia</li>
<li>Canada</li>
<li>New Zealand</li>
</ul>
</li>
<li>Courses
<ul>
<li>Ielts</li>
<li>PTE</li>
<li>Spoken English</li>
</ul>
</li>
<li>Contact Us
</li>
<li> Login </li>
<li>Reviews</li>
</ul>
<div class="button">
Explore More
</div>
</header>
</body>
I hope this will help you to solve the problem.
.main-menu {
background-color: #444;
}
.main-menu nav ul {
margin: 0;
padding: 0;
}
.main-menu nav > ul > li {
display: inline-block;
position: relative;
margin: 0;
}
.main-menu nav > ul > li a {
display: block;
color: #fff;
font-size: 16px;
padding: 20px 15px;
text-decoration: none;
transition: .3s;
}
.main-menu nav > ul > li:hover > a {
color: #7AA93C;
}
.main-menu nav ul li ul {
position: absolute;
padding: 10px 0;
width: 200px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
top: 150%;
opacity: 0;
visibility: hidden;
transition: .3s;
}
.main-menu nav ul li:hover ul {
top: 100%;
opacity: 1;
visibility: visible;
}
.main-menu nav ul li ul li {
display: block;
padding: 0;
margin: 0;
}
.main-menu nav ul li ul li a {
display: block;
text-decoration: none;
padding: 6px 20px;
font-size: 14px;
color: #444;
transition: .3s;
}
.main-menu nav ul li ul li:hover a {
color: #7AA93C;
}
<div class="main-menu">
<nav>
<ul>
<li>
Home
<!-- submenu start -->
<ul class="submenu">
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
</ul>
<!-- submenu end -->
</li>
<li>About</li>
<li>
Service
<!-- submenu start -->
<ul class="submenu">
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
<li>Sub Menu</li>
</ul>
<!-- submenu end -->
</li>
<li>Contact</li>
</ul>
</nav>
</div>

CSS Dropdown-menu not displaying when <li>-element is hovered.

I have a top navigation bar with 4 options, where I wish that while the fourth option is hovered, a dropdown-menu will display.
The navigation bar is an unordered list, and the dropdown-menu (which should be activated by the fourth option) is a div consisting of 3 links.
The list item that is supposed to display the dropdown-menu while hovered:
<li class="dropdownbutton">Contact</li>
With the help of this line of code:
.dropdownbutton:hover .dropdowncontent {
display:inline-block;
}
And this is the CSS for the dropdown-content:
.dropdowncontent {
display:none;
background-color:#333;
margin-left:272px;
width:90px;
text-align:center;
}
What am I missing?
This should be allright.
ul {
margin: 0;
padding: 0;
list-style: none;
background-color: #333;
}
ul li {
display: inline-block;
position: relative;
text-align: left;
background-color: #333;
}
ul li a {
display: block;
color: #f2f2f2;
text-align: center;
padding: 16px 15px;
text-decoration: none;
transition-duration: 0.3s;
-webkit-transition-duration: 0.3s;
font-size: 17px;
font-family: Arial;
}
ul li a:hover {
background-color: #555;
}
ul li ul.dropdown {
min-width: 100%;
display: none;
position: absolute;
z-index: 999;
left: 0;
width: 90px;
}
ul li:hover ul.dropdown {
display: block;
}
ul li ul.dropdown li {
display: block;
}
ul li ul.dropdown li a {
font-size: 14px;
padding: 10px 15px;
}
<ul>
<li>Home</li>
<li>About Us</li>
<li>Products</li>
<li>Contact
<ul class="dropdown">
<li>Option 1</li>
<li>Option 2</li>
<li>Option 3</li>
</ul>
</li>
</ul>

fix responsive mobile menu

i have a menu i'm developing at this link:
http://events.discoverportland.net/
The menu should load to a blue square just to the right of the discover portland logo. There are serveral nested ul's in the menu, the problem i'm having is getting them to load to the side of the menus above them As it load now, you can't get to the teritairy links unless you move VERY fast.
Is there any way to get the uls to load inline as i'm hovering over them, or is there a better solution?
this my nav html:
<nav>
<div class="clearfix hd8 suckerfish" >
<ul id="md">
<li>Home2</li>
<li>Neighborhoods
<ul>
<li>Northwest
<ul>
<li>Pearl District</li>
<li>Oldtown-Chinatown </li>
<li>Nob Hill</li>
</ul>
</li>
<li>Southwest
<ul>
<li>West End</li>
<li>Riverplace-South Waterfront</li>
<li>Downtown</li>
</ul>
</li>
<li>Southeast
<ul>
<li>Sellwood-Westmoreland</li>
<li>Hawthorne</li>
<li>Clinton-Division</li>
</ul>
</li>
<li>Northeast
<ul>
<li>Alberta</li>
<li>Lloyd District</li>
<li>Hollywood District</li>
</ul>
</li>
<li>North
<ul>
<li>Mississippi</li>
<li>Williams</li>
<li>St. Johns</li>
</ul>
</li>
</ul>
</li>
<li>Itineraries</li>
<li>Day Trips</li>
<li>Food+Drink
<ul>
<li>Dining Picks</li>
<li>Food Cart Fare </li>
<li>Beer, Wine & Spirits</li>
<li>Café Culture</li>
</ul>
</li>
<li>To Do
<ul>
<li>Shopping</li>
<li>Recreation</li>
<li>Culture
<ul>
<li>Galleries</li>
</ul>
</li>
<li>Family</li>
</ul>
</li>
<li>Events</li>
</ul>
</nav>
this is the css i'm using:
nav ul ul li a::before {
content: "\f0da";
font-family: FontAwesome;
margin-right: 8px;
}
nav {
text-transform:uppercase;
font-family: Oswald,Arial,Helvetica,sans-serif !important;
font-size: 14px;
font-weight: 100 !important;
letter-spacing: 1px!important;
}
nav ul ul {
display: none;
}
nav ul li:hover > ul {
display: block;
}
nav ul {
background: #FF0066;
padding: 2px 0 0 64px;
border-radius: 0px;
list-style: none;
position: relative;
display: inline-table;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li {
float: left;
}
nav ul li:hover {
background: #FF0066;
}
nav ul li:hover a {
color: #fff;
}
nav ul li a {
display: block; padding: 15px 20px;
color: #fff; text-decoration: none;
}
nav ul ul {
background: #FF0066; border-radius: 0px; padding: 0;
position: absolute; top: 100%;
}
nav ul ul li {
float: none;
position: relative;
}
nav ul ul li a {
padding: 15px 25px;
color: #fff;
font-family: 'Fira Sans', sans-serif;Important;
font-size: 12px;
}
nav ul ul li a:hover {
background: #AD0548;
}
nav ul ul ul {
position: absolute; left: 100%; top:0;
}
nav ul ul ul li {
width: 275px !important;
}
#media (max-width: 767px) {
#logo a {
background: rgba(0, 0, 0, 0) url("http://discoverportland.net/templates/urbanlife/images/logos/DP_HeadingLogo2.png") no-repeat scroll 0 0 / 100% auto;
height: 60px;
margin: 0 !important;
width: 60px !important;
}
#menu-icon {
display:inline-block;
}
nav ul, nav:active ul {
display: none;
position: absolute;
right: 20px;
top: 60px;
width: 50%;
border-radius: 4px 0 4px 4px;
}
nav li {
text-align: center;
width: 100%;
padding: 10px 0;
margin: 0;
}
nav:hover #md {
display: inline-block;
}
}

Why doesn't this sub navigation element fill the entire area?

I've tried everything I can do get the "Rentals" element to fill the entire width of the dropdown menu, but nothing seems to work. Any ideas? I've tried modifying widths, using nowrap, etc... nothing seems to work (ps. this is part of a custom responsive design so if something seems out of place it might be because I'm resetting something that was previously defined)
nav ul {
display: inline;
width: auto;
position: relative;
top: 70px;
list-style-type: none;
padding: 0px;
margin: 0px;
font-family: Raleway, Arial, sans-serif;
z-index: 10;
}
nav ul li {
display: inline-block;
position: relative;
width: auto;
list-style-type: none;
background-color: transparent;
padding: 0px;
}
nav ul li a {
display: inline;
color: #FFF;
font-size: 14px;
padding: 5px 5px;
text-decoration: none;
border-bottom: none;
}
nav ul a:hover,
nav ul a:active {
background-color: #9a1414;
}
nav ul ul {
display: none;
position: absolute;
top: 26px;
left: 0px;
z-index: 10;
}
nav ul li:hover > ul {
display: block;
background: #333;
border-top: 1px solid #666;
}
nav ul ul li {
float: left;
display: block;
margin-top: 5px;
margin-bottom: 5px;
}
<nav>
<ul id="nav">
<li>
Search
<ul>
<li>Search MLS
</li>
<li>Commercial
</li>
<li>Rentals
</li>
</ul>
</li>
<li>Agents
</li>
<li>Property Management
</li>
<li>Open Houses
</li>
<li>Local
</li>
<li>Blog
</li>
<li>Contact
</li>
</ul>
</nav>