首页 > 其他 > 详细

学习笔记(1)----垂直居中的方法

时间:2016-07-16 19:35:59      阅读:268      评论:0      收藏:0      [点我收藏+]

(1)利用transform居中,示例如下:

<!DOCTYPE html>
<html>
    <head>
        <title>实现垂直居中</title>
        <meta charset="UTF-8"/>
        <style type="text/css">
            *{
                margin:0;
                padding:0;
            }
            .parent{
                width:300px;
                height:300px;
                border:green solid 1px;
            }
            .child{
                margin-top:50%;
                transform:translateY(-50%);/*结合margin-top:50%;使得该元素垂直居中*/
                text-align:center;/*水平居中*/
            }
        </style>
    </head>
    <body>
        <div class="parent">
            <div class="child">
                <p>I love imooc</p>
                <p>快来慕课吧</p>
            </div>
        </div>
    </body>
</html>

 

学习笔记(1)----垂直居中的方法

原文:http://www.cnblogs.com/mujinxinian/p/5676722.html

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