悬停时按钮动画可以从上到下更改颜色

时间:2015-12-27 02:30:32

标签: html css animation button

我想要的是悬停时从上到下更改按钮的背景颜色。这个页面有一个很好的例子http://tympanus.net/Development/CreativeButtons/  这是我现在的代码。感谢

CSS

#button {

    outline: 0;
    margin: 20px  10px 10px 6px;
    border-width:2.7px;
    font-size: 25px;
    border-style: solid;
    font-family: 'PT Sans Narrow', sans-serif;
    padding: 4px 40px;
    background-color: white;
    border-color: #0e83cd;
    color: #0e83cd;
    transition: all .3s ease-in;


    }

 #button:hover {
    color: white;
    background-color: #0e83cd;
    transition: all .3s ease-in;
    }

HTML

  <button id="button" />Ask</button>

2 个答案:

答案 0 :(得分:1)

这是一种方法,就像它在网站上所做的那样:

CSS:

button {
    text-rendering: auto;
    color: initial;
    letter-spacing: normal;
    word-spacing: normal;
    text-transform: none;
    text-indent: 0px;
    text-shadow: none;
    display: inline-block;
    text-align: start;
    margin: 0em 0em 0em 0em;
    font: 13.3333px Arial;
}
user agent stylesheetinput,
textarea,
keygen,
select,
button,
meter,
progress {
    -webkit-writing-mode: horizontal-tb;
}
user agent stylesheetbutton {
    -webkit-appearance: button;
}
.btTxt submit {
    border: 3px solid #fff;
    color: #fff;
}
.btTxt submit {
    border: none;
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    cursor: pointer;
    padding: 25px 80px;
    display: inline-block;
    margin: 15px 30px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    outline: none;
    position: relative;
    -webkit-transition: all 0.3s;
    -moz-transition: all 0.3s;
    transition: all 0.3s;
}
*,
*:after,
*:before {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

希望这有帮助!有一个快乐的圣诞节: - )

答案 1 :(得分:1)

有很多方法可以做到这一点。 这个CSS可以帮到你。

#button {

  /*Reset*/
  display: inline-block;
  outline: none;
  background-color: transparent;

  /*Some fancy stuff*/
  padding: 0 20px;
  line-height: 200%;
  border: 1px solid silver;

  /*Magic*/
  background-image: linear-gradient(PaleVioletRed, PaleVioletRed 50%, Sienna 50%, Sienna);
  background-size: 100% 200%;
  -webkit-transition: background-position .3s;
  transition: background-position .3s;
}
#button:hover {
  background-position: 0 -100%;
}

演示:http://codepen.io/theonebeing/pen/wMzYdY