0

I have used the text-align: center CSS property but the image is not getting aligned in center of the body of the HTML page.

I tried the suggestions mentioned in the below URL but couldn't make it work:

Center image using text-align center?

HTML:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <style type="text/css">
        </style>
    </head>
    <body>
        <div style="position: absolute; top: 0px; width:794px; height:1122px border:10px solid black" >
            <img style="text-align:center; display:block; margin-left: auto;margin-right:auto; width: 747px; height: 1056px" src="Image.jpg" alt="" />
        </div>
    </body>
</html>

Note: I have to achieve this requirement using inline style only.FYI, In the whole HTML page, only this image will get displayed.

  • I tried adding text-align:center; property to the outermost div tag to make it work. But it didn't work. I have added the display: inline-block in the img tag and adding text-align:center in div tag simultaneousluy but it's not working. Let me know if I am missing something. – Deepak Jain Apr 19 '20 at 15:58

1 Answers1

-1

Try this once:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <style type="text/css">
    </style>
</head>
<body>
    <center>
        <div style=" padding: 25%; border:10px solid black"  >
            <img src="image.png" alt="" />
        </div>
    </center>
</body>

  • Unfortunately, I have to achieve this requirement using inline CSS only. I do not have the privilege to use
    HTML tag.
    – Deepak Jain Apr 19 '20 at 16:06