因此希望绿色背景颜色比按下的按钮更长。有可能吗?
#button {
background-color: red;
width: 100px;
height: 50px;
display: block;
}
#button:active {
background-color: green;
}

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<a href="#" id="button">1</a>
</body>
</html>
&#13;
答案 0 :(得分:4)
可以使用transition
#button {
background-color: red;
width: 100px;
height: 50px;
display: block;
transition:0s 1s;
}
#button:active {
background-color: green;
transition:0s;
}
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<a href="#" id="button">1</a>
</body>
</html>
&#13;