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>
4

3 回答 3

0

你最好还是使用 margin:0px auto;

于 2013-11-01T00:34:52.623 回答
0

添加display: block到您的 img css

于 2013-11-01T01:10:19.097 回答
0

当您说margin-left:-300px您希望图片向左移动 300 像素时。将右边距设置为自动,它当然会向左偏移。如果你想让它居中然后稍微移动它,那么我建议在这里阅读这个答案:Offset div from center

您还需要添加

display:block;
于 2013-11-01T01:19:51.473 回答