【问题标题】:Changing the border color of a submit button after clicking it, CSS, HTML单击提交按钮后更改其边框颜色,CSS,HTML
【发布时间】:2015-07-11 19:02:46
【问题描述】:

我有一个背景颜色为绿色的提交按钮。单击它时,它的背景色变为红色,但单击后,背景色变回绿色,并且按钮周围有蓝色边框。我想知道是否有办法摆脱蓝色边框?谢谢你。

input[type=submit] {
background-color: green;
}
input[type=submit]:active {
background-color: red;
}

<input type = 'submit' value = 'Click me'>

【问题讨论】:

    标签: html css


    【解决方案1】:

    outline 设置为0 并将:focus 添加到按钮上,这意味着在它被单击并保持焦点后。

    input[type=submit]:focus {
      background-color: green;
      outline: 0;
    } 
    

    【讨论】:

      【解决方案2】:

      你想对按钮做些什么,点击后他应该是绿色还是红色?删除边框(如果元素有一个)和轮廓....应该可以解决问题。
      http://www.w3schools.com/css/css_link.asp

      input[type=submit]:active{
            background-color: green;
            outline: 0;
            border: none;
          } 
      

      【讨论】:

      • 它应该是 :focus not :active 因为 active 只在用户点击时做出反应,而不是当元素处于焦点时。
      • :重点是,我误解了这个问题。谢谢
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 1970-01-01
      • 2020-12-17
      • 1970-01-01
      • 2020-06-25
      • 2021-03-18
      • 2018-08-01
      相关资源
      最近更新 更多