谢谢大家的及时反馈,非常有帮助。仍然存在一个问题:当应用于表格单元格时,似乎也无法将line-height
足够长的文本和整齐地放在图片中间一行的文本居中。padding
奇怪的是,下面由 SwDevMan81 提供的填充解决方案在应用于 div 时完美运行,但不适用于表格单元格......
我提前为我的幼稚道歉;这是我第一次涉足 HTML 和 CSS。
该表的代码如下:
<table border="1">
<tr>
<td class="imgcontainer">
<a href="#">
<img src="http://www.bigjimsburgers.com/burger.jpg" alt="" />
<span class="desc">
Very long text that wraps around and is centered properly
</span>
</a>
</td>
<td class ="imgcontainer">
<a href="#">
<img src="http://www.bigjimsburgers.com/burger.jpg" alt="" />
<span class="desc">
misaligned text
</span>
</a>
</td>
</tr>
<tr>
<td class="imgcontainer">
<a href="#">
<img src="http://www.bigjimsburgers.com/burger.jpg" alt="" />
<span class="desc">
misaligned text
</span>
</a>
</td>
<td class ="imgcontainer">
<a href="#">
<img src="http://www.bigjimsburgers.com/burger.jpg" alt="" />
<span class="desc">
Very long text that wraps around and is centered properly
</span>
</a>
</td>
</tr>
</table>
<style type="text/css">
.imgcontainer {
overflow: hidden;
text-align: center;
}
.imgcontainer img {
float: left;
background: #fff;
width: 200px;
height: 200px;
}
.imgcontainer a .desc {
display: none;
font-size: 1.0em;
}
.imgcontainer a:hover {
cursor: pointer;
text-decoration: none;
}
.imgcontainer a:hover .desc {
display: -webkit-box;
display: -moz-box;
display: box;
-webkit-box-align: center;
-moz-box-align: center;
box-align: center;
background: #DDD;
filter: alpha(opacity=75);
opacity: .75;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=75)";
position: absolute;
width: 200px;
height: 200px;
}
</style>