2013-10-31 32 views
0

所以有这个形象在我的代码,并与下面的代码是正确的水平居中,含量不居中正确

img#headerImage{ 
      width: 600px; 
      margin-left:auto !important; 
      margin-right:auto !important; 
     } 

,但是当我添加margin-left:-300px;图像进行适当调整,但略微向左偏移和不再精确地居中。

任何想法?

而且,这里的一些的HTML:

<tr> 
    <td class="headerContent" id="logoContainer"> 
    <img src="url" style="max-width:600px;" 
     id="headerImage" mc:label="header_image" mc:edit="header_image" 
     mc:allowdesigner="" mc:allowtext="" /> 
    </td> 
</tr> 
+2

您需要发布您的HTML以及 –

+0

@Juangweb会做! – Drew

+0

你可以发布你的整个HTML和CSS? –

回答

0

你可以更好使用保证金:0px auto的;

+0

这不能解决它,'img'默认是内联的。他可以完全删除边距,只使用text-align:center,或者他可以添加“display:block”使img成为块级元素。 –

0

添加display: block到您的IMG CSS

0

当你说margin-left:-300px你说你想要的图片移动300到左边。将右边距设置为自动时,它当然会左移。如果你想使它中心,然后将其移到稍稍那么我建议在这个答案在这里读了起来:Offset div from center

而且你会希望添加

display:block;