I have a header composed of navigation links to other websites, some of these links are shown through drop-down menus.
With the event hover I have added an animation and style to see what you are on at every moment and that, in case of a drop-down, shows you all the options.
The thing is that I don't know how to keep the drop-down menu displayed to select any of the links and that it disappears in case of #mouseleave.
I have tried to take the event #mouseleave to the dropdown itself but it doesn't work.
If someone can make me see my mistake.
Thanks in advance for your time and help.
I leave you a link with a sample which I have it working now
https://codepen.io/carlosurra/pen/YzqXjdP
this is my template
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.18/vue.min.js"></script>
<div id="row">
<div class="col-xs-12">
<header>
<nav class="navbar navbar-expand-lg navbar-light header">
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav menu">
<li class="nav-item">
<a class="nav-link">PERSONAL INFO</a>
</li>
<li class="nav-item">
<a class="nav-link menu-link-toggle" #mouseover="animalList = true" #mouseleave="animalList = false" >PERSONAL FORM</a>
<ul class='dropdown-menu' v-if="animalList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>FORM DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >AUTOCOMPLETE</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class='menu-link menu-link-toggle' #mouseover="serviceList = true" #mouseleave="serviceList = false">SERVICES</a>
<ul class='dropdown-menu' v-if="serviceList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >LA CRÉMATION PRIVÉE</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' href="https://www.esthima.fr/incineration-reference">PERSONAL S</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>COMPANY S</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >FULL S INFO</a>
</li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link ">SHOP</a>
</li>
<li class="nav-item active">
<router-link class="nav-link" to="/devis">TARIFS ET DEVIS </router-link>
</li>
<li class="nav-item">
<a class='menu-link menu-link-toggle' #mouseover="contactList = true" #mouseleave="contactList = false">CONTACT</a>
<ul class='dropdown-menu' v-if="contactList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>MAIL</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >PHONE</a>
</li>
</ul>
</li>
</ul>
</div>
</nav>
</header>
</div>
</div>
this is my css
.header {
display: flex;
justify-content: center;
align-items: baseline;
}
.menu {
list-style: none;
display: flex;
align-items: center;
}
.nav-item {
padding: 25px;
position: relative;
}
.nav-link:hover {
color: grey;
}
.menu-link-toggle {
cursor: pointer;
}
.dropdown-menu {
margin-top: 10px;
list-style: none;
position: absolute;
padding: 1em 1.25em 0.5em 0.75em;
background-color: white;
width: max-content;
box-shadow: 0px 14px 24px 0px rgba(0,0,0,0.21);
}
.dropdown-menu-item {
margin: 20px 0 20px 0;
}
.dropdown-menu-link {
font-size: 14px;
font-weight: bold;
color: red;
text-decoration: none;
}
.head {
font-size: 14px;
color: red;
font-weight: bold;
text-decoration: none;
}
.head:before {
content: '';
position: absolute;
width: 30%;
height: 3px;
bottom: 30%;
left: 35%;
background: red;
visibility: hidden;
border-radius: 5px;
transform: scaleX(0);
transition: .25s linear;
}
.head:hover:before,
.head:focus:before {
visibility: visible;
transform: scaleX(1);
}
.added {
display: none;
}
Put the mouseover and mouseleave events on the <li> element that contains both the link and the dropdown.
<li class="nav-item" #mouseover="animalList = true" #mouseleave="animalList = false">
<a class="nav-link menu-link-toggle">PERSONAL FORM</a>
<ul class='dropdown-menu' v-if="animalList">
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link'>FORM DATA</a>
</li>
<li class='dropdown-menu-item'>
<a class='dropdown-menu-link' >AUTOCOMPLETE</a>
</li>
</ul>
</li>
Related
I have a checkbox that when it is clicked, it's meant to move my nav bar to the left, but nothing happenes. I've checked the property in F12 (Chrome) and when I check the box, the checked property stays false. Any ideas? Code is below.
#toggle:checked + .nav-links {
transform: translateX(0%);
}
.nav-links {
position: absolute;
right: 0px;
top: 0px;
height: 100vh;
background: #009af3;
display: flex;
flex-direction: column;
align-items: center;
z-index: 4;
transform: translateX(100%);
}
.
<nav>
<div class="logo-container">
<img src="/images/Business/logo.png" alt="LPS Logo">
</div>
<ul class="nav-links">
<li><a class="nav-link active" href="#">Home</a></li>
<li><a class="nav-link" href="#">Production</a></li>
<li><a class="nav-link" href="#">Dry Hire</a></li>
<li><a class="nav-link" href="#">Installation</a></li>
<li><a class="nav-link" href="#">About Us</a></li>
<li><a class="nav-link" href="#">Contact</a></li>
</ul>
<div class="burger">
<label for="toggle">☰</label>
<input type="checkbox" id="toggle"/>
</div>
</nav>
Your problem is that in CSS you use + which means apply this to all rules that are next to in your case toggle-Element. So to actually see the navigation you have to move it next to the toggle-element in the HTML:
#toggle:checked+.nav-links {
transform: translateX(0%);
}
.nav-links {
position: absolute;
right: 0px;
top: 0px;
height: 100vh;
background: #009af3;
display: flex;
flex-direction: column;
align-items: center;
z-index: 4;
transform: translateX(100%);
}
<nav>
<div class="logo-container">
<img src="/images/Business/logo.png" alt="LPS Logo">
<input type="checkbox" id="toggle" />
<ul class="nav-links">
<li><a class="nav-link active" href="#">Home</a></li>
<li><a class="nav-link" href="#">Production</a></li>
<li><a class="nav-link" href="#">Dry Hire</a></li>
<li><a class="nav-link" href="#">Installation</a></li>
<li><a class="nav-link" href="#">About Us</a></li>
<li><a class="nav-link" href="#">Contact</a></li>
</ul>
</div>
<div class="burger">
<label for="toggle">☰</label>
</div>
</nav>
<style type="text/css">
#parent:hover #abc{
display: block ;
}
</style>
The :hover in this is not working
The following was the code used. Whenever the mouse hovers over #parent #abc should be displayed. But this it is not happening so.
<a class="w3-bar-item w3-button" id="parent">LIK2</a>
<ul style="list-style-type: none;margin: 0px; margin-left:100px;position: absolute; top: 0px; padding: 0px; background-color:green; display: none" id="abc" class="w3-bar-block">
<li class="w3-bar-item w3-button">Link1 </li>
<li class="w3-bar-item w3-button">Link1</li>
<li class="w3-bar-item w3-button">Link1</li>
</ul>
please can someone figure out the problem.
EDIT:
Entire code
<div class="w3-dropdown-hover" style="width: 50%;">
<button class="w3-button">SomeButton</button>
<div class="w3-bar-block w3-black w3-dropdown-content " id="xyz" style="width: 100px; ">
<a class="w3-bar-item w3-button">LIK1</a>
<div style="margin:0px; padding: 0px; position: relative;" id="parent">
<a class="w3-bar-item w3-button">LIK2</a>
<ul style="list-style-type: none;margin: 0px; margin-left:100px;position: absolute; top: 0px; padding: 0px; background-color:green; display: none" id="abc" class="w3-bar-block">
<li class="w3-bar-item w3-button">
Link1
</li>
<li class="w3-bar-item w3-button">
Link1
</li>
<li class="w3-bar-item w3-button">
Link1
</li>
</ul>
</div>
<a class="w3-bar-item w3-button">LIN3</a>
</div>
</div>
because you set inline style for #abc and never let you set other style in head , you should set #abc style in a head , like this :
CSS:
<style type="text/css">
#abc {
list-style-type: none;
margin: 0px;
margin-left: 100px;
position: absolute;
top: 0px;
padding: 0px;
background-color: green;
display: none;
}
div#parent:hover > ul#abc {
display: block;
}
</style>
HTML :
<div id="parent">
<a class="w3-bar-item w3-button">LIK2</a>
<ul id="abc" class="w3-bar-block">
<li class="w3-bar-item w3-button">Link1 </li>
<li class="w3-bar-item w3-button">Link1</li>
<li class="w3-bar-item w3-button">Link1</li>
</ul>
</div>
Use adjacent sibling selector(+) or general sibling selector(~) to select the siblings. Check below snippet for reference. Check here for more details about Combinators selectors.
#parent:hover ~#abc{
display: block !important;
}
<a class="w3-bar-item w3-button" id="parent">LIK2</a>
<ul style="list-style-type: none;margin: 0px; margin-left:100px;position: absolute; top: 0px; padding: 0px; background-color:green; display: none" id="abc" class="w3-bar-block">
<li class="w3-bar-item w3-button">Link1 </li>
<li class="w3-bar-item w3-button">Link1</li>
<li class="w3-bar-item w3-button">Link1</li>
</ul>
try like this, you can give appropriate ids as you needed to do so.
li:hover ul{
display: block !important;
}
<ul style="" id="abc" class="w3-bar-block">
<li>
LIK2<br>
<ul id="inner" style="list-style-type: none;margin: 0px; margin-left:100px;position: absolute; top: 0px; padding: 0px; background-color:green; display: none">
<li class="w3-bar-item w3-button">Link1 </li>
<li class="w3-bar-item w3-button">Link1</li>
<li class="w3-bar-item w3-button">Link1</li>
</ul>
</li>
</ul>
hope this helps
I have tried couple solutions, but nothing that is working as I intended so far. I just want the links to be in the same level of indentation and in a block level manner. I am trying to get this accomplish without using absolute positioning, otherwise it breaks the rest of the code. Any help would be appreciated.
body {
margin-left: 40px; }
.bookmarks {
border: 1px solid gray;
width: 200px; }
.bookmarks ul {
list-style-type: none; }
.link4 {
box-sizing: border-box;
display: inline-block;
background-color: pink; }
.link4 .left-side {
height: 100%;
width: 80%;
color: white;
background-color: blue;
float: left; }
.link4 .right-side {
height: 100%;
width: 20%;
background-color: yellow;
float: right; }
.second-menu li {
background-color: lightgreen; }
.last-menu li {
background-color: lightgray; }
/*# sourceMappingURL=test2.css.map */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet"/>
<div class="col-md-6">
<div class="bookmarks">
<ul class="nav top-menu" id="affix-ul">
<li class="link1">
<a href="#">
Some Text on link 1
</a>
</li>
<li class="link2">
<a href="#">
Some Text on link 2
</a>
</li>
<li class="link 3">
<a href="#">
Some Text on link 3
</a>
</li>
<li class="link4 active">
<div class="left-side">
<a href="#">
<span>Some Text on link 4</span>
</a>
</div>
<div class="right-side">
<a href="#" class="arrow-up" aria-hidden="true" data-toggle="collapse" data-target="#hiddenMenuOne">
<i class="fa fa-chevron-down"> ^
</i>
</a>
</div>
<ul id="hiddenMenuOne" class="collapse second-menu">
<li>
Sublink1
</li>
<li>
Sublink2
</li>
<li>
This is a sublink3 with a bit more text
</li>
<li>
sublink4
</li>
<li>
sublink5
</li>
<li>
sublink6
</li>
<li class="second-level-menu wrapper">
<div class="left-side">
<a href="#" class="">
Last sublink on submenu
</a>
</div>
<div class="right-side">
<a href="#" class="second-dropdown" aria-hidden="true" data-toggle="collapse" data-target="#hiddenMenuTwo">
<i class="fa fa-chevron-down">^
</i>
</a>
</div>
<ul id="hiddenMenuTwo" class="collapse last-menu">
<li>
Tertiary 1
</li>
<li>
Tertiary 2
</li>
<li>
Tertiary 3 with a second line
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
Just in case anyone wants to know the answer. I just removed the padding-left of the li and added a height property to the uls
Okay so here's the deal I made this navigation bar, thanks to a tutorial online, with the code below, everything works BUT the drop down menu, I hover over and nothing happens I've been slaving over this for hours! Thank you very much in advance for anyone's help! I know I'm close to getting it right but I just can't figure it out! Again thank you in advance for your help.
<style>
header { font-family: 'blades_gf_freeregular', Futura, Arial, sans-serif; }
nav { height: 41px; background: linear-gradient( #1e7995, #1c2c3f); }
nav ul { margin: 0; }
nav, ul.submenu { background: linear-gradient( #1e7995, #1c2c3f); border-radius: 5px; padding: 0; }
nav ul li { display: block; width: 150px; text-align: center; float: left; margin: 0; padding: 0; }
nav li:hover { background: rgba(0,0,0,0.4); }
nav a { color:#fff; text-decoration: none; display: block; padding: 10px; }
nav ul.submenu { background: rgba(0,0,0,0.8); position: relative; boredr-radius: 0 0 5px 5px; height: 0px; overflow: hidden; }
nav ul.submenu li { float: none; text-align: left; border-bottom: 1px solid rbga(0,0,0,0.3); }
nav ul li { transition: .3s all linear; }
nav ul li:hover ul.submenu { height: 126px; }
</style>
<header>
<p><img src="assets/images/header32.png" alt="before and after effects title image"/></p>
<nav role="navigation" aria-label="Main menu">
<ul role="menubar">
<li role="menuitem" tabindex="0">Home</li>
<li role="menuitem" aria-haspopup=true tabindex="0">Tutorials</li>
<ul class="submenu" role="menu" aria-hidden=true>
<li role="menuitem" tabindex="-1">Pre-Production</li>
<li role="menuitem" tabindex="-1">Production</li>
<li role="menuitem" tabindex="-1">Post</li>
</ul>
<li role="menuitem" tabindex="0">Films</li>
</ul>
</nav>
</header>
You need to move sub menu ul inside the menu li
<header>
<p><img src="assets/images/header32.png" alt="before and after effects title image"/></p>
<nav role="navigation" aria-label="Main menu">
<ul role="menubar">
<li role="menuitem" tabindex="0">Home</li>
<li role="menuitem" aria-haspopup=true tabindex="0">Tutorials
<ul class="submenu" role="menu" aria-hidden=true>
<li role="menuitem" tabindex="-1">Pre-Production</li>
<li role="menuitem" tabindex="-1">Production</li>
<li role="menuitem" tabindex="-1">Post</li>
</ul>
</li>
<li role="menuitem" tabindex="0">Films</li>
</ul>
</nav>
</header>
DEMO
You have prematurely closed the parent <li> element that the submenu should belong to.
http://jsfiddle.net/GL87s/
<header>
<p><img src="assets/images/header32.png" alt="before and after effects title image"/></p>
<nav role="navigation" aria-label="Main menu">
<ul role="menubar">
<li role="menuitem" tabindex="0">Home</li>
<li role="menuitem" aria-haspopup=true tabindex="0">Tutorials
<ul class="submenu" role="menu" aria-hidden=true>
<li role="menuitem" tabindex="-1">Pre-Production</li>
<li role="menuitem" tabindex="-1">Production</li>
<li role="menuitem" tabindex="-1">Post</li>
</ul></li>
<li role="menuitem" tabindex="0">Films</li>
</ul>
</nav>
</header>
Fixes it.
The only children a <ul> should have is <li>s. Not another <ul>.
You're really close. Judging by your CSS, the ul.submenu should be inside the <li> it belongs to. Just move it inside the <li>. Here's a jsfiddle with the change:
http://jsfiddle.net/8WGKU/
Keep submenu inside <li>
<li role="menuitem" aria-haspopup=true tabindex="0">Tutorials
<ul class="submenu" role="menu" aria-hidden=true>
<li role="menuitem" tabindex="-1">Pre-Production</li>
<li role="menuitem" tabindex="-1">Production</li>
<li role="menuitem" tabindex="-1">Post</li>
</ul>
</li>
Fiddle here.
I have created a site-map using the following HTML:
<ul class="main-menu">
<li>
<div>
Menu Item 1
<ul class="actions">
<li>
<a
title="Collapse"
href="#"
class="icon icon-bullet-toggle-minus"
>Collapse</a>
</li>
<li>
<a
title="Add to Favourites"
href="#"
class="icon icon-award-star-add"
>Add to Favourites</a>
</li>
</ul>
</div>
<ul class="child-nodes">
<li>
<div>
Menu Item 1's First Child
<ul class="actions">
<li>
<a
title="Open"
href="#"
class="icon icon-page"
>Open</a>
</li>
<li>
<a
title="Add to Favourites"
href="#"
class="icon icon-award-star-add"
>Add to Favourites</a>
</li>
</ul>
</div>
</li>
<li>
<div>
<a href="#">A menu item with a really long name that is
eventually going to wrap over and break my styling</a>
<ul class="actions">
<li>
<a
title="Open"
href="#"
class="icon icon-page"
>Open</a>
</li>
<li>
<a
title="Add to Favourites"
href="#"
class="icon icon-award-star-add"
>Add to Favourites</a>
</li>
</ul>
</div>
</li>
</ul>
</li>
<li>
<div>
Menu Item 2
<ul class="actions">
<li>
<a
title="Expand"
href="#"
class="icon icon-bullet-toggle-plus"
>Expand</a>
</li>
<li>
<a
title="Add to Favourites"
href="#"
class="icon icon-award-star-add"
>Add to Favourites</a>
</li>
</ul>
</div>
</li>
<li>
<div>
Menu Item 3
<ul class="actions">
<li>
<a title="Open" href="#" class="icon icon-page">Open</a>
</li>
<li>
<a
title="Add to Favourites"
href="#"
class="icon icon-award-star-add"
>Add to Favourites</a>
</li>
</ul>
</div>
</li>
</ul>
and the following CSS:
.main-menu {
list-style: none;
padding: 0;
width: 405px;
}
.main-menu div {
padding: 5px;
}
.main-menu div a {
color: #036;
padding: 5px;
padding-left: 0;
text-decoration: none;
}
.main-menu .actions {
float: left;
margin: 0;
margin-right: 3px;
padding: 0;
}
.main-menu .actions li {
display: inline;
list-style: none;
}
.main-menu .actions a {
outline: none;
padding: 0;
text-indent: -9999px;
}
.main-menu .child-nodes {
list-style: none;
padding-left: 41px;
}
.main-menu .space {
margin-top: 16px;
}
The issue is that as soon as the text of a menu item becomes wider than the 405 pixel width of the menu, the item no longer wraps correctly.
Instead of the text flowing underneath the "actions" list, the text flows over the "actions" list.
I want to have something similar to:
[some icon] [another icon] item text
that wraps around
But instead I get:
item text that wraps
[some icon] [another icon] around
If you would like to see the problem in action, here's an example of the issue.
Any ideas?
If I understand correctly what you want to achieve, then you must simply remove float: left; from .main-menu .actions:
.main-menu .actions {
margin: 0;
margin-right: 3px;
padding: 0;
}
Is this the desired result?
The first thing I notice is that the <a> tag comes before the <ul class="actions"> tag. Have you tried reversing the order of the tags?
I currently can't try it out, but if you want the icons to appear before the text, I'd order the tags the same way. Not sure if this will solve the issue, though.
Edited to add: I just run a quick test. Changing
<A href="http://robertwhittaker.com/example/#">A menu item with a really long name that is
eventually going to wrap over and break my styling</A>
<UL class="actions">
<LI>
<A title="Open" href="http://robertwhittaker.com/example/#" class="icon icon-page">Open</A>
</LI>
<LI>
<A title="Add to Favourites" href="http://robertwhittaker.com/example/#" class="icon icon-award-star-add">Add to Favourites</A>
</LI>
</UL>
to...
<UL class="actions">
<LI>
<A title="Open" href="http://robertwhittaker.com/example/#" class="icon icon-page">Open</A>
</LI>
<LI>
<A title="Add to Favourites" href="http://robertwhittaker.com/example/#" class="icon icon-award-star-add">Add to Favourites</A>
</LI>
</UL>
<A href="http://robertwhittaker.com/example/#">A menu item with a really long name that is
eventually going to wrap over and break my styling</A>
seemed to solve your problem (if I understood it correctly).
With help from RegDwight and Anne Schuessler, I think I have now solved this issue.
The first step was to swap link and the "actions" list around so that it now appears as:
<div>
<ul class="actions">
<li>
<a class="icon icon-page" href="#" title="Open">Open</a>
</li>
<li>
<a
class="icon icon-award-star-add"
href="#"
title="Add to Favourites"
>Add to Favourites</a>
</li>
</ul>
Menu Item
</div>
From there it was just a case of slightly adjusting the CSS so that the link text was always inline instead of wrapping underneath the "actions" menu.
The complete CSS is as follows:
.main-menu {
list-style-type: none;
padding: 0;
width: 405px;
}
.main-menu div {
padding: 5px 5px 5px 46px;
}
.main-menu div a {
color: #036;
text-decoration: none;
}
.main-menu .actions {
float: left;
margin: 0 3px 0 -41px;
padding: 0;
}
.main-menu .actions li {
display: inline;
list-style-type: none;
}
.main-menu .actions a {
outline-style: none;
text-indent: -9999px;
}
.main-menu .child-nodes {
list-style-type: none;
padding-left: 41px;
}
.main-menu .space {
margin-top: 16px;
}
It was just a case of padding the container div by the width of the "actions" list and then giving the "actions" list a negative left-margin of the same value.