Start CSS transition at one point - html

I'm using a CSS transition to show the sub-menu. The main-menu sits in the right hand column and the sub-menu appears when the user hovers over it. The first menu items slides out of the left on the menu and then the other menu items drop down from it.
The problem I have is that the sub-menu needs to be wider than the main-menu and when the user hovers over, the menu starts too far over the right. I want the menu to get bigger at the same speed that it moves out but where it will have reached the maximum width before it's finished moveing. How to I achieve this?
.mainmenu ul li ul{
margin-left: 0;
max-height:61px;
width:263px;
overflow: hidden;
-webkit-transition: margin-left 0.3s ease-in 1s, max-height 1s ease-in;
-moz-transition: margin-left 0.3s ease-in 1s, max-height 1s ease-in;
-o-transition: margin-left 0.3s ease-in 1s, max-height 1s ease-in;
-ms-transition: margin-left 0.3s ease-in 1s, max-height 1s ease-in;
transition: margin-left 0.3s ease-in 1s, max-height 1s ease-in, width 0s ease-in 1s;
}
.mainmenu li:hover ul{
margin-left: -262px;
width:263px;
max-height: 999px;
-webkit-transition: margin-left 0.3s ease-in, max-height 1s ease-in 0.3s;
-moz-transition: margin-left 0.3s ease-in, max-height 1s ease-in 0.3s;
-o-transition: margin-left 0.3s ease-in, max-height 1s ease-in 0.3s;
-ms-transition: margin-left 0.3s ease-in, max-height 1s ease-in 0.3s;
transition: margin-left 0.3s ease-in, max-height 1s ease-in 0.3s, width 0s ease-in;
}
#mobile_menu .mainmenu li ul{
display: block;
position:static;
margin: 0;
max-height: 999px;
}
<div id="mobile_menu">
<div class="mainmenu">
<ul>
<li><a href='/home-0.html' class='active' >Home</a></li>
<li><a href='/blog-25.html' class='' >Blog</a></li>
<li>
<a href='/contact-us-8.html' class='' >Contact Us</a>
<ul>
<li><a href='/contact-us/find-us-27.html' >Find Us</a></li>
<li><a href='/contact-us/about-us-28.html' >About Us</a></li>
<li><a href='/contact-us/meet-the-team-29.html' >Meet the Team</a></li>
</ul>
</li>
</ul>
</div>
</div>

There is some work on it and had to restructure the CSS, but it is basically like follows:
HTML:
<div id="mobile_menu">
<div class="mainmenu">
<ul>
<li><a href='#' class='active'>Home</a></li>
<li><a href='#' class=''>Blog</a></li>
<li>
<a href='#' class=''>Contact Us</a>
<ul>
<li><a href='#'>Find Us</a></li>
<li><a href='#'>About Us</a></li>
<li><a href='#'>Meet the Team</a></li>
</ul>
</li>
</ul>
</div>
</div>
CSS:
#mobile_menu .mainmenu {
width: 100px;
}
#mobile_menu .mainmenu ul {
padding: 0;
width: 100px;
}
#mobile_menu .mainmenu ul li {
list-style: none;
}
#mobile_menu .mainmenu ul li ul {
height: 18px;
margin-left: 0;
margin-top: -18px;
overflow: hidden;
-webkit-transition: height 1s 1s, margin-left 1s, width 1s;
-moz-transition: height 1s 1s, margin-left 1s, width 1s;
-o-transition: height 1s 1s, margin-left 1s, width 1s;
transition: height 1s 1s, margin-left 1s, width 1s;
width: 0;
}
#mobile_menu .mainmenu ul li:hover ul {
height: 100px;
margin-left: 100px;
width: 100%;
}
... and of course the JSfiddle as well. :)

Related

How to put a animation on dropmenu using CSS?

/*.dropdownMenuLista {
-webkit-transition: max-height 0.5s, opacity 0.2s 0.1s, visibility 0s 4s;
-moz-transition: max-height 0.5s, opacity 0.2s 0.1s, visibility 0s 4s;
-ms-transition: max-height 0.5s, opacity 0.2s 0.1s, visibility 0s 4s;
-o-transition: max-height 0.5s, opacity 0.2s 0.1s, visibility 0s 4s;
transition: max-height 0.5s, opacity 0.2s 0.1s, visibility 0s 4s;
max-height: 0;
display: block;
padding: 0;
overflow: hidden;
opacity: 0;
visibility: hidden;
}
.dropdownMenu {
-webkit-transition: max-height 0.6s, opacity 0.2s, visibility 0s;
-moz-transition: max-height 0.6s, opacity 0.2s, visibility 0s;
-ms-transition: max-height 0.6s, opacity 0.2s, visibility 0s;
-o-transition: max-height 0.6s, opacity 0.2s, visibility 0s;
transition: max-height 0.6s, opacity 0.2s, visibility 0s;
max-height: 290px;
opacity: 1;
visibility: visible;
padding: 0;
}*/
ul.ulDropMenu{
float: left;
}
ul.ulDropMenu li{
float: left;
list-style: none;
position: relative;
}
ul.ulDropMenu li a{
display: block;
padding: 9px 14px;
}
ul.ulDropMenu li ul{
display: none;
position: absolute;
background-color: #fff;
border-radius: 4px;
padding: 8px;
}
ul.ulDropMenu li:hover ul{
display: block;
}
ul.ulDropMenu li ul li{
width: 120px;
}
ul.ulDropMenu li ul li a{
padding: 6px 14px;
color: #2A2A2A;
}
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<ul class="ulDropMenu">
<li class="pr-5 dropdownMenu">
<a class="nav-link" id="navbarDropdown" aria-haspopup="true" aria-expanded="false" role="button" data-toggle="dropdown" style="transition: color .4s;" href="#">Drop Menu
<i class="fa fa-caret-down"></i>
</a>
<ul class="dropdownMenuLista">
<li aria-labelledby="navbarDropdown">
<a style="transition: color .4s;" href="#">items</a>
<a style="transition: color .4s;" href="#">items</a>
<a style="transition: color .4s;" href="#">items</a>
</li>
</ul>
</li>
</ul>
How to put an animation with transition on this drop menu? I have this code that should put an animation on drop menu, but it's not working.
When i add the classes dropdownMenuLista and dropdownMenu the dropmenu stop working.
I'm using bootstrap, but I don't want to use the JS drop menu from bootstrap. I need a CSS version of the drop menu for some purposes.....
The whole thing could be cleaned up a lot, but doing this would not explain to you what is wrong, so I will change only what is necessary.
The core issue here is that you cannot animate from max-height of display: none to display: block, because there is no max-height for non-block items.
Thus we need to remove switching of display of ul.ulDropMenu li:hover ul(. dropdownMenuLista) element and show/hide some other way. Since it is hidden in .dropdownMenuLista class, by max-height, opacity and visibility props, we need to enable those on hover.
Additionally, your visibility animation was 4 secs but others were < 1sec. Thus the possibly visible animations would run through before the element actually became visible after 4 seconds.
All changes are marked with comments it the snippet.
.dropdownMenuLista {
-webkit-transition: max-height 1s, opacity 0.2s 0.1s;
-moz-transition: max-height 1s, opacity 0.2s 0.1s;
-ms-transition: max-height 1s, opacity 0.2s 0.1s;
-o-transition: max-height 1s, opacity 0.2s 0.1s;
transition: max-height 1s, opacity 0.2s 0.1s;
/* removed visibility animation */
max-height: 0;
display: block;
padding: 0;
overflow: hidden;
opacity: 0;
visibility: hidden;
}
.dropdownMenu {
-webkit-transition: max-height 0.6s, opacity 0.2s, visibility 0s;
-moz-transition: max-height 0.6s, opacity 0.2s, visibility 0s;
-ms-transition: max-height 0.6s, opacity 0.2s, visibility 0s;
-o-transition: max-height 0.6s, opacity 0.2s, visibility 0s;
transition: max-height 0.6s, opacity 0.2s, visibility 0s;
max-height: 290px;
opacity: 1;
visibility: visible;
padding: 0;
}
ul.ulDropMenu{
float: left;
}
ul.ulDropMenu li{
float: left;
list-style: none;
position: relative;
}
ul.ulDropMenu li a{
display: block;
padding: 9px 14px;
}
ul.ulDropMenu li ul{
/* display: none; - cannot animate */
position: absolute;
background-color: #fff;
border-radius: 4px;
padding: 8px;
}
ul.ulDropMenu li:hover ul{
/* display: block; - cannot animate */
/* show by enabling all props that
hide this element in .dropdownMenuLista
style */
max-height: 290px;
visibility: visible;
opacity: 1;
}
ul.ulDropMenu li ul li{
width: 120px;
}
ul.ulDropMenu li ul li a{
padding: 6px 14px;
color: #2A2A2A;
}
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<ul class="ulDropMenu">
<li class="pr-5 dropdownMenu">
<a class="nav-link" id="navbarDropdown" aria-haspopup="true" aria-expanded="false" role="button" data-toggle="dropdown" style="transition: color .4s;" href="#">Drop Menu
<i class="fa fa-caret-down"></i>
</a>
<ul class="dropdownMenuLista">
<li aria-labelledby="navbarDropdown">
<a style="transition: color .4s;" href="#">items</a>
<a style="transition: color .4s;" href="#">items</a>
<a style="transition: color .4s;" href="#">items</a>
</li>
</ul>
</li>
</ul>

Change animation's transition speed in CSS when un-hovering element

I've got a dropdown menu that uses lists to achieve it. The sub menu has a height of 0 and then the hight changes when the user hovers over it.
The limit of the animation is that I can't set the max-height as auto so I've set it to a value that it unlikley that the sub menu will ever reach.
Since the tranistion time is based on the max-height is is very fast so I've slowed it down to be a suitable speed but what I'd like is to have it disappear a lot faster when someone un-hovers or even have it disppear immediately. Is there a way to do this?
.menu ul ul{
float: left;
padding: 0;
position: absolute;
text-align: left;
width: 274px;
z-index: 1000;
max-height: 0;
overflow: hidden;
-webkit-transition: max-height 1s ease-in;
-moz-transition: max-height 1s ease-in;
-o-transition: max-height 1s ease-in;
-ms-transition: max-height 1s ease-in;
transition: max-height 1s ease-in;
}
.menu ul li:hover ul, .menu li.over ul {
max-height: 999px;
}
I'd like to stick to CSS but I'm willing to use JavaScript.
Try this :
For the basic class ( not the :hover ), just define the transition duration you want for when the list will disapear.
On hover, define a new transition duration ( the duration that the list will take to appear ).
Quick exemple here : http://codepen.io/AxelCardinaels/pen/wBQZbm
HTML :
<div class="text">Some texte</div>
CSS :
.text{
background:blue;
transition:all 0.3s ease-in-out;
-webkit-transition: all 0.3s ease-in;
-moz-transition: all 0.3s ease-in;
-o-transition: all 0.3s ease-in;
-ms-transition: all 0.3s ease-in;
transition: all 0.3s ease-in;
}
.text:hover{
background:red;
transition-duration:2s;
}

Pure css submenu vertical

I got a css3 menu with this code:
HTML:
<div id="navi">
<ul>
<li>First</li>
<li class="active">Second
<ul class="child">
<li>First child</li>
</ul>
</li>
<li>Third</li>
</ul>
</div>
CSS:
#navi {
height: auto;
width: auto;
}
#navi ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#navi ul li {
float: left;
position: relative;
}
#navi 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;
}
#navi ul li a:hover {
background-color: #0C3;
}
#navi 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;
}
#navi 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;
}
Fiddle Here
Now I want that the menu isn't horizontal. It should be vertical. I tried to remove float:left; but then the submenu doesn't display. The submenu should press all menu items below down. Any suggestions? Would be great.
If you do this, it will give it perfect look and push your nav three item down. Add this height to your particular class:
#navi ul li:hover ul {
height:32px;
}
But if you have other sub menu items in other main nav items with different items in them, then you should make classes for all particular elements and give them height according to them. Have a look at this:
#navi ul li:hover .class {
height:64px; /*for two items in sub menu and like this for other*/
}
<!DOCTYPE html>
<html>
<head>
<style>
#navi {
height: auto;
width: auto;
}
#navi ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#navi ul li {
}
#navi 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;
}
#navi ul li a:hover {
background-color: #0C3;
}
#navi ul li ul {
position: relative;
-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;
}
#navi 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;
}
</style>
</head>
<body>
<div id="navi">
<ul>
<li>First</li>
<li class="active">Second
<ul class="child">
<li>First child</li>
</ul>
</li>
<li>Third</li>
</ul>
</div>
</body>
</html>
Check this
your css:
#navi {
height: auto;
width: auto;
}
#navi ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#navi ul li {
position: relative;
}
#navi 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;
}
#navi ul li a:hover {
background-color: #0C3;
}
#navi 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;
}
#navi ul li:hover ul {
position:absolute;
left: 100px;
top: 0px;
height:50px;
-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;
}
your html:
<div id="navi">
<ul>
<li>First</li>
<li class="active">Second
<ul class="child">
<li>First child</li>
</ul>
</li>
<li>Third</li>
</ul>
</div>
copy and paste this coding. its worked. i think you want like this vertical menu bar???

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.

CSS3 transition on a list is ignored

I'm trying to fade in a list but for some reason the transition appears to be ignored.
HTML
<div>
<ul>
<li>item 1</li>
<li>item 2</li>
</ul>
</div>
CSS
div {
background-color: #ccc;
width: 200px;
height: 200px;
}
ul {
display:none;
/*transition*/
-webkit-transition: all 0.9s ease-in-out;
-moz-transition: all 0.9s ease-in-out;
-o-transition: all 0.9s ease-in-out;
transition: all 0.9s ease-in-out;
}
div:hover ul {
display: inline-block;
}
Is there a problem with the way I'm trying to implement this?
http://jsfiddle.net/QeG4X/1/
You can not animate the display property of css. You can do it with opacity!
Here is an updated fiddle
http://jsfiddle.net/cfknoop/QeG4X/2/
ul {
opacity:0;
/*transition*/
-webkit-transition: all 0.9s ease-in-out;
-moz-transition: all 0.9s ease-in-out;
-o-transition: all 0.9s ease-in-out;
transition: all 0.9s ease-in-out;
}
div:hover ul {
opacity:1;
}
Another option is to animate the height i.e. of an element.
Well, display is not animatable, since you want to fade in, add opacity: 0 to ul and opacity: 1 in div:hover ul. Note you would have to remove display from both rules. See the fiddle: http://jsfiddle.net/QeG4X/3/