二十:让行内元素在div中垂直居中

(1)使用display:table-cell配合vertical-align:center(淘宝也是这样用的)

<div class="method4">
  <span>第四种方法</span>
</div>


<style>
.method4 {
  width: 200px;
  height: 200px;
  vertical-align: middle;
  display: table-cell;  /*只支持IE8+及现代浏览器,与position:absolute;或float:left;属性尽量不一起用*/
  text-align: center;
  background-color:#00ACED;
}
.method4{
  width:100px;
  height:100px;
  background-color:#0A58A0;
}
</style>

  

猜你喜欢

转载自www.cnblogs.com/deng-jie/p/9206393.html
今日推荐