使用 CSS 将图像居中

原创
ithorizon 5个月前 (10-19) 阅读数 42 #CSS

要使图像居中,请使用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"    style="max-width:90%"  style="max-width:90%">
   </body>
</html>

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



热门