利用vertical-align实现div中img垂直居中

 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <style type="text/css">
    div{
        height:200px;
        background:#eee;
        vertical-align:middle;
    }
    img{
        height:40px;
        vertical-align:middle;
    }
    /* span{
        height:100%;
        display:inline-block;
        vertical-align:middle;
    }     */
 </style>
 <body>
  <div>
    <!-- <span></span> -->
    <img src="https://www.baidu.com/img/bd_logo1.png" alt="" />
  </div>
 </body>

这样是不能居中显示的,打开注释的代码即可

posted @ 2017-01-17 15:21  cao_zhen  阅读(10779)  评论(2编辑  收藏  举报