gpt4 book ai didi

html - 在文本悬停 css 上旋转图像

转载 作者:行者123 更新时间:2023-11-27 23:09:19 26 4
gpt4 key购买 nike

现在我可以通过这段代码在 css 中悬停时旋转图像:

.spin1 img {
-webkit-transition: -webkit-transform .8s ease-in-out;
transition: transform .8s ease-in-out;
}
.spin1 img:hover {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}

但是当鼠标悬停在图片下方的文字上时,我还想旋转图片

最佳答案

您需要确保图像 及其文本 共享相同的父元素,这就是您需要的到 :hover over:

.spin1 > img {
display: block; /* removes bottom margin/whitespace */
-webkit-transition: -webkit-transform .8s ease-in-out;
transition: transform .8s ease-in-out;
}

.spin1:hover > img {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
<div class="spin1">
<img src="http://via.placeholder.com/100x100" alt="img">
Rotate
</div>

关于html - 在文本悬停 css 上旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47095212/

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