img
tags are inline
by default so all you have to do is call text-align: center
on its parent:
<div style="display:inline-block;">
<div style="width:210px;text-align: center;">
<img src="res/img/TopAd.png" style="padding:10px 0;">
</div>
</div>
A few other notes:
- You can remove
align="left"
, that's not supported in HTML5.
- You can also remove
top: -100px
because the top
, left
, right
, and bottom
properties don't work unless an element is set to fixed
, absolute
or relative
.
- This line:
padding: 10 0 10 0;
is missing px
added to it and can be condensed to padding: 10px 0;
which is top and bottom.
UPDATE
if you want to just center all of this in the middle of the page you can add text-align: center
to the body
but I would suggest removing the first div
and adding margin:auto
to the second one which has a defined width:
<div style="width:210px;text-align: center; margin: auto;">
<img src="http://www.placecage.com/200/400" style="padding:10px 0;"/>
</div>
FIDDLE