gpt4 book ai didi

css - 变换 :rotate not just rotates but also translates

转载 作者:太空宇宙 更新时间:2023-11-03 20:33:04 27 4
gpt4 key购买 nike

我正在学习 CSS 过渡和转换。这是 HTML:

<!DOCTYPE html>
<html>
<head>
<title> Transformatons and Transitions</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/n.css">
</head>
<body>
<div class="animate">animate</div>
<div class="animate">animate2</div>
<div class="different">different1</div>
<div class="different">different2</div>
</body>
</html>

CSS 是:

div.different {
transform: translate(1000px,400px);
border-style: solid;
padding: 25px;
background-color: yellow;
display: block;
width: 125px;
transition:1s ease-in-out;
}
div.different:hover{
background-color: red;
-webkit-transform: rotate(300deg);
}

旋转不正常。元素不只是旋转,而是移回原来的位置。元素不再停留在 (1000px,400px),而是回到 (0px,0px)如何防止它移动?

最佳答案

您也必须在悬停 上使用translate,因为浏览器会将您的悬停变换解释为translate(0,0) rotate(300deg):

div.different {
-webkit-transform: translate(1000px, 400px);
-ms-transform: translate(1000px, 400px);
transform: translate(1000px, 400px);
border-style: solid;
padding: 25px;
background-color: yellow;
display: block;
width: 125px;
transition: 1s ease-in-out;
}
div.different:hover {
background-color: red;
-webkit-transform: translate(1000px, 400px) rotate(300deg);
-ms-transform: translate(1000px, 400px) rotate(300deg);
transform: translate(1000px, 400px) rotate(300deg);
}

关于css - 变换 :rotate not just rotates but also translates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38059007/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com