Animate height of menu bar in CSS - html

What I really want is to have the same effect on the website of www.ditto.com by the menu, if anyone can figure that out, it would be really great, but if not this is what I have and please if anyone can answer this question, I'm in the middle of making a website for someone and I need this info fast!!
This code waits 0.8s when going up but it doesn't wait when it goes down, it just pops down.
Thanks in advance!!
You can see the full code here here: http://jsfiddle.net/zZPPR/
CSS
.one
{
max-height: 0;
overflow: hidden;
-webkit-transition: max-height 0.8s;
}
.two
{
max-height: 200px;
overflow:visible;
}

Here is a solution that target the second animation in the link. Still a draft though.
http://jsfiddle.net/NicoO/T4Nbk/5/
Update: Max-height is causing speed issues, making the feeling the transition too fast or slow. Here is an alternative solution using transforms: http://jsfiddle.net/NicoO/T4Nbk/7/ same version with Chrome vendor prefixes: http://jsfiddle.net/T4Nbk/9/
CSS:
ul
{
margin: 0;
padding: 0;
}
ul > li
{
display: inline-block;
position: relative;
}
ul > li li
{
display: block;
}
ul > li:before
{
background-color:gray;
top: 100%;
bottom:0;
left: 0;
right: 0;
position: absolute;
content: "";
transition-duration: 0.4s;
z-index:-1;
}
ul > li a
{
display: block;
position: relative;
}
ul > li ul
{
max-height: 0;
overflow: hidden;
position: absolute;
left:0;
width: 300px;
background-color: gray;
transition-duration: 0.4s;
transition-property: max-height;
}
ul > li:hover:before
{
top:0;
}
ul > li:hover ul
{
max-height: 400px;
}
HTML:
<nav>
<ul>
<li>Home</li>
<li>News & Events</li>
<li>
Discover
<ul>
<li>Jordan</li>
<li>Jordan</li>
</ul>
</li>
</ul>
</nav>
CSS of the solution using transforms:
Inspired by: How can I transition height: 0; to height: auto; using CSS?
ul
{
margin: 0;
padding: 0;
}
ul > li
{
display: inline-block;
position: relative;
}
ul > li li
{
display: block;
}
ul > li:before
{
background-color:gray;
top: 100%;
bottom:0;
left: 0;
right: 0;
position: absolute;
content: "";
transition-duration: 0.4s;
z-index:-1;
}
ul > li a
{
display: block;
position: relative;
}
ul > li ul
{
transform: scaleY(0);
transition: transform 0.4s;
transform-origin: top;
overflow: hidden;
position: absolute;
left:0;
width: 300px;
background-color: gray;
}
ul > li:hover:before
{
top:0;
}
ul > li:hover ul
{
transform: scaleY(1);
}

What's happening is that you're not transitioning the overflow property. So as soon as the class two is applied, the overflow is set to visible and the content shows immediately.

Remove the overflow:visible from the class .two and it will work
JSFIDDLE

You should remove overflow:visible;

Related

CSS: transform 1 pixel shift on Chrome

In the actual version of the Chrome browser there is a little issue when transition of this code finishes: 1 pixel shift of the line height on the bottom (on hover of the links).
Also, I've noticed that in code snippets of jsfiddle and here it may not be visible, but on the CodePen and on my website this is what happens. Checked on Firefox - everything is fine and on every web site.
Here is snippet of Stack Overflow and CodePen:
https://codepen.io/Maxim222/pen/OQWWEB
body{
background:#111;
}
ul{
margin:0;
padding:0;
list-style:none;
}
ul li{
float:left;
position:relative;
}
li a{
padding:10px;
color:#fff;
text-decoration:none;
}
li a:before{
content:'';
-webkit-transform: scaleX(0);
transform: scaleX(0);
background-color: #fb0;
bottom: 0px;
height: 15px;
left: 0;
margin: 0;
padding: 0;
position: absolute;
width: 100%;
transition:all 1s;
}
li a:hover:before{
bottom:0;
transform: scaleX(1);
-webkit-transform: scaleX(1);
}
<div>
<ul>
<li>Hello</li>
<li>Worldsdfsdf</li>
</ul>
</div>
From what I know, it's not your fault, it's a "glitch" with the scaleX param. If you use 0.99 as a value instead of 1, it should work fine.
body {
background: #111;
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
ul li {
float: left;
position: relative;
}
ul li a {
padding: 10px;
color: #fff;
text-decoration: none;
}
ul li a:before {
content: '';
-webkit-transform: scaleX(0);
transform: scaleX(0);
background-color: #fb0;
bottom: 0px;
height: 15px;
left: 0;
margin: 0;
padding: 0;
position: absolute;
width: 100%;
transition: all 1s;
}
ul li a:hover:before {
bottom: 0;
transform: scaleX(0.99);
-webkit-transform: scaleX(0.99);
}
<div>
<ul>
<li>Hello</li>
<li>Worldsdfsdf</li>
</ul>
</div>

Max height of ul is limited to a single nested li item

Making a slide down drop menu animation, if I set max height to 100% the <ul> will only extend its height to the first nested <li>. I can set the max-height in the Keyframe to 400%, but this causes to animation to go twice as fast in other drop downs with less submenus. The height of the <ul> before I hover over seems to be the full size when debugging, not sure why it gets limited in the animation.
And as a secondary question, will I run into browser support issues using animations like this?
JSFiddle
#keyframes slideDown {
0% {
max-height: 0%;
opacity: .2;
}
100% {
max-height: 400%;
opacity: 1;
}
}
#menuTabs {
float: left;
position: absolute;
margin-left: 0px;
background: #256AAA none repeat scroll 0% 0%;
width: 100%;
overflow: visible;
}
#menuTabs ul {
left: 50%;
margin: 0px;
clear: left;
float: left;
padding: 0px;
font-size: 15px;
position: relative;
text-align: center;
font-family: helvetica;
list-style: outside none none;
}
#menuTabs ul li {
margin:0;
padding:0;
right:50%;
float:left;
display:block;
list-style:none;
min-width: 170px;
max-width: 170px;
position:relative;
}
#menuTabs ul li a {
color:#000;
display:block;
background:#ddd;
padding:0px 50px;
line-height:1.3em;
text-decoration:none;
font-family:'Oxygen', sans-serif;
color: #FFF;
margin-top: 0px;
font-weight: bold;
padding: 15px 50px;
text-decoration: none;
background: #Blue;
}
#menuTabs ul li:hover > a {
visibility: visible;
text-decoration: none;
background: #CCC;
}
ul#menu li.selected a {
color: #000;
background-color: #fff;
}
#menuTabs ul li ul {
margin: 0;
padding: 0;
width: 100%;
visibility: hidden;
overflow: hidden;
position: absolute;
left: 0%;
max-height: 0%;
}
#menuTabs ul li ul a {
z-index: 1;
display: block;
font-size: 12px;
max-width: 70px;
min-width: 120px;
min-height: 22px;
overflow: visible;
position: relative;
padding: 14px 25px;
background: #256AAA none repeat scroll 0% 0%;
}
#menuTabs ul li ul a:hover {
background: #CCC;
}
#menuTabs ul li:hover ul {
visibility: visible;
position: absolute;
background: #CCC;
}
#menuTabs ul li:hover ul {
max-height: 0%;
animation-name: slideDown;
animation-duration: 2s;
animation-fill-mode: forwards;
}
#menuTabs ul li ul li {
left: 0%;
display: block;
}
<div id="menuTabs">
<ul id="menu">
<li> Services
<ul id="class">
<li id="srv1"> SubMenu
</li>
<li id="srv2"> SubMenu2
</li>
</ul>
<li>Resources
<ul>
<li> SubMenu2</li>
<li> SubMenu3</li>
<li> SubMenu4</li>
<li> SubMenu5</li>
</ul>
</li>
</li>
</ul>
</div>
I would do it by just using transition instead of keyframes for that, it runs smoother, and much easier. I haven't found a way to do the dynamic height thing, so I think you'll have to pick a height with the max number of items you're possibility going to have.
jsfiddle
#menuTabs ul li ul {
...
max-height: 0;
transition: all .1s ease-out;
opacity: .5;
}
#menuTabs ul li:hover ul {
...
max-height: 400%;
transition: all .25s ease-in;
opacity: 1;
}

How can I make it so the dropdown menu stays there when I'm hovering on it?

I have the following dropdown menu:
<div id="header">
<div class="container">
<ul class="navigation">
<li>
<ul class="sub-menu">
<li></li>
</ul>
</li>
</ul>
</div>
</div>
#header .navigation {
float: right;
margin: 15px 0 0;
position: relative;
}
#header .navigation li {
float: left;
margin: 0 20px 0 0;
position: relative;
}
#header .navigation li a {
float: left;
}
#header .navigation li:hover .sub-menu {
display: block;
transition: all 0.0s ease 0s;
}
#header .navigation > li > .sub-menu {
display: none;
width: 150px;
transition: all 0.0s ease 0.2s;
padding: 10px 15px 2px;
position: absolute;
top: 20px;
left: 0;
}
#header .navigation > li > .sub-menu li {
clear: both;
margin: 0 0 10px;
width: 100% ;
}
#header .sub-menu .sub-menu li {
padding: 10px 0 0 15px;
margin: 0 !important;
}
The problem is that the .sub-menu disappears immediately after I leave the parent. How can I make it so that .sub-menu stays where it is as long as I'm hovering it?
Here's a live example: http://m2c.dreamhosters.com/wordpress/
Two things to note:
place any padding on the links themselves, as you don't want any gaps between the top li and the sub uls
make sure the sub ul is neatly tucked at the bottom of the top li, with top: 100%. (That prevents any gap between them.
E.g.
#header .navigation {
float: right;
margin: 15px 0 0;
position: relative;
}
#header .navigation li {
float: left;
margin: 0 20px 0 0;
position: relative;
}
#header .navigation li a {
float: left;
}
#header .navigation li:hover .sub-menu {
display: block;
transition: all 0.0s ease 0s;
}
#header .navigation li .sub-menu {
display: none;
width: 150px;
transition: all 0.0s ease 0.2s;
position: absolute;
top: 100%;
left: 0;
}
#header .navigation > li > .sub-menu li {
clear: both;
width: 100%;
}
ul, li {list-style: none; padding: 0; margin: 0;}
<div id="header">
<ul class="navigation">
<li>
link
<ul class="sub-menu">
<li>text</li>
</ul>
</li>
</ul>
</div>
It seems to me that the problem lies on this line of code:
top: 20px;
If you do a very fast move of your mouse from the list item anchor tag to the .sub-menu, the .sub-menu won't disappear.
So what you've gotta do is to reduce the gap from a to .sub-menu.
For example you can change top: 20px; to padding-top: 20px;, it would do the trick. However the style might change.
UPDATE:
For the link you provided, you can simply change top: 20px; to top: 15px.

Child ul behind parent ul in css

I'm trying to make my dropdown menu with pure css3 but my child ul keeps showing on top of the parent. I've tried with z-index -100, removing the positive z-index value from the parent ul, but nothing happens.
This is my code:
http://jsfiddle.net/z9kCx/
I've updated your fiddle here. Would that work?
I added menu and sub-menu classes to your uls and edited your css a bit:
ul.menu li {
position: relative;
width: 100px;
float: left;
background: #2A2A2A;
text-align: center;
font-size: 14px;
padding: 15px;
-webkit-transition: all 0.5s;
transition: all 0.5s;
list-style-type: none;
}
ul.sub-menu {
padding: 0;
position: absolute;
top: 45px;
left: 0;
width: 145px;
display: none;
opacity: 0;
visibility: hidden;
}
ul.menu li:hover > .sub-menu {
display: block;
opacity: 1;
visibility: visible;
}

CSS3 Display other element on hover

I'm here trying to display a list item on hovering an anchor tag. How to affect other elements when a div is hovered - tried using this post but I couldn't succeed.
I'm here trying this with only pure CSS.
Here's the FIDDLE.
And below is the code.
HTML :
<div class="container">
<div class="menu">
<a class="user" href="#">Brett</a>
<ul>
<li>
Settings
</li>
<li>
Logout
</li>
</ul>
</div>
</div>
CSS :
body {
font-size: 50px;
}
.container {
margin-top: 100px;
margin-left: 200px;
}
a {
text-decoration: none;
/*color: #fff;*/
}
.user {
position: relative;
z-index: 1000;
margin-left: -200px;
}
ul {
list-style: none;
position: absolute;
top: 2%;
left: 11%;
visibility: hidden;
opacity: 0;
}
.menu a:hover .menu ul {
visibility: visible;
opacity: 1;
-webkit-transition: visibility 1s, opacity 1s;
/*color: #000;*/
/*-webkit-transition: color 1s;*/
}
Try using the adjacent siblings selector
.menu a:hover + ul instead of .menu a:hover .menu ul
jsFiddle Demo
You have to use the adjacent siblings selector:
.menu > a:hover + ul
Also, there's something wrong with your property -webkit-transition: visibility 1s, opacity 1s; as it is preventing the menu from appearing.
http://jsfiddle.net/KA5Tg/4/
Here is update fiddle, Position is not correct for menu but its working on hover.
I have updated css as:
ul {
list-style: none;
position: absolute;
top: 2%;
left: 11%;
display :none;
}
.menu a:hover + ul {
display :block !important;
opacity: 1;
-webkit-transition: visibility 1s, opacity 1s;
}