我最近遇到了 CSS 的一个小问题。我对列表进行了一些设计,现在想要悬停效果。因此,当您将鼠标悬停在列表项上时,其中的图像会调整大小,而其余部分(文本 - 跨度)保持不变。
<ul id="Somename">
<li>
<a id="ID1" href="LINK">
<img alt="Something 1" src="LINK">
<span>Text</span>
</a>
</li>
<li>
<a id="ID2" href="LINK">
<img alt="Something 2" src="LINK">
<span>Text</span>
</a>
</li>
<li>
<a id="ID3" href="LINK">
<img alt="Something 3" src="LINK">
<span>Text</span>
</a>
</li>
我试着像完成动画一样制作动画here , 但无法做到。
我试过的方法是
#Somename a:hover > img {width: XXpx; }
最佳答案
这是一个简单的示例,可以帮助您开始设置 html 样式。这将像示例中那样放大并旋转图像:
/* Give the parent li item a relative position. Hide overflowed content since image will overflow*/
li {
width: 300px;
height: 300px;
margin: 10px;
overflow: hidden;
background: black;
color: white;
position: relative;
}
li span {
color: white;
position: absolute;
z-index: 999;
}
/* Set an initial size and rotate to be transitioned */
#Somename a > img {
width: 200px;
transition: .4s;
position: absolute;
transform: rotate(0deg);
}
/* Add hover styles to scale and rotate */
#Somename li:hover a > img {
width: 300px;
transform: rotate(90deg);
}
关于css - 调整 "ul hover"上的图片大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32592022/