【第三天学习】元素定位

<!DOCTYPE html>
<html lang=”en”>
<head>
    <meta charset=”UTF-8″>
    <meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
    <meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
    <title>元素定位</title>
    <style>
        body {
            position: static;
            border: 2px solid crimson;
            height: 100vh;
        }
        .div1 {
            height: 200px;
            width: 300px;
            border: 2px solid chocolate;
            position: relative;
            top: 50px;
            left: 50px;
        }
        .div2 {
            height: 100px;
            width: 100px;
            border:2px solid chartreuse;
            /* 以父级作为参照物,否则以body作为定位 */
            position: absolute;
            top: 50px;
            left: 50px;
        }
    </style>
</head>
<body>
    <div class=”div1″>
        <div class=”div2″></div>
    </div>
</body>
</html>

原创文章,作者:土豆是条哈士奇,如若转载,请注明出处:https://www.hashi7.com/women/shuoshuo/10787.html

发表评论

登录后才能评论