我有以下代码:
<!DOCTYPE html> <html >
<head>
<style type="text/css">
.imgBox {background: url(lock75.png) no-repeat; }
.imgBox:hover {background: url(lock75light.png) no-repeat; }
</style>
</head>
<body>
<div style="width:200px; height:200px; border:1px solid;" class="imgBox"> </div>
</body>
</html>
我的图片是 75x75,当我将鼠标悬停在边框上时会出现问题,我希望将鼠标悬停在图片上时更改图片。
注意:我需要一个与此类似的 html 结构。
编辑
我忘了说我需要图片集中在其他 div 之上,而我没有一定的图片空间。
谢谢
最佳答案
您需要有一个容器,可以在以下结构中同时容纳背景图像和您的内容(我知道您要求的内容与您发布的内容类似,但这是不可能的;好吧,但它会涉及 CSS3元素和 jQuery)
这是设置
body {
padding:10px;
}
.img-box {
max-width:200px;
width:100%;
border:1px solid #ddd;
}
.img-box .img {
width:200px;
height:200px;
background: url(https://unsplash.it/200/200/?image=876) no-repeat;
border-bottom:1px solid #ddd;
}
.img-box .img:hover {
background: url(https://unsplash.it/200/200/?image=876&blur) no-repeat;
}
p { margin:5px }
<div class="img-box">
<div class="img" ></div>
<p>other content here</p>
</div>
关于html - 将鼠标悬停在图像上时更改 div 的背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33282149/