要使图像居中,请使用margin-left、margin-right块CSS属性。您可以尝试运行以下代码使图像居中

示例

实时演示

<!DOCTYPE html>
<html>
   <head>
      <style>
         img {
            border: 2px solid orange;
            border-radius: 3px;
            padding: 7px;
         }
         img {
            display: block;
            margin-left: auto;
            margin-right: auto;
            width: 50%;
         }
      </style>
   </head>
   <body>
      <img src = https://www.tutorialspoint.com/videotutorials/images/coding_ground_home.jpg alt=Online Compiler width=300 height=300>
   </body>
</html>

以上就是使用 CSS 将图像居中的详细内容,更多请关注双恒网络其它相关文章!

简简单单挺好的

联系我们 订单查询