按下时如何使按钮改变其背景颜色?

时间:2014-10-13 15:10:30

标签: css angularjs

我正在使用AngularJS,我想知道是否有任何功能可以帮助我。我有以下按钮CSS:

   button {
        background-color: @button-background-color;
        border: 1px solid @button-border;
        background-color: #ccc;
        border: 1px solid #999;
        color: @button-color;
        background: #e6e6e6;
        background-image: -moz-linear-gradient(top,#fff,#d9d9d9);
        background-image: -webkit-linear-gradient(top,#fff,#d9d9d9);
        background-image: -o-linear-gradient(top,#fff,#d9d9d9);
        background-image: -ms-linear-gradient(top,#fff,#d9d9d9);
        background-image: linear-gradient(top,#fff,#d9d9d9);
        border: 1px solid #ccc;
        border-top-color: #ccc;
        border-bottom-color: #a2a2a2;
        border-radius: 4px;
        text-shadow: 0 1px 0 rgba(255,255,255,1);
        box-shadow: 0 1px 1px rgba(0,0,0,.1),inset 0 1px 0 rgba(255,255,255,.2);
        -moz-appearance: none;
        -webkit-appearance: none;
        appearance: none;
        display: inline-block;
        line-height: 18px;
        line-height: 1.8rem;
        font-size: 14px;
        font-size: 1.4rem;
        cursor: pointer;
        color: #474747;
        padding: 4px 10px 3px 10px;
        font-family: arial,sans-serif;
        vertical-align: middle;
  }

这看起来不错,但我希望有一个效果,当我将鼠标悬停在单击按钮而没有释放点击时。

有没有什么方法可以用角度来捕捉这个并且在我按住按钮的时候改变了班级?

请注意,我正在寻找仅CSS或CSS / AngularJS解决方案。我没有使用jQuery。

由于

2 个答案:

答案 0 :(得分:3)

http://www.w3schools.com/cssref/sel_hover.asp

http://www.w3schools.com/cssref/sel_active.asp

button:hover button:active

  button {
        background-color: @button-background-color;
        border: 1px solid @button-border;
        background-color: #ccc;
        border: 1px solid #999;
        color: @button-color;
        background: #e6e6e6;
        background-image: -moz-linear-gradient(top,#fff,#d9d9d9);
        background-image: -webkit-linear-gradient(top,#fff,#d9d9d9);
        background-image: -o-linear-gradient(top,#fff,#d9d9d9);
        background-image: -ms-linear-gradient(top,#fff,#d9d9d9);
    background-image: linear-gradient(top,#fff,#d9d9d9);
        border: 1px solid #ccc;
        border-top-color: #ccc;
        border-bottom-color: #a2a2a2;
        border-radius: 4px;
        text-shadow: 0 1px 0 rgba(255,255,255,1);
        box-shadow: 0 1px 1px rgba(0,0,0,.1),inset 0 1px 0 rgba(255,255,255,.2);
        -moz-appearance: none;
        -webkit-appearance: none;
        appearance: none;
    display: inline-block;
        line-height: 18px;
        line-height: 1.8rem;
        font-size: 14px;
        font-size: 1.4rem;
        cursor: pointer;
        color: #474747;
        padding: 4px 10px 3px 10px;
    font-family: arial,sans-serif;
        vertical-align: middle;
  }
button:hover 
{
  background: red;
}

button:active 
{
  background: green;
}
<button>button</button>

答案 1 :(得分:0)

你可以输入以下css:

button:active{
    background-color: red;
}

了解更多信息:http://www.w3schools.com/cssref/sel_active.asp