Centering an image link with HTML and no CSS

后端 未结 2 1244
误落风尘
误落风尘 2021-01-19 18:02

I am trying to center an image using only HTML and no CSS, is this possible? I have tried the following code:




        
相关标签:
2条回答
  • 2021-01-19 18:32

    Well, you could use <center>, but it is no longer supported. Your best bet here is to use the style attribute in HTML and text-align:center. This won't directly center the image, so you would wrap it in a div with the styling:

    <div style="text-align: center">
    <a href="link">
    
    <img src="URL" align="center"></a>
    </div>
    

    After looking at a comment that was posted, I see that you actually don't need the div. Just apply it to the link around it.

    <a href="link" style="text-align: center">
    
    <img src="URL" align="center"></a>
    

    There is no possible way to do this without CSS, unless you want to use outdated stuff.

    0 讨论(0)
  • 2021-01-19 18:39

    Another way that doesn't use CSS is to wrap the image in a table. While it's not the best way to do things on the Internet as it stands, but it is compliant with older e-mail clients, browsers, and systems where companies strip CSS from contents on a firewall.

    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr><td align="center">
    <img src="URL">
    </td></tr>
    </table>
    

    While I realize this question was about implementation in WordPress, Google thought it was relevant to my own issue.

    0 讨论(0)
提交回复
热议问题