负边距+定位:水平垂直居中

<style type="text/css">
.demo {
    background: gray;
    width: 100px;
    height: 200px;
    border: solid 5px black;
    /* border-width: 10px;
    border-color: black; 
    !!要想有边框出现,必须有边框样式,仅有宽度和颜色是不行的*/
    margin: auto; /*水平居中:margin:auto; &&margin:100px auto;两者都是可以的   */
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -50px; /*值为-width/2  */
    margin-top: -100px; /*值为-height/2  */
}
</style>
<body>
    <div class="demo"></div>
</body>

 

posted @ 2016-04-08 13:26  绯乐  阅读(314)  评论(0编辑  收藏  举报