首页 > 其他 > 详细

绝对定位

时间:2021-02-19 23:52:30      阅读:22      评论:0      收藏:0      [点我收藏+]

特点:

1.开启了绝对定位,不设置偏移量则元素不发生移动

2.元素从文档流中脱离

3.绝对定位会改变元素的性质,行内变成块,块的宽高被内容撑开

4.绝对定位会使元素提升一个层级

 

 

包含块:就是当前元素最近的祖先块元素

 

绝对定位的包含块:离他最近的开启了定位的祖先元素

如果所有的祖先元素都没有开启定位的元素,则相对于根元素进行定位,根元素就是他的包含块,HTML就是初始包含块

<!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>Document</title>
<style>
    .box1,.box2,.box3
    {
        width: 100px;
        height: 100px;

    }
    .box1
    {
        background-color: aqua;
    }
    .box2
    {
        background-color: rgb(206, 31, 31);
        position: absolute;
        top: 0;
        left: 0;
    }
    .box3
    {
        background-color: chartreuse;
    }
    .box4{
        width: 400px;
        height: 400px;
        background-color: chartreuse;
        /* position: relative; */
    }
    .box5   {
        width: 300px;
        height: 300px;
        background-color: cornflowerblue;
        /* position: relative; */
    }
</style>
</head>
<body>
    <div class="box1">1</div>
    <div class="box4">
            <p>4</p>
        <div class="box5">
            <p>5</p>
            <div class="box2">2</div>
        </div>
    </div>

<div class="box3">3</div>
</body>
</html>

 

绝对定位

原文:https://www.cnblogs.com/strugglingbo/p/14418602.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!