Hover with id not working - css

<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

Related

How to keep a dropdown displayed after showing with hover event?

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>

CSS: how to center a list with image

How do I center an unordered list that is divided with an image inside?
I want to achieve that the unordered list is one row, centered and also the image inside is centered so that the image divides the rest of the list in two halves (topnav-left and topnav-right).
My HTML:
<ul class="nav">
<div class="topnav-left">
<li class="">
<a class="toggle-nav" data-no-turbolink="true" href="Women">Women</a>
</li>
<li class="">
<a class="toggle-nav" data-no-turbolink="true" href="Men">Men</a>
</li>
<li class="">
Stores
</li>
<li class="">
Lifestyle
</li>
</div>
<div class="nile-logo" style="">
<li>
<img alt="Logo" src="http://img.logospectrum.com/dec/dummy-logo.jpg">
</li>
</div>
<div class="topnav-right">
<li class="">
<a class="toggle-account-nav" data-no-turbolink="true" href="/de/account">My Account</a>
</li>
<li>
<div class="cart">
<a href="/de/cart">
Warenkorb
</a> </div>
</li>
<li>
<a html="{:class=>"open-wishlist"}" href="/de/wishlist">WUNSCHLISTE</a>
</li>
<li class="language">
<a class="language" href="/en/pages/imprint">EN</a>
<a class="language" href="/fr/pages/imprint">FR</a>
</li>
</div>
</ul>
My CSS:
ul.nav { text-align: center; }
ul.nav li { display: inline-block; }
Here a codepen: demo
Try to use display:flex; add this to add this,
ul {display:flex;justify-content: space-around;list-style-type: none;}
ul.nav li { flex:1; text-align: center; } /* Edit from comment by Paulie_D
Working DEMO
You mean like this?:
http://codepen.io/anon/pen/pENYLZ
ul.nav li {
display: block;
}
Or like this?:
http://codepen.io/anon/pen/mAOoKN
ul.nav {
margin: 0 auto;
width: 200px;
position: relative;
}
ul.nav li {
display: block;
}

Bootstrap 3 CenterNav In the Middle of a page

<div class="other center_2">
<div class="container_2">
<nav id="sidebar-wrapper">
<ul class="sidebar-nav">
<a id="menu-close" href="#" class="btn btn-light btn-lg pull-right toggle"><i class="fa fa-times"></i></a>
<li class="sidebar-brand">
</li>
<li>
<a href="#work" onclick = $("#menu-close").click(); >Work</a>
</li>
<li>
<a href="#contact" onclick = $("#menu-close").click(); >Contact</a>
</li>
</ul>
</nav>
</div>
</div>
.centered_2 {
position: fixed; /* or absolute */
top: 50%;
left: 50%;
}
http://shearelegancechicago.com/todd/
I'm trying to center the nav right dab smack in the middle when it opens up. I tried a fewed different tutorials nothing is working. The live link is including.
In CSS you have .centered_2 class - and in HTML you have center_2. Just change to center_2 in CSS and everything will work fine!
.center_2 {
position: fixed; /* or absolute */
top: 50%;
left: 50%;
}
<div class="other center_2">
<div class="container_2">
<nav id="sidebar-wrapper">
<ul class="sidebar-nav">
<a id="menu-close" href="#" class="btn btn-light btn-lg pull-right toggle"><i class="fa fa-times"></i></a>
<li class="sidebar-brand">
</li>
<li>
<a href="#work" onclick = $("#menu-close").click(); >Work</a>
</li>
<li>
<a href="#contact" onclick = $("#menu-close").click(); >Contact</a>
</li>
</ul>
</nav>
</div>
</div>
Here is a demo.
You may also try this.
.sidebar-nav {
/* position: absolute; */ No use.
width: 250px;
margin: 0 auto; /*Set the margin as per your requirement. eg; 50px auto 0px*/
padding: 0;
list-style: none;
border: 1px solid red; /*just to highlight*/
}
Hope this help you.!

Parent li overlaps child li, having absolute uls, relative lis

I am creating a topmenu for a webpage, and with scripting, the sub menus pops up on hover. I have also taken measures to not let the menu grow too far to the right, by if needed let it grow in the other direction. This picture clarifies:
I do this by adding the class "to-the-left" to the sub sub menu.
Now, why is some menu items of the parent on top of my sub sub menu? You can read "Item 3" below "Sub sub item 2" which should not be possible.
I have tried to add z-index to the sub sub menu without succeeding.
http://jsfiddle.net/VK7Mt/
<!doctype html>
<html>
<head>
<style type="text/css">
div.top-menu
{
width: 920px;
margin: 0 auto;
}
div.top-menu ul.topmenu
{
margin: 0;
height: 41px;
background: #ccc;
padding: 0;
position: relative;
}
ul.topmenu li
{
list-style: none;
float: left;
padding: 12px 19px;
min-height: 17px;
position: relative;
}
ul.topmenu ul
{
width: 190px;
position: absolute;
top: 41px;
left: 0;
margin: 0;
padding: 0;
background: #dddddd;
border: #c4c4c4 1px solid;
}
ul.topmenu ul li
{
float: none;
padding: 3px 6px 3px 13px;
}
ul.topmenu a
{
color: #333;
text-decoration: none;
}
ul.topmenu ul li a
{
display: inline-block;
font-weight: normal;
width: 90%;
}
ul.topmenu ul li:hover
{
background: #3399cc;
}
ul.topmenu ul ul
{
left: 100%;
top: 0;
}
ul.topmenu div
{
cursor: pointer;
}
.topmenu-sub-item > .item
{
padding-left: 6px;
}
.topmenu-sub-item > .item > a
{
margin-top: 3px;
margin-bottom: 3px;
}
ul.topmenu ul ul.to-the-left
{
left: -100.5%;
}
</style>
</head>
<body>
<div class="top-menu">
<ul class="topmenu">
<li class="topmenu-root-node">
root item
<ul class="topmenu-submenu-container">
<li class="topmenu-sub-item">
<div class="item">
item 1
</div>
</li>
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/item2">item 2</a>
</div>
<ul class="topmenu-submenu-container to-the-right">
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/subitem1">Sub item 1</a>
</div>
<ul class="topmenu-submenu-container to-the-right">
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/subsubitem1">Sub sub item 1</a>
</div>
</li>
<li class="topmenu-sub-item">
<div class="item">
Sub sub item 2
</div>
</li>
<li class="topmenu-sub-item">
<div class="item">
Sub sub item 3
</div>
</li>
</ul>
</li>
</ul>
</li>
<li class="topmenu-sub-item">
<div class="item">
Item 3
</div>
</li>
</ul>
</li>
</ul>
</div>
<div class="top-menu" style="margin-top: 170px">
<ul class="topmenu">
<li class="topmenu-root-node">
root item
<ul class="topmenu-submenu-container">
<li class="topmenu-sub-item">
<div class="item">
item 1
</div>
</li>
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/item2">item 2</a>
</div>
<ul class="topmenu-submenu-container to-the-right">
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/subitem1">Sub item 1</a>
</div>
<ul class="topmenu-submenu-container to-the-left">
<li class="topmenu-sub-item nonempty">
<div class="item has-submenu">
<a class="topmenu-hassubmenu" href="/subsubitem1">Sub sub item 1</a>
</div>
</li>
<li class="topmenu-sub-item">
<div class="item">
Sub sub item 2
</div>
</li>
<li class="topmenu-sub-item">
<div class="item">
Sub sub item 3
</div>
</li>
</ul>
</li>
</ul>
</li>
<li class="topmenu-sub-item">
<div class="item">
Item 3
</div>
</li>
</ul>
</li>
</ul>
</div>
</body>
</html>
This is because the order of the elements matters: elements that come later in code, are on top of the previous elements.
In your case, the subsubs are a part of the main Item 2 >> are BELOW the afterwards following Item 3.
You can override this using z-index for the sub-menu (not the subsub):
ul.topmenu ul {
...
position:absolute;
z-index:999;
...
}
updated fiddle: http://jsfiddle.net/VK7Mt/3/
Add z-index to:
ul.topmenu ul ul.to-the-left {
z-index: 100;
}
That way you are saying that you want that ul to be in front of other elements. It had position absolute so it needed some z-index.
JSFIDDLE

List item text incorrectly overflowing sub list

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.

Resources