Reputation: 1059
I was trying the examples from w3schools: http://www.w3schools.com/css/tryit.asp?filename=trycss3_transition1 but I doing the same in my CSS and it does not work.
CSS:
nav > ul > li{
display: inline-block;
padding: 0px;
margin: 0px;
transition: width 2s;
}
nav > ul > li:hover{
width: 20%;
}
hover works without problems, but does not the transition... this should be easy
Upvotes: 1
Views: 73
Reputation: 61036
The browser typically cannot transition an element's property without having both a start and end value. Give it an initial width.
nav > ul > li {
width: 100px;
You'll notice that if you remove the initial width from the example you gave the transition ceases to function.
Upvotes: 4
Reputation: 157284
You need to define the initial/start width
of the element before you apply transition
nav > ul > li {
display: inline-block;
padding: 0px;
margin: 0px;
transition: width 2s;
background: #f00;
width: 0; /* Add this */
}
nav > ul > li:hover {
width: 20%;
}
Some tips :
px
if the value is 0
so unit doesn't matter.inline-block
so white-space will occurclass
to the parent element to uniquely identify the element. So instead of writing nav > ul > li
.some-class-nav > li
. Also you can get rid of >
if you are sure that your li
items won't have child li
Upvotes: 3