定位(设置盒子的位置)

    .box1{
        /* 绝对位置,和父元素的相对位置,参照物是浏览器的第一屏位置 */
        background-color: red;
        position: absolute;
        top: 100px;
        left: 100px;
        /* 设置层级,两个盒子重叠部分显示层级大的盒子 */
        z-index: 1;
    }
    .box2{
        background-color: blue;
        /* 相对定位 */
        /* 距离原来位置顶端100px,左端距离100px */
        position: relative;
        top: 100px;
        left: 100px;
    }
    .box3{
        background-color: green;
        /* 固定定位,显示位置随着拉滚动条,在屏幕上的位置不变 */
        position: fixed;
        top: 100px;
        left: 100px;
    }
    .box4{
        background-color: black;
        /* 粘性定位,距离顶端还有10px时开始保持不动 */
        position: sticky;
        top: 10px;
    }
    .box5{
        background-color: aqua;
        /* 水平方向居中 */
        margin: 0 auto;
    }
    .box6{
        background-color: yellow;
        /* 垂直方向居中 随着滚动轴移动*/
        position: absolute;
        top: 50%;
        left: 50%;
        margin-top: -100px;
        margin-left: -100px;
    }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值