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;
}
}
Related
I've been trying to figure out why the hover image is flying from the left to bottom with transition effect even though the hover image is only set to padding-bottom. I just want the hover image to appear at the bottom of the menu when hovered.
http://jsfiddle.net/9buk14b5/1/
<header>
<div class="row">
<div class="large-12 columns">
<nav id="primary_nav">
<ul>
<li>Home</li>
<li>Work</li>
<li>Contact</li>
<li>Get a Quote</li>
<li>FAQ</li>
</ul>
</nav>
</div>
</div>
</header>
#primary_nav ul{
display: inline;
list-style-type: none;
li{
float: left;
padding: 15px 50px 15px 0;
a{
color:#ccc;
&:hover{
color:#fff;
background: url('../images/hover.png') no-repeat;
background-position: center center;
width: 22px;
height: 19px;
padding-bottom: 35px;
-webkit-transition: 0.8s all ease-out;
-o-transition: 0.8s all ease-out;
-moz-transition: 0.8s all ease-out;
transition: 0.8s all ease-out;
}
}
}
}
Use the :after pseudo-element in conjunction with :hover.
li {
position: relative;
float: left;
padding: 15px 50px 15px 0;
a {
padding-bottom: 35px;
&:after {
position: absolute;
content: '';
bottom: -3px;
left: 25%;
display:block;
margin: 0 -11px;
background: url('http://i60.tinypic.com/35a7xvs.png') no-repeat 0;
width: 22px;
height: 19px;
opacity: 0;
transition: opacity 500ms linear;
-webkit-transition: opacity 200ms linear;
-moz-transition: opacity 200ms linear;
-ms-transition: opacity 200ms linear;
-o-transition: opacity 200ms linear;
}
&:hover {
&:after {
opacity: 1;
}
}
}
}
Add the background-image to the :after pseudo element allows you to set a style to applied when its parent <a> is hovered. In this case, we set the pseudo element toopacity:0; initially and opacity:1;, then we simply set the transition-property to watch opacity.
Fade in/Fade out Examples:
Fiddle using original background image: http://jsfiddle.net/9buk14b5/8/
Fiddle using only css to create triangle: http://jsfiddle.net/9buk14b5/7/
A few things:
The odd animation behavior is fixed by tell the transition which property to animate. In your code it's set to all. Change that to padding. I've also changed the timing function to be ease-in-out.
-webkit-transition: 0.8s padding ease-in-out;
-o-transition: 0.8s padding ease-in-out;
-moz-transition: 0.8s padding ease-in-out;
transition: 0.8s padding ease-in-out;
Second, your padding-bottom amount needs to be the sum of the height of the element it is trying to go to the bottom of, and any padding, border, margin offset it may include. In your case, the magic number was 132px
padding-bottom: 132px;
Here is a working fiddle with these modifications: http://jsfiddle.net/rv9wbn8b/
Edit:
To show the arrow without any effect, simply move the padding outside of the :hover
Updated fiddle: http://jsfiddle.net/9buk14b5/4/
I'm trying to get rid of the flickering I'm getting after I added negative top margin (so that it would be visible above my navbar) to my < li > item. Here's the JSFiddle's link: http://fiddle.jshell.net/xv6mk/.
And the code just in case.
HTML:
<ul>
<li>Main</li>
<li>Subpage 1</li>
<li>Subpage 2</li>
<li>Subpage 3</li>
<li>About</li>
</ul>
And CSS:
ul {
display: inline;
list-style: none;
}
li {
font-size: 16px;
display: inline-block;
margin-right: -6px;
padding: 16px;
cursor: pointer;
display:inline-block;
-webkit-transition: all 0.4s ease;
-moz-transition: all 0.4s ease;
-ms-transition: all 0.4s ease;
-o-transition: all 0.4s ease;
transition: all 0.4s ease;
}
li:hover {
background: white;
color: #74DF00;
border-top: 10px solid #525458;
margin-top: -10px;
}
I will really appreciate help :) .
EDIT: Adding this 2 lines to < li > item (not only hover) works like charm. Thank you :) .
border-top: 10px solid #848484;
margin-top: -10px;
The problem is the transition property, you are transitioning everything, try the following:
transition-property: color, border-top, background;
Just add the prefixes for cross browser support.
Fiddle: http://fiddle.jshell.net/xv6mk/3/
I am trying to add transition property using css which is not working properly, I am giving my html & css code below :
HTML :
<ul class="job-tile">
<li style="background-color:#000" class="active" id="sw_start">Tile 1</li>
<li style="background-color:#000" class="active" id="sw_start">Tile 1</li>
</ul>
CSS :
.job-tile
{
position:relative;
list-style:none;
text-align:center;
display:block;
float:left;
}
.job-tile li
{
color: #FFFFFF;
display: inline-block;
font-size: 18px;
height: 22px;
margin: 12px;
padding: 50px 0;
position: relative;
width: 200px;
font-weight:normal;
cursor:pointer;
float:left;
opacity:0.6;
filter:alpha(opacity=60);
border-radius: 3px;
transition: background-color 0.2s linear 0s, color 0.2s linear 0s;
}
.job-tile li:hover
{
opacity:1 !important;
filter:alpha(opacity=100) !important;
transition: background-color 0.2s linear 0s, color 0.2s linear 0s;
}
If I put a background color on hover property, it will works fine, but I want to place opacity in on hover.any idea?
I am also giving working js fiddle link :- http://jsfiddle.net/4Qcr3/1/
The transition-property you set is not enough (missing the opacity property), you should use the all keyword instead. Also the transition is not fully implemented by all browsers, you should add vendor prefixes to make it function cross-browser well:
.job-tile li {
...
-webkit-transition: all 0.2s linear;
-moz-transition: all 0.2s linear;
transition: all 0.2s linear;
}
.job-tile li:hover {
opacity:1 !important;
filter:alpha(opacity=100) !important;
}
Here is the working fiddle
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.
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/