将图像包裹在元素内并使用text-align: center;...
<div class="center">
<img src="http://www.google.com/intl/en_ALL/images/logos/images_logo_lg.gif" alt="Google" />
</div>
.center {
text-align: center;
}
Run Code Online (Sandbox Code Playgroud)
另外,如果你是知道的,那什么是图像的宽度,也可以使用margin: auto;与display: block;作为img标签是inline在默认情况下,当然,元素width属性
img {
width: 276px;
display: block;
margin: auto;
}
Run Code Online (Sandbox Code Playgroud)
试试这个css水平居中
display: block;
margin: 0 auto;
Run Code Online (Sandbox Code Playgroud)
=顶部和底部边距0,以及左右边距auto