我有一个圆圈,它的背景颜色设置为红色,我想在使用css动画悬停时更改其背景我该怎么办? 这是我的代码:
.circle{
background-color: red;
border-radius: 50px;
height: 100px;
width: 100px;
}

<html>
<body>
<div class="circle"></div>
</body>
</html>
&#13;
答案 0 :(得分:3)
要使用css动画更改颜色,请尝试使用以下代码。
.circle
{
border-radius: 50px;
height: 100px;
width: 100px;
background: linear-gradient(to right, blue 50%, red 50%);
background-size: 200% 100%;
background-position: right bottom;
transition: all 2s ease;
}
.circle:hover {
background-position: left bottom;
}
<div class="circle"></div>
答案 1 :(得分:3)
.circle{
background-color: red;
border-radius: 50px;
height: 100px;
width: 100px;
}
.circle:hover{
background-color: green;
transition: all 0.5s ease;
background-position: left bottom;
}
<html>
<body>
<div class="circle"></div>
</body>
</html>
答案 2 :(得分:3)
HTML
<div class="circle"></div>
CSS
.circle {
background-color: red;
border-radius: 50px;
height: 100px;
width: 100px;
position: relative;
overflow: hidden;
}
.circle:after {
width: 0;
height: 100%;
position: absolute;
left: 0;
transition: all ease 0.5s;
content: "";
background-color: blue;
}
.circle:hover:after {
width: 100%;
transition: all ease 0.5s;
}
希望这能解决问题。