02-CSS基础与进阶-day9_2018-09-12-20-47-19

定位
静态定位 position: static
相对定位 position: relative
绝对定位 position: absolute 脱标 参考点
子绝父相
让绝对定位的盒子水平居中和垂直居中
固定定位 position: fixed
参考点 浏览器左上角
固定定位的元素脱标不占有位置
兼容性 ie6低版本不支持固定定位

 03固定定位.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        * {
            padding: 0;
            margin: 0;
        } 

        body {
            height: 2000px;
        }

        .fa {
            width: 600px;
            height: 300px;
            margin: 60px auto;
            background-color: skyblue;
            position: relative;
        }

        span {
            width: 300px;
            height: 100px;
            background-color: green;
            position: fixed;
            top: 60px;
            left: 50px;
        }
    </style>
</head>
<body>
    <div class="fa">
        <span class="son">我是一段文字</span>
    </div>
</body>
</html>

转载于:https://www.cnblogs.com/HiJackykun/p/11069863.html

猜你喜欢

转载自blog.csdn.net/weixin_34162629/article/details/93407570