首页 > 其他 > 详细

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

时间:2016-04-08 14:36:24      阅读:248      评论:0      收藏:0      [点我收藏+]
<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>

 

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

原文:http://www.cnblogs.com/feile/p/5367694.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!