下面是一个CSS代码片段,用于在悬停按钮时将按钮从#33ae74转换到#1ce。
.button {
font-size: 3em;
font-family: inherit;
border: none;
background-color: #33ae74;
padding: 0.5em 0.75em;
}
.button:hover {
background-color: #1ce;
transition: background-color 2s ease-out;
}它工作得很好。我的问题是:在鼠标悬停之前,没有过渡绑定到按钮,为什么当鼠标悬停时过渡会起作用?在另一种情况下,当鼠标悬停时,过渡绑定到按钮上,同时背景颜色也立即更改为#1ce,因此应该不会有颜色过渡。但是为什么我们仍然可以看到这种转变呢?
发布于 2021-03-29 23:45:04
这非常简单,只需在原始元素上进行转换即可。通过这样做,当你悬停时,过渡就会起作用,当悬停完成时,过渡就会起作用。
.button {
font-size: 3em;
font-family: inherit;
border: none;
background-color: #33ae74;
padding: 0.5em 0.75em;
transition: background-color 2s ease-out;
}
.button:hover {
background-color: #1ce;
}<button class="button">hover over me</button>
https://stackoverflow.com/questions/66856164
复制相似问题