body{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
div {
height: 50px;
width: 200px;
background: rgb(255, 99, 99);
}
div:hover{
transform: translateX(100px) rotateZ(45deg);
transition: transform 2s;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>Hover on me.</div>
</body>
</html>
我只想在 translateX()
上应用过渡,而不是在 rotateZ()
上应用。
类似于transition: translateX 1s;
。有什么办法吗? (Chrome 浏览器)。
最佳答案
您可以使用单独的转换,但要注意浏览器支持,因为它是一项新功能
body{
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
div {
height: 50px;
width: 200px;
background: rgb(255, 99, 99);
transition: translate 2s;
}
body:hover div{
translate: 100px 0;
rotate: 45deg;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div>Hover on me.</div>
</body>
</html>
关于css - 如何仅在转换 : translateX()? 上应用转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73825066/