Changing the background colour of an active input

2019-02-26 09:46发布

Any reason why when I run this code,

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

when I click the desired button it only flashes green for a split second and then returns to the original colour? How can I keep it permanently green?

2条回答
Anthone
2楼-- · 2019-02-26 09:59
input[type=submit]:focus {
    background-color: green;
}

try this

查看更多
仙女界的扛把子
3楼-- · 2019-02-26 09:59

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" />

查看更多
登录 后发表回答