gpt4 book ai didi

CSS Onmouseover 旋转子元素

转载 作者:行者123 更新时间:2023-11-28 15:15:39 24 4
gpt4 key购买 nike

我在下面的代码中,当您将鼠标悬停在 clid 元素上时,它会旋转。我想让 parent 和 child 在悬停时触发旋转。

https://jsfiddle.net/d4sbvmb0/

.parent {
width: 250px;
height: 250px;
background: silver;
padding: 25px;
}

.child {
background: red;
border-radius: 2% 50%;
height: 100px;
margin: 100px;
transition: all 0.5s;
transition-timing-function: ease-in-out;
width: 100px;
}

.child:hover {
transform: rotate(20deg);
}
<div class="parent">
<div class="child"></div>
</div>

最佳答案

如果您只需要父元素触发子元素的旋转,只需修改包含从 .child:hover.parent:hover .child 的转换的选择器.对于后者,我们说的是,当 .parent 悬停时,选择 .child 并旋转它。

.parent {
width: 250px;
height: 250px;
background: silver;
padding: 25px;
}

.child {
background: red;
border-radius: 2% 50%;
height: 100px;
margin: 100px;
transition: all 0.5s;
transition-timing-function: ease-in-out;
width: 100px;
}

.parent:hover .child {
transform: rotate(20deg);
}

/* Add me if you want additional rotation when both are hovered. */
/*
.parent:hover .child:hover {
transform: rotate(40deg);
}
*/
<div class="parent">
<div class="child"></div>
</div>

注意:transition-timing应该是transition-timing-function

关于CSS Onmouseover 旋转子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44334523/

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