1. 程式人生 > >圖片垂直水平居中

圖片垂直水平居中

-s code view ont round 垂直居中 20px 分享 mage

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>圖片垂直水平居中</title>
    <style>
  .test_div{
      width
:120px;
      height:120px;
      border:1px solid #ccc;
      display
:table-cell;/*最重要*/
      vertical-align:middle;/*設置水平居中*/
      } .test_div img{
        border
:none;
        max-width
:100%;
        max-height:100%;
        display
:block;
        margin
:auto;
/*設置垂直居中*/
        } </style> </head> <body> <div class="test_div"> <img src="https://ss0.baidu.com/73F1bjeh1BF3odCf/it/u=2262276723,1254933744&fm=85&s=E1D15B8C0C45989C3DBF60400300B0DA" alt=""> </div> </body> </html>

效果圖

技術分享

圖片垂直水平居中