居中

100 阅读1分钟
  1. 固定宽高垂直居中?

    <div id='box'>
    <div id='row'>
       这是被居中的盒子
    </div></div>
    <style>
    #box{
    position:relative;
    width:500px;
    height:500px;
    background:black;
    }
    #row{
    position:absolute;
    background:#fff;
    height:100px;
    width:100px;
    left:50%;
    top:50%;
    margin-left: -50px;
    margin-top:-50px;
    }
    </style>