【问题标题】:Button animate on hover to change colors from top to bottom [closed]悬停时按钮动画以从上到下更改颜色[关闭]
【发布时间】:2021-12-25 03:56:15
【问题描述】:

我想要的是在悬停时从上到下更改按钮的背景颜色。这个页面上有一个很好的例子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>

【问题讨论】:

  • 您的 HTML 标记在哪里?还请用你目前所做的创建一个演示,以便我们查看。

标签: html css animation button


【解决方案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

【讨论】:

  • 我怎样才能改变背景的颜色,谢谢
  • 第一种颜色是 PaleVioletRed,第二种是 Sienna。您可以更改它们。
【解决方案2】:

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

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;
}

【讨论】:

    猜你喜欢
    • 2021-09-18
    • 2017-07-21
    • 2013-02-28
    • 2012-08-16
    • 2018-07-20
    • 2021-11-10
    • 2016-05-26
    • 2019-10-19
    • 1970-01-01
    相关资源
    最近更新 更多