没有不值得去解决的问题,也没有不值得去学习的技术!

图片水平垂直居中的CSS解决方案!

作者:

在

html:

<ul>
<li>
<div><a href=”#” target=”_blank”><img src=”images/brand/product/1.png” width=”142″ height=”158″ alt=”产品名称一”></a></div>
<span><a href=”#” target=”_blank”>海星鱼缸水族箱&nbsp;&nbsp;AEC&nbsp;&nbsp;单拱面&nbsp;&nbsp;拱面鱼缸</a></span>
<span>免换水&nbsp;&nbsp;全国包邮&nbsp;&nbsp;生态鱼缸</span>
<div><a href=”#” target=”_blank”>查看详情</a></div>
</li>
<li>
<div><a href=”#” target=”_blank”><img src=”images/brand/product/2.png” width=”167″ height=”161″ alt=”产品名称二”></a></div>
<span><a href=”#” target=”_blank”>海星鱼缸水族箱&nbsp;&nbsp;AEC&nbsp;&nbsp;单拱面&nbsp;&nbsp;拱面鱼缸</a></span>
<span>免换水&nbsp;&nbsp;全国包邮&nbsp;&nbsp;生态鱼缸</span>
<div><a href=”#” target=”_blank”>查看详情</a></div>
</li>
<li>
<div><a href=”#” target=”_blank”><img src=”images/brand/product/3.png” width=”139″ height=”161″ alt=”产品名称三”></a></div>
<span><a href=”#” target=”_blank”>海星鱼缸水族箱&nbsp;&nbsp;AEC&nbsp;&nbsp;单拱面&nbsp;&nbsp;拱面鱼缸</a></span>
<span>免换水&nbsp;&nbsp;全国包邮&nbsp;&nbsp;生态鱼缸</span>
<div><a href=”#” target=”_blank”>查看详情</a></div>
</li>
<li>
<div><a href=”#” target=”_blank”><img src=”images/brand/product/4.png” width=”138″ height=”161″ alt=”产品名称四”></a></div>
<span><a href=”#” target=”_blank”>海星鱼缸水族箱&nbsp;&nbsp;AEC&nbsp;&nbsp;单拱面&nbsp;&nbsp;拱面鱼缸</a></span>
<span>免换水&nbsp;&nbsp;全国包邮&nbsp;&nbsp;生态鱼缸</span>
<div><a href=”#” target=”_blank”>查看详情</a></div>
</li>
</ul>

css:

.brand_list .pro_list {
float: left;
width: 984px;
overflow: hidden;
}
.pro_list li {
display: block;
float: left;
height: 300px;
width: 210px;
margin-right: 16px;
overflow: hidden;
padding: 0 10px;
text-align: center;
}
.pro_list .thumb {
height: 200px;
width: 200px;
overflow: hidden;
position: relative;
display: table-cell;
text-align: center;
vertical-align: middle;
padding: 5px;
}
.pro_list .thumb a {
display: block;
position: static;
*position: absolute;
top: 50%;
}
.pro_list .thumb img {
position: static;
*position: relative;
top: -50%;
left: -50%;
}

css:在IE6的垂直居中有一点小的问题,就是并未绝对的垂直居中,只是近似罢了,但是在其它浏览器中却是没有问题的哈。

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系

评论

2 条对“图片水平垂直居中的CSS解决方案!”的回复

  1. conscience 的头像

    Hey very nice website!! Guy .. Excellent .. Wonderful .. I will bookmark your site and take the feeds alsoI am|I’m} glad to seek out so many useful info right here in the submit, we’d like work out more techniques in this regard, thank you for sharing. . . . . .

  2. occurrence 的头像

    Thanks for sharing excellent informations. Your web-site is very cool. I am impressed by the details that you have on this blog. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found just the information I already searched all over the place and simply could not come across. What a great site.