首页 > Web开发 > 详细

css居中

时间:2017-09-30 11:00:08      阅读:321      评论:0      收藏:0      [点我收藏+]

1.div内文字垂直居中

text-align: center;
line-height: height px;

2.div在另一个div中垂直水平居中

html

<div class="box-big">
            <div class="box-small">我是一个垂直居中div。</div>
        </div>

css

.box-big{
                width:400px;
                height: 300px;
                background-color: pink;
                position: relative;/*父元素相对定位*/
            }
            .box-small{
                width:200px;
                height: 100px;
                text-align: center;
                line-height: 100px;
                position: absolute;/*子元素绝对定位*/
                top:50%;
                left: 50%;
                margin-top: -50px;
                margin-left: -100px;
                background-color:saddlebrown;
            }

css居中

原文:http://www.cnblogs.com/lwhz/p/7613879.html

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