CSS3过渡 - 为同一个元素添加2个不同的过渡

时间:2021-01-11 20:24:29

I am having issues with my CSS3 transitions:

我的CSS3过渡问题:

div.one_fifth{
   border: 1px solid #48484A;
   transition : border 400ms ease-out; 
   -webkit-transition : border 400ms ease-out; 
   -moz-transition : border 400ms ease-out;
   -o-transition : border 400ms ease-out; 
   font-size: 18px;
   transition : font 300ms ease-out; 
   -webkit-transition : font 300ms ease-out; 
   -moz-transition : font 300ms ease-out;
   -o-transition : font 300ms ease-out;
}

 div.one_fifth:hover{
   border: 1px solid #ed2124;
   font-size: 20px;
 }

Now the problem is that when I define both the transitions, the border one does not work...So it seems like the two transitions interfere and the font one overrides the border one...How do I intergrate them, if so, how would you do it with different speeds(ms)?

现在的问题是,当我定义两个转换时,边框一个不起作用...所以看起来两个转换干扰而字体一个覆盖边框一个...我如何整合它们,如果是这样,如何你会用不同的速度(ms)做到吗?

2 个解决方案

#1


23  

You can specify 2 or more comma-separated transitions, using a single transition property:

您可以使用单个过渡属性指定2个或更多逗号分隔的过渡:

JSFiddle Demo

div.one_fifth {
    border: 1px solid #48484A;
    font-size: 18px;
    -webkit-transition : border 400ms ease-out, font 300ms ease-out; 
       -moz-transition : border 400ms ease-out, font 300ms ease-out;
         -o-transition : border 400ms ease-out, font 300ms ease-out; 
            transition : border 400ms ease-out, font 300ms ease-out; 
}
div.one_fifth:hover {
    border: 1px solid #ed2124;
    font-size: 20px;
}

#2


1  

If you were using the same timing and easing for both transitions, you could use transition: all;

如果您使用相同的时序并缓和两个转换,则可以使用transition:all;

jsFiddle

div.one_fifth {
    border: 1px solid #48484A;
    font-size: 18px;
    -webkit-transition: all 400ms ease-out; 
       -moz-transition: all 400ms ease-out;
         -o-transition: all 400ms ease-out; 
            transition: all 400ms ease-out; 
}
div.one_fifth:hover {
    border: 1px solid #ed2124;
    font-size: 20px;
}

#1


23  

You can specify 2 or more comma-separated transitions, using a single transition property:

您可以使用单个过渡属性指定2个或更多逗号分隔的过渡:

JSFiddle Demo

div.one_fifth {
    border: 1px solid #48484A;
    font-size: 18px;
    -webkit-transition : border 400ms ease-out, font 300ms ease-out; 
       -moz-transition : border 400ms ease-out, font 300ms ease-out;
         -o-transition : border 400ms ease-out, font 300ms ease-out; 
            transition : border 400ms ease-out, font 300ms ease-out; 
}
div.one_fifth:hover {
    border: 1px solid #ed2124;
    font-size: 20px;
}

#2


1  

If you were using the same timing and easing for both transitions, you could use transition: all;

如果您使用相同的时序并缓和两个转换,则可以使用transition:all;

jsFiddle

div.one_fifth {
    border: 1px solid #48484A;
    font-size: 18px;
    -webkit-transition: all 400ms ease-out; 
       -moz-transition: all 400ms ease-out;
         -o-transition: all 400ms ease-out; 
            transition: all 400ms ease-out; 
}
div.one_fifth:hover {
    border: 1px solid #ed2124;
    font-size: 20px;
}