帮助需要CSS悬停图像
问题描述:
我正在学习CSS的过程。帮助需要CSS悬停图像
我想在用户将鼠标悬停在画廊中时在屏幕中间显示图像。
但是,图像悬停在图像本身。 这是我的代码。
body {
margin: 0;
padding: 0;
background: #EEE;
font: 10px/13px 'Lucida Sans',sans-serif;
}
.wrap {
overflow: hidden;
margin: 50px;
}
.box {
float: left;
position: relative;
width: 25%;
padding-bottom: 25%;
color: #FFF;
}
.boxInner {
position: absolute;
left: 30px;
right: 30px;
top: 30px;
bottom: 30px;
overflow: hidden;
background: #66F;
}
.boxInner img {
width: 100%;
}
.thumbnail:hover img{
border: 1px solid transparent;
}
.thumbnail span{
position: absolute;
padding: 5px;
left: -1000px;
visibility: hidden;
color: black;
text-decoration: none;
}
.thumbnail span img{
border-width: 0;
width:70%;
height: auto;
padding: 2px;
}
.thumbnail:hover span{
visibility: visible;
top: 0;
left: 230px;
z-index: 50;
}
答
第一点是你需要隐藏第一张图像。所以只有你可以看到第二个。第二点是内部跨度不需要position:absolute, left:-1000px;
款式。
.thumbnail:hover > img{
border: 1px solid transparent;
display:none;
}
.thumbnail span{
/*position: absolute;
left: -1000px;*/
padding: 5px;
visibility: hidden;
color: black;
text-decoration: none;
}
用这种方法,为什么图像消失,当鼠标移到?可以使框中的图像保持并将图像悬停在中间? – newbieprogrammer 2014-09-24 08:43:18
如果是这种情况,你必须使用2个图像,因为该框是固定大小的图像无法离开它 – himanshu 2014-09-24 08:45:12