CSS定位

1.相对定位

                相对定位:position:relativee;

                相对原来位置进行指定的偏移(上下左右)

                相对定位的话,它仍然在标准文档流中,原本的位置会被保留

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <!--    相对定位:相对自己原来的位置进行偏移
    
            -->
    <style>
        
        body{
            padding: 20px;
        }
        
        div {
            margin: 10px;
            padding: 5px;
            font-size: 12px;
            line-height: 25px;

        }

        #father {
            border: 1px solid black;
            padding: 0px;
        }

        #first {
            background: #ff2600;
            border: 1px dashed red;
            position: relative;/*    相对定位:上下左右*/
            top: -20px;/*上*/
            left: 20px;/*左*/
        }

        #second {
            background: #fff200;
            border: 1px dashed #f7ff00;
        }

        #third {
            background: #08ff00;
            border: 1px dashed #00ffd9;
            position: relative;
            bottom: -10px;/*下*/
            right: 20px;/*右*/
        }
    </style>

</head>
<body>

<div id="father">
    <div id="first">第一个盒子</div>
    <div id="second">第二个盒子</div>
    <div id="third">第三个盒子</div>
</div>


</body>
</html>

2.绝对定位

定位:基于XXX定位,上下左右

相对父级或者浏览器进行指定的偏移(上下左右)

              绝对定位的话,它仍然在标准文档流中,原本的位置不1会被保留

1.没有父级元素定位的前提下,根据浏览器定位

2.假设父级元素存在定位,我们通常会相对于父级元素定位、

3.在父级元素范围内移动

position: absolute;
            right: 100px;
            top: 10px;

3.固定定位

不管怎么样移动网页,该定位不会移动

position: fixed;
            right: 0;
            bottom: 0;

4.z-index

图层  z-index:默认是0,最高无限~999

#content {
    width: 400px;
    padding: 0;
    margin: 0;
    overflow: hidden;
    font-size: 12px;
    line-height: 25px;
    border: 1px black solid;
}

ul, li {
    padding: 0;
    margin: 0;
    list-style: none;
}

/*父级元素相对定位*/
#content ul {
    position: relative;

}

.tipText, .tipBg {
    position: absolute;
    width: 400px;
    height: 25px;
    top: 210px;
}

.tipText {
    color: white;
    z-index: 999;
}

.tipBg {
    background: black;
    opacity: 0.5; /*背景透明度    */
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值