Eri*_*eon 18 css css-transitions css-animations
有没有办法让按钮的背景颜色从灰色变为蓝色,然后仅使用css3变回灰色?一个很好的例子是默认操作按钮是可可吗?我知道这可以在javascript中完成,但我宁愿只使用css.
Sha*_*ora 38
嗨我通过CSS3动画制作了按钮请看看我希望它接近你的问题: -
HTML
<input type="submit" value="submit" class="button" />
Run Code Online (Sandbox Code Playgroud)
CSS
.button {
width:100px;
height:20px;
background:red;
animation:myfirst 5s;
-moz-animation:myfirst 5s infinite; /* Firefox */
-webkit-animation:myfirst 5s infinite; /* Safari and Chrome */
}
@-moz-keyframes myfirst /* Firefox */ {
0% {background:red;}
50% {background:yellow;}
100% {background:red;}
}
@-webkit-keyframes myfirst /* Safari and Chrome */ {
0% {background:red;}
50% {background:yellow;}
100% {background:red;}
}
Run Code Online (Sandbox Code Playgroud)
看演示: - http://jsbin.com/osohak/7/edit
了解有关CSS3过渡和动画的更多信息http://css3.bradshawenterprises.com/cfimg/
如果您需要淡入淡出动画hover或类似的东西,CSS3过渡属性是您的解决方案.
编辑:
.btn {
background-color: lightblue;
-webkit-transition: all 0.3s ease-out; /* Saf3.2+, Chrome */
-moz-transition: all 0.3s ease-out; /* FF4+ */
-ms-transition: all 0.3s ease-out; /* IE10 */
-o-transition: all 0.3s ease-out; /* Opera 10.5+ */
transition: all 0.3s ease-out;
}
.btn:hover {
background-color: lightgreen;
}
Run Code Online (Sandbox Code Playgroud)