Changing the background colour of an active input selector

前端 未结 2 1653
时光取名叫无心
时光取名叫无心 2021-01-19 17:42

Any reason why when I run this code,

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

when I click the desired button it only flash

相关标签:
2条回答
  • 2021-01-19 18:11
    input[type=submit]:focus {
        background-color: green;
    }
    

    try this

    0 讨论(0)
  • 2021-01-19 18:23

    You also need to use the :focus selector.

    This then adds the background color to the input as it is the focused element.

    input[type=submit]:active, input[type=submit]:focus {
      background-color: green;
    }
    <input type="submit" />

    0 讨论(0)
提交回复
热议问题