首页 > 解决方案 > 使用“中心”将图像水平居中

问题描述

我无法将图像水平居中。这是我的代码:

<img src="https://dummyimage.com/300x200/000/fff" alt="johnson johnson" style="width:300px; height:225px;" class="center">

我究竟做错了什么?谢谢你的时间。

标签: htmlimagecenter

解决方案


只需在图像前添加 p 标签并为其添加样式即可。

 <p style="text-align:  center;">
     <img src="https://dummyimage.com/300x200/000/fff" alt="johnson johnson" style="width:300px;height:225px;>
 </p>

推荐阅读