图片垂直水平居中

本文介绍如何使用CSS实现图片垂直水平居中布局,包括使用相对定位、绝对定位及表格单元格等方法,并通过HTML代码示例进行演示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

转载于:http://www.jiaoben8.cn/Article-id180.html

图片垂直水平居中,为了什么?为了好看,所以我们希望图片垂直水平居中,而不是设置为背景。。

css呈现:

<style>
* {margin:0;padding:0}
img{
position:static;
*position:relative; top:-50%;
left:-50%;
max-height:175px;
max-width:175px;
border-top-style: none;
border-right-style: none;
border-bottom-style: none;
border-left-style: none; 
}
.wai {
   width: 185px; height:188px;position: relative; display: table-cell;vertical-align: middle; text-align:center;
}
.nei{
 position: static;*position:absolute;top:50%;
}
  ul{
margin: 0px;
padding: 0px;
}
ul li{
list-style:none;
width:188px;
float:left;
height: 188px;
margin: 5px;
position:relative;
background-image: url(images/img_bg.gif);
background-repeat: no-repeat;
background-position: center center;
border: 2px solid #F2F2F2;
}
</style>

html代码呈现:

<div style="margin:0 auto; width:420px; margin-top:90px">
<ul>
<li><div class='wai'><div class='nei'><a href="http://www.jiaoben8.cn"><img src="image/01.jpg" /></a></div></div></li>
<li><div class='wai'><div class='nei'><a href="http://www.jiaoben8.cn"><img src="image/cancelHover.png" /></a></div></div></li>
<li><div class='wai'><div class='nei'><a href="http://www.jiaoben8.cn"><img src="image/20110805111038873858.png" /></a></div></div></li>
<li><div class='wai'><div class='nei'><a href="http://www.jiaoben8.cn"><img src="image/loadingdata.gif" /></a></div></div></li>
</ul>
</div>

演示效果:http://www.jiaoben8.cn/Specia-id181.html



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值