简体   繁体   English

CSS按钮过渡

[英]CSS Button Transitions

I'm fairly new to HTML and CSS. 我是HTML和CSS的新手。 In my first website being created, I encountered a problem with CSS transitions. 在我创建的第一个网站中,我遇到了CSS转换问题。 What I want to happen, is when you mouse over, the text and background color transition, and for the same to happen when you mouse off. 我想发生的事情是,当您将鼠标悬停在上方时,文本和背景颜色会过渡,而当您将鼠标移开时,同样会发生。 But instead, one of the CSS transitions seems to be overriding the other. 但是,相反,CSS转换之一似乎覆盖了另一个。 I can't get them both to transition at the same time on mouse off. 我不能让它们在鼠标关闭时同时转换。 Am I just missing something, or is it more complicated than just a "transition: color 0.5s"? 我只是在想什么吗?还是比“过渡:颜色0.5s”还复杂? It's got to be possible somehow. 它必须以某种方式成为可能。

Check out what I mean here. 在这里查看我的意思。 here: ( http://jsfiddle.net/SeanWhelan/oz0amfL7/ ) 此处:( http://jsfiddle.net/SeanWhelan/oz0amfL7/

Here is the code for the button: 这是按钮的代码:

.btn {
background-color: #333;
color: #fff;
padding: 10px 35px;
text-decoration: none;
text-transform: none;
transition: color 0.5s; }

.btn:hover {
background: #87ff00;
cursor: pointer; 
transition: background-color 0.5s;
color: #333; }

I apologise if there's a really simple way to do this, only started learning HTML and CSS a few days ago. 抱歉,如果真的有一种简单的方法,那么几天前才开始学习HTML和CSS。

Give this a try: 试试看:

.btn {
background-color: #333;
color: #fff;
padding: 10px 35px;
text-decoration: none;
text-transform: none;
transition: color .5s, background-color .5s; }

.btn:hover {
background: #87ff00;
cursor: pointer; 
color: #333; }

Transition statements do overwrite one another. 转换语句确实会相互覆盖。 You can either comma separate the various properties you want to transition or you can use the all keyword to target all properties. 您可以逗号分隔要转换的各种属性,也可以使用all关键字定位所有属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM