【问题标题】:Change background color of link/button on hover更改悬停时链接/按钮的背景颜色
【发布时间】:2017-04-12 13:12:44
【问题描述】:

我想更改此链接的背景颜色,当它悬停时看起来像一个按钮。我该怎么做呢。下面是它的当前 CSS。

input[type="button" i],
input[type="submit" i],
input[type="reset" i],
input[type="file" i]::-webkit-file-upload-button,
button {
  background-color: #fbf7de;
  padding: 9px;
  display: inline;
  border-style: solid; 
  border-color: #fbf7de;
  border-width: 5px;
}

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

基本上就是这样——为了这个例子,我只是减少了你的选择器。您还可以在悬停状态下修改其他样式(如border-color),并为动画添加transition

button {
  background-color: #fbf7de;
  padding: 9px;
  display: inline;
  border-style: solid; 
  border-color: #fbf7de;
  border-width: 5px;
}

button:hover {
  background: #fff;
}
<button>Button</button>

【讨论】:

    【解决方案2】:

    在元素中添加:hover

    input[type="button"], input[type="submit"], input[type="reset"], input[type="file"]::-webkit-file-upload-button, button, a[href]{
      background-color:#fbf7de;
      padding:9px;
      display:inline;
      border-style: solid; 
      border-color: #fbf7de;
      border-width: 5px;
    }
    input[type="button"]:hover, input[type="submit"]:hover, input[type="reset"]:hover, input[type="file"]::-webkit-file-upload-button:hover, button:hover, a[href]:hover{
      background-color:#ff0000;
    }
    <input type="button" value="button"/><br/>
    <a href="#">anchor</a>

    【讨论】:

      猜你喜欢
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 2021-03-18
      • 2014-09-09
      • 1970-01-01
      • 2021-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多