码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-07-16 19:37:52      阅读:142      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!