2015年4月29日学习笔记

1、又学到了一种水平垂直居中的方法。适用于父级元素只有一个子元素的情况,比如全屏的效果。

   父级元素:pos-r, w、h设定;(emmet代码, 下同)

   子元素:   pos-a,w、h设定, t0 b0 l0 r0, m-a。

   以前只知道margin: 0 auto之类的,从来没想到margin: auto的妙用...孤陋寡闻了...

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>Document</title>
    <style>
        .outer {
            position: relative;
            width: 300px;
            height: 300px;
            background-color: #f80;
            margin: 50px auto;
        }
        .inner {
            position: absolute;
            height: 100px;
            width: 60%;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background-color: #fff;
            margin: auto;
        }
    </style>
</head>
<body>
    <div class="outer">
        <div class="inner">Lorem ipsum dolor sit amet.</div>
    </div>
</body>
</html>

效果如下:

小时不识月,呼作白玉盘。又疑瑶台镜,飞在碧云端。
原文地址:https://www.cnblogs.com/bydclouds/p/4466971.html