PHP前端开发

使用 CSS 将图像居中

百变鹏仔 4周前 (09-19) #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>