要设置过渡效果为的CSS属性的名称,请使用CSS过渡属性。
在下面的示例中,我们将属性设置为width,还设置了持续时间:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 150px;
height: 150px;
background: blue;
transition-property: width;
transition-duration: 3s;
}
div:hover {
width: 250px;
}
</style>
</head>
<body>
<h1>Heading One</h1>
<p>Hover over the below box to change its width.</p>
<div></div>
</body>
</html>