<!--调整背景图位置 :10px center/ center center 10px 和 center就能调整背景图片的位置了-->
<div style="width:30%;height100%;background:url(${ctx}/assets/images/logo.png) no-repeat 10px center"></div>
分开写:
background:url(/../../image/feed.gif)no-repeat;
background-position:10px 5px; /*调整其中的数值就可以达到调整位置的目的。*/
方法一
利用display:table-cell
<div class="img_wrap">
<img src="wgs.jpg">
</div>
.img_wrap{
width: 400px;
height: 300px;
border: 1px dashed #ccc;
display: table-cell; /*主要是这个属性*/
vertical-align: middle;
text-align: center;
}
方法二
背景法
<div class="img_wrap"></div>
.img_wrap{
width: 400px;
height: 300px;
border: 1px dashed #ccc;
background: url(wgs.jpg) no-repeat center center;
}
方法三
图片外面用个p标签,通过设置line-height使图片垂直居中
<div class="img_wrap">
<p><img src="wgs.jpg"></p>
</div>
*{margin: 0px;padding: 0px}
.img_wrap{
width: 400px;
height: 300px;
border: 1px dashed #ccc;
text-align: center;
}
.img_wrap p{
width:400px;
height:300px;
line-height:300px; /* 行高等于高度 */
}
.img_wrap p img{
*margin-top:expression((400 - this.height )/2); /* CSS表达式用来兼容IE6/IE7 */
vertical-align:middle;
border:1px solid #ccc;
}