定位元素练习

absolute
定位元素练习
relative
定位元素练习
fixed
定位元素练习

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box1 {
            /* absolute_定页面 */
            /* relative_定自己*/
            /* fixed_定电脑 */
            position: fixed;
            top: 50px;
            left: 50px;
            background-color: blue;
            width: 100px;
        }
        
        .box2 {
            background-color: red;
            width: 100px;
            height: 10000px;
        }
    </style>
</head>

<body>
    <div class="box1">有定位</div>
    <div class="box2">无</div>
</body>

</html>
上一篇:CSS居中显示


下一篇:css子元素如何相对父元素定位?