0

So there's this image in my code and with following code it is centered correctly horizontally,

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

but when I add margin-left:-300px; the image is resized appropriately but it is slightly offset to the left and no longer exactly centered.

Any ideas?

Also, here's some of the 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>
Martin Turjak
  • 20,896
  • 5
  • 56
  • 76
Drew
  • 2,583
  • 5
  • 36
  • 54

3 Answers3

0

You could better still use margin:0px auto;

Precious Okwu
  • 397
  • 5
  • 12
  • This doesn't fix it, `img` are inline by default. He could remove the margin's altogether and just use text-align: center, or he can add `display: block` to make the img a block-level element. – Marco Pietro Cirillo Nov 01 '13 at 01:12
0

add display: block to your img css

0

When you say margin-left:-300px you are saying you want the picture moved 300px to the left. With a right margin set to auto it will of course be offset left. If you want to make it center and then move it over just slightly then I recommend reading up on this answer here: Offset div from center

Also you will want to add

display:block;
Community
  • 1
  • 1
Nick Chapman
  • 4,402
  • 1
  • 27
  • 41