图片垂直居中

第一种

<!DOCTYPE html> 
<html>
    <head>
       <meta charset="UTF-8"> 
       <title></title>
       <style type="text/css"> 
           div{height:100px;width:100px;text-align: center;} 
           img{vertical-align: middle;display: inline-block;} 
           span{height:100%;width:0;vertical-align: middle;display: inline-block;} 
       </style>
    </head>
    <body>
       <div>
           <img src="" alt="" /> 
           <span></span>
       </div>
    </body>
</html>

第二种

<!DOCTYPE html> 
<html>
    <head>
       <meta charset="UTF-8"> 
       <title></title>
       <style>
           div
           {
               display:flex    
           }
           img{
               margin:auto;
           }
       </style>
    </head>
    <body>
       <div>
           <img>
       </div>
    </body>
</html>
posted @ 2017-10-09 10:13  张书达  阅读(153)  评论(0编辑  收藏  举报