如何在DIV容器中添加下面的图片?我想在图片下方添加一些中心,这些文本将随着悬停效果移动,例如增大尺寸并具有白色背景。另外,为什么我要在网页右侧留出额外的空间?
<!DOCTYPE html>
<head>
<title></title>
<body>
<style type="text/css">
#container {
width: 720px;
}
.panel {
float: left;
width: 200px;
height: 200px;
margin: 40px;
position: relative;
padding-bottom: 150px;
}
.panel .hover {
float: none;
position: absolute;
top: 0;
bottom: 100px;
left: 0;
width: 200px;
height: 200px;
text-align: center;
-o-transform: scale(1);
-moz-transform: scale(1);
-webkit-transform: scale(1);
transform: scale(1);
-o-transition: all .3s;
-moz-transition: all .3s ease-out;
-webkit-transition: all .3s ease-out;
transition: all .3s ease-out;
padding-bottom: 90px;
}
.panel .hover:hover {
-o-transform: scale(1.4);
-moz-transform: scale(1.4);
-webkit-transform: scale(1.4);
transform: scale(1.4);
padding-bottom: 90px;
}
</style>
<div class="panel"><div class="hover"><img src="B2.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="B2+.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="C1.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="C2.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="B2W.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="B2+W.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="C1W.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="C2W.jpg" width="110%" height="150%"></div></div>
</div>
</body></html>
答案 0 :(得分:1)
只需将文本放在div中,就像这样使用悬停类。
#container {
width: 720px;
}
.panel {
float: left;
width: 200px;
height: 200px;
margin: 40px;
position: relative;
padding-bottom: 150px;
}
.panel .hover {
float: none;
position: absolute;
top: 0;
bottom: 100px;
left: 0;
width: 200px;
height: 200px;
text-align: center;
-o-transform: scale(1);
-moz-transform: scale(1);
-webkit-transform: scale(1);
transform: scale(1);
-o-transition: all .3s;
-moz-transition: all .3s ease-out;
-webkit-transition: all .3s ease-out;
transition: all .3s ease-out;
padding-bottom: 90px;
}
.panel .hover:hover {
-o-transform: scale(1.4);
-moz-transform: scale(1.4);
-webkit-transform: scale(1.4);
transform: scale(1.4);
padding-bottom: 90px;
}
<!DOCTYPE html>
<head>
<body>
<div class="panel"><div class="hover"><img src="B2.jpg" width="110%" height="150%">Some Text</div></div>
<div class="panel"><div class="hover"><img src="B2+.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="C1.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="C2.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="B2W.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="B2+W.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="C1W.jpg" width="110%" height="150%"></div></div>
<div class="panel"><div class="hover"><img src="C2W.jpg" width="110%" height="150%"></div></div>
</div>
</body></html>