Pure CSS dropdown triggering on hover of wrong element - html

So I have a pure css dropdown menu, but I'm having one problem. The dropdown works when you hover over a link, but it's also triggering when you hover over the actual container that contains the dropdown portion. Here's a jsfiddle with the code. http://jsfiddle.net/9BRac/
<div class="nav-con">
<nav role='navigation' id="nav">
<ul>
<li id="linked">Home</li>
<li>About
<ul class="dropdown">
<li>Link 1.</li>
<li>Link 2.</li>
<li>Link 3</li>
</ul>
</li>
<li>Clients
<ul class="dropdown">
<li>Link 1.</li>
<li>Link 2.</li>
<li>Link 3</li>
</ul>
</li>
<li>Contact Us
<ul class="dropdown">
<li>Link 1.</li>
<li>Link 2.</li>
<li>Link 3</li>
</ul>
</li>
</ul>
</nav>
.clearfix:before,
.clearfix:after {
content: " ";
display: table;
}
.clearfix:after {
clear: both;
}
.clearfix {
*zoom: 1;
}
nav {
width: 100%;
height: 60px;
background-color:black;
border-bottom: #ffd600 solid 10px;
margin: 0 auto;
}
nav ul {
position:inheirt;
}
nav ul li {
transition: all .6s ease-in-out;
-moz-transition: all .6s ease-in-out;
-o-transition: all .6s ease-in-out;
-webkit-transition: all .6s ease-in-out;
width: 80px;
height:60px;
margin-left:10px;
display:;
float: left;
line-height: 60px;
text-align:center;
list-style:none;
position:inherit;
color: white;
text-decoration:none;
}
nav ul li:hover {
width: 80px;
-moz-transition: all .6s ease-in-out;
-o-transition: all .6s ease-in-out;
-webkit-transition: all .6s ease-in-out;
height:60px;
margin-left:10px;
background-color:#ffd600;
float: left;
line-height: 60px;
text-align:center;
list-style:none;
position:inherit;
color: white;
text-decoration:none;
}
nav ul li a {
color: white;
text-decoration:none;
}
html {
background-color: #f2f2f2;
}
#dropdown {
width:100%;
height:200px;
opacity: 0.8;
background-color:black;
display:none;
}
.dropdown {
margin-top:10px;
}
.dropdown li {
width: 300px;
background-color: #ffd600;
}
nav ul ul {
opacity: 0;
transition: all .6s ease-in-out;
-moz-transition: all .6s ease-in-out;
-o-transition: all .6s ease-in-out;
-webkit-transition: all .6s ease-in
}
nav ul li:hover > ul {
opacity: 0.8;
transition: all .6s ease-in-out;
-moz-transition: all .6s ease-in-out;
-o-transition: all .6s ease-in-out;
-webkit-transition: all .6s ease-in-out;
}
nav ul ul li {
opacity: 1.0 !important;
}
nav ul ul li:hover {
width: 350px !important;
}

Use the following
/* Your dropdown */
nav ul ul {
opacity: 0;
visibility:hidden;
transition: opacity .6s ease-in-out;
-moz-transition: opacity .6s ease-in-out;
-o-transition: opacity .6s ease-in-out;
-webkit-transition: opacity .6s ease-in
}
/* Code to display your dropdown */
nav ul li:hover > ul {
opacity: 0.8;
visibility:visible;
}
For a working example go here http://jsfiddle.net/DanielApt/9BRac/12/
Explanation:
Your .dropdown still exists, it just has an opacity of 0.
Whenever you hover over this “invisible” .dropdown you trigger the hover styling for its parent li, which leads to showing .dropdown again.
The solution: set a visibility of hidden for your .dropdown, and set the visibility to visible only when you hover over the parent li
Also only use the transition on the opacity property, then visibility is changed immediately, but the opacity transitions smoothly.
PS: If you're curious why I'm not using display:none, it is because you can't transition display (source for the solution using visibiliy

Try using visibility:hidden instead of editing just the opacity on hover like this:
http://jsfiddle.net/9BRac/18/
Now you can edit a bit the transitions timing to make it smoother.
As well the transition property could be used on opacity only and not on all properties.

Related

Why has my .tabs li:hover property stopped working?

My page no longer applies the :hover effect to my .tabs li element, but I can't for the life of me figure out why. I commented out my jQuery script and it still won't work.
Here's a JSFiddle: https://jsfiddle.net/qpmg4wzq/
<div id="tabs-container">
<ul class="tabs">
<li class="tab current" data-tab="tab-1">tab 1</li>
<li class="tab" data-tab="tab-2">tab 2</li>
<li class="tab" data-tab="tab-3">tab 3</li>
<li class="tab" data-tab="tab-4">tab 4</li>
</ul>
</div>
#tabs-container {
float: left;
width: 100%;
overflow: hidden;
}
.tabs {
padding: 0px;
list-style: none;
clear: left;
float: left;
left: 50%;
}
.tabs li {
display: block;
float: left;
right: 50%;
margin: 0;
padding: 10px 20px 5px 20px;
cursor: pointer;
font-size: 1.1em;
line-height: 2em;
-webkit-transition: color .2s linear;
-moz-transition: color .2s linear;
-ms-transition: color .2s linear;
-o-transition: color .2s linear;
transition: color .2s linear;
-webkit-transition: background .2s linear;
-moz-transition: background .2s linear;
-ms-transition: background .2s linear;
-o-transition: background .2s linear;
transition: background .2s linear;
}
.tabs li:hover {
background: #88abc2!important;
}
.tabs li.current {
background: #d0e0eb;
color: #49708a;
}
.tab-content {
display: none;
padding: 15px;
line-height: 1.4;
}
.tab-content.current {
display: inherit;
}
Thanks.
Your .tab-content is overlapping the .tabs-container so any :hover action you make is actually registering as a hover on the .tab-content element.
A couple of options to solve this
Move the tab-content down using margin-top
.tab-content.current {
display: inherit;
margin-top: 60px;
}
Remove float: left from #tabs-container

Div cover other Div

I am creating a demo for my homework.
My navigation is not displaying correctly. I have been trying to fix the problem in many ways but none of them work.
demo
here is my demo
<body>
<div class="container">
<div class="content">
<div id="menu">
<ul class="parent-menu">
<li>
Home & Kitchen
<ul>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Electronics
<ul>
<li>item</li>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Clothing
<ul>
<li>item</li>
<li>item</li>
<
</ul>
</li>
<li>
Cars & Motorbikes
<ul>
<li>item</li>
<li>item</li>
<
</ul>
</li>
<li>
Books
<ul>
<li>item</li>
<li>item</li>
</ul>
</li>
<li>
Support
<ul>
<li>
Contact Us
</li>
<li>
Forum
</li>
<li>Deliveries</li>
<li>T&C</li>
</ul>
</li>
</ul>
</div>
<!-----------Shorcut Panel Content--------->
<div class="shortcutpanel">
<div class="usergroup">
</div>
</div>
</div>
</body>
Here is my CSS code.
/* Basic Style */
html, body{
height:100%;
}
body {
background-color: grey;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
background-size:cover;
}
/*Global Setting*/
.hover{
float:left;
display: inline-block;
vertical-align: middle;
-webkit-transform: translateZ(0);
transform: translateZ(0);
box-shadow: 0 0 1px rgba(0, 0, 0, 0);
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-moz-osx-font-smoothing: grayscale;
overflow: hidden;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-property: color, background-color;
transition-property: color, background-color;
}
.hover:active, .hover:hover, .hover:focus{
background-color: rgba(32, 152, 209, 0.5);
}
.container{
height:100%;
width:100%;
}
.content{
position:fixed;
top:10%;
left:0%;
height:90%;
width:100%;
}
/* NAVIGATION*/
p, ul, li, div, nav { padding:0; margin:0; }
#menu {
overflow: hidden;
position:fixed ;
left:0%;
top:20%;
z-index:999; }
.parent-menu {
background-color: #0c8fff;
width:180px; }
#menu ul {
list-style-type:none;
}
#menu ul li a {
padding:10px 15px;
display:block;
color:#fff;
text-decoration:none;
}
#menu ul li a:hover {
background-color:#007ee9;
}
#menu ul li:hover > ul {
left: 200px;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#menu ul li > ul {
position: absolute;
background-color: #333;
top: 0;
left: -200px;
min-width: 200px;
z-index: 999;
height: 100%;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
#menu ul li > ul li a:hover {
background-color:#2e2e2e;
}
#menu ul li a:focus + ul {
left: 200px;
-webkit-transition: left 200ms ease-in;
-moz-transition: left 200ms ease-in;
-ms-transition: left 200ms ease-in;
transition: left 200ms ease-in;
}
/* Shortcut Panel Content */
.shortcutpanel{
position:relative;
left:10%;
top:5%;
height:90%;
width:30%;
float:left;
margin:0;
padding:0;
background-color:rgba(255,240,240,0.1);
}
Here this Demo,its the navigation effect that i want.
But however in my first demo.When you hover over the navi menu, the 2nd level menu will come out but display incorrectly. I don't know how to solve this.
Thanks for helps guys
If i get your question right.. U can do that by width animation..
And change :focus to :hover + ul
DEMO FIDDLE
#menu ul li:hover > ul {
left: 200px;
width: 200px;
}
#menu ul li > ul {
width: 0px;
}
#menu ul li a:hover + ul {
width: 200px;
-webkit-transition: width 300ms ease-in;
-moz-transition: width 300ms ease-in;
-ms-transition: width 300ms ease-in;
transition: width 300ms ease-in;
}
Hope it helps..

Animated submenu pure css

I tried to make a menu, which has 3 menu items and 1 subitem. If I click on second item, first child item should display. But not normally display it. It should animate it and slide it. I think there is a way with transition but I don't really know CSS3. And I want to have a pure css solution.
Here my HTML code:
<div id="menu">
<ul>
<li>First</li>
<li class="active">Second
<ul class="child">
<li>First child</li>
</ul>
</li>
<li>Third</li>
</ul>
</div>
I created this fiddle. Now I want to show First child menu item slowly if I click on Second menu item.
The only thing that I did before was checking transition but I just don't get it.
Can someone give me a hint?
Cheers
See your jsfiddle updated http://jsfiddle.net/3kEg4/3/
#menu {
height: auto;
width: auto;
}
#menu ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#menu ul li {
float: left;
position: relative;
}
#menu ul li a {
line-height: 30px;
text-decoration: none;
text-align: center;
display: block;
width: 100px;
height: 30px;
border: thin solid #999;
color: #FFF;
background-color: #0CF;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
}
#menu ul li a:hover {
background-color: #0C3;
}
#menu ul li ul {
position: absolute;
-webkit-transition: height 1s linear 0s;
-moz-transition: height 1s linear 0s;
-ms-transition: height 1s linear 0s;
-o-transition: height 1s linear 0s;
transition: height 1s linear 0s;
height: 0px;
overflow:hidden;
}
#menu ul li:hover ul {
height: 100px;
-webkit-transition: height 1s linear 0s;
-moz-transition: height 1s linear 0s;
-ms-transition: height 1s linear 0s;
-o-transition: height 1s linear 0s;
transition: height 1s linear 0s;
}
(inspired from http://jsfiddle.net/ashukasama/2BqGY/)
You can use some CSS3 animations to achieve this effect.
#menu ul li ul{
opacity:0;
-webkit-transition: .6s ease;
-moz-transition: .6s ease;
-ms-transition: .6s ease;
-o-transition: .6s ease;
height: 0;
}
#menu ul li:hover ul {
opacity: 1;
height: 100px;
}
JSFIDDLE
radio active states
JSFIDDLE Radio
Stackoverflow Q
jQuery
$('.subMenu').on('click', function() {
$('.subMenu ul').slideToggle(1000);
});
JSFIDDLE jQuery
i think this is better
#menu ul li ul{
visibility: hidden;
opacity: 0;
transition: visibility 0s, opacity 0.5s linear;
position: absolute;
}
#menu ul li:hover ul {
visibility: visible;
opacity: 1;
position: relative;
}
Works great as well. Please do add prefixes. Hope this helps someone.

CSS Problems with increasing menu height on hover

I'm trying to create a horizontal menu that increases in height and displays a vertical list when you hover over it. If there is a way to make a smooth transition when the menu increases in height that would be nice too.
#nav {
width: 100%;
height: 20px;
background-color: #989898;
}
#nav:hover {
height: 80px;
}
#nav li {
display: inline;
padding: 15px;
}
#nav a {
color: black;
text-decoration: none;
}
<div id="nav">
<ul>
<li>Item 1
</li>
<li>Item 2
</li>
<li>Item 3
</li>
</ul>
</div>
Here's a gif demonstration of what I want to do:
I added this code to yours to make it animate:
-webkit-transition: all 0.2s linear;
-moz-transition: all 0.2s linear;
-o-transition: all 0.2s linear;
-ms-transition: all 0.2s linear;
transition: all 0.2s linear;
Here is a fiddle:
http://jsfiddle.net/Hive7/7HS8p/
Check out this example: its similar to what u want...
Link
Something like this?
jsFiddle demo here
-webkit-animation: move .5s;
-webkit-animation-fill-mode: forwards;
#-webkit-keyframes "move" {
100% {
height:80px;
}
}

i want to make pure css horizontal nav with vertical SubMenu and Horizontal SubMenus of SubMenus

i want to fix this fiddle u can see its not working well.
i want to make this nav horizontally and submenu vertically and submenus of submenu horizontally but problem is that i also used transitions on this but its not working correct.
the first submenu dont drop smoothly but rollout smoothly and 3rd menu dont work like smooth rolling and rolling out.
i want to fix this out and i want help how to figure this out.
here is the fiddle,
all codes included this.
http://jsfiddle.net/hsn0/nQneb/
css
#nav {
height: auto;
width: auto;
}
#nav ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#nav ul li {
float: left;
position: relative;
}
#nav ul li a {
line-height: 30px;
text-decoration: none;
text-align: center;
display: block;
width: 100px;
height: 30px;
border: thin solid #999;
color: #FFF;
background-color: #0CF;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
}
#nav ul li a:hover {
background-color: #0C3;
}
#nav ul li ul {
position: absolute;
visibility: hidden;
-webkit-transition: all 1s linear 0s;
-moz-transition: all 1s linear 0s;
-ms-transition: all 1s linear 0s;
-o-transition: all 1s linear 0s;
transition: all 1s linear 0s;
overflow: hidden;
height: 0px;
}
#nav ul li:hover ul {
height: 100px;
visibility: visible;
overflow: visible;
}
#nav ul li ul li {
-ms-transition: all 1s;
-o-transition: all 1s;
}
#nav ul li ul li a {
background-color: #666;
-webkit-transition: all 1s;
-moz-transition: all 1s;
-ms-transition: all 1s;
-o-transition: all 1s;
transition: all 1s;
}
#nav ul li ul li a:hover {
background-color: #C30;
}
#nav ul li ul li ul {
position: absolute;
left: 102px;
top: 0px;
display: none;
-webkit-transition: all 1s ease 0s;
-moz-transition: all 1s ease 0s;
-ms-transition: all 1s ease 0s;
-o-transition: all 1s ease 0s;
transition: all 1s ease 0s;
overflow: hidden;
visibility: hidden;
width: 0px;
}
#nav ul li ul li ul li {
float: left;
position: relative;
}
#nav ul li ul li:hover ul {
width: 104px;
display: block;
/* [disabled]overflow: visible; */
visibility: visible;
}
**html**
<nav id="nav">
<ul>
<li>Item1
<ul>
<li>Sub1</li>
<li>Sub1</li>
<li>Sub1
<ul>
<li>Sub2</li>
<li>Sub2</li>
<li>Sub2</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>
please checkout this demo
I feel major problem is due to visibility and overflow, We can transition opacity and height though.
I used few menu part for this... I tried with height, although it will work with all also.
#nav ul li ul {
position: absolute;
-webkit-transition: height 1s linear 0s;
-moz-transition: height 1s linear 0s;
-ms-transition: height 1s linear 0s;
-o-transition: height 1s linear 0s;
transition: height 1s linear 0s;
height: 0px;
overflow:hidden;
}
#nav ul li:hover ul {
height: 100px;
-webkit-transition: height 1s linear 0s;
-moz-transition: height 1s linear 0s;
-ms-transition: height 1s linear 0s;
-o-transition: height 1s linear 0s;
transition: height 1s linear 0s;
}
i hope, below css will solve ur problem
#nav {
height: auto;
width: auto;
}
#nav ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#nav ul li {
float: left;
position: relative;
}
#nav ul li a {
line-height: 30px;
text-decoration: none;
text-align: center;
display: block;
width: 100px;
height: 30px;
border: thin solid #999;
color: #FFF;
background-color: #0CF;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
/*transition: all 0.3s ease-out;*/
transition:display 0s linear 0.5s,opacity 0.5s linear;
}
#nav ul li a:hover {
background-color: #0C3;
}
#nav ul li ul {
position: absolute;
height:0;
visibility:hidden;
opacity:0;
-webkit-transition: all 1s ease-out;
-moz-transition: all 1s ease-out;
-o-transition: all 1s ease-out;
transition: all 1s ease-out;
}
#nav ul li:hover ul {
opacity:1;
visibility:visible;
overflow: visible;
}
#nav ul li ul li a {
background-color: #666;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
#nav ul li ul li a:hover {
background-color: #C30;
}
#nav ul li ul li ul {
position: absolute;
left: 102px;
top: 0px;
visibility:hidden !important;
opacity:0 !important;
-webkit-transition: all 1s ease-out;
-moz-transition: all 1s ease-out;
-o-transition: all 1s ease-out;
transition: all 1s ease-out;
overflow: hidden;
}
#nav ul li ul li:hover .last {
opacity:1 !important;
visibility:visible !important;
overflow: visible;
}
#nav ul li ul li .last li{
float: left;
position: relative;
}
#navul li ul li .last li a {
line-height: 30px;
text-decoration: none;
text-align: center;
display: block;
width: 100px;
height: 30px;
border: thin solid #999;
color: #FFF;
background-color: #0CF;
-webkit-transition: all 0.3s ease-out;
-moz-transition: all 0.3s ease-out;
-ms-transition: all 0.3s ease-out;
-o-transition: all 0.3s ease-out;
transition: all 0.3s ease-out;
}
HTML
<nav id="nav">
<ul>
<li>Item1
<ul>
<li>Sub1</li>
<li>Sub1</li>
<li>Sub1
<ul class="last">
<li>Sub2</li>
<li>Sub2</li>
<li>Sub2</li>
</ul>
</li>
</ul>
</li>
</ul>
</nav>