6 个回答
.box {
    position: absolute;
    top: 0;
    left: 0;
}

/* 或者 */
.wrapper {
    display: flex;
    align-items: flex-end;
}

看下我有没有猜错你的意思;

<div class="container"> //大容器100%
    <div class="wrapper">
        <div class="content"></div>//内容区域
        <div class="refresh"></div> //小盒子显示的上拉状态
    </div> //滚动区域
    <div class="scrollBox">
        <div class="bar"></div>
    </div>//我是滚动条
</div>

<style>
.container{
    position:relative;
    height:100%;
    overflow:hidden;
    /*.....*/
}

.wrapper{
    position:relative;
    height:auto;
    /*.....*/
}

.content{
    position:relative;
    height:auto;
    /*....*/
}

.refresh{
    position:relative;
    float : left;
    width:100%;
    height:40px;
    /*......*/
}

.scrollBox{
    position:absolute;
    height:100%;
    right:0px;
    top:0px;
    /*因为scrollBox的父元素是container,而且改变的是content,所以这里不会发生改变*/
}

.bar{
    position:relative;
    height : /*通过js计算并更新*/;
}
</style>

这里你可以让wrapper和content的高度一样,也就是position都为relative,refresh这里使用float,然后设定好宽高。因为refresh这里已经脱离了文档流,所以不会影响wrapper的高度,container设定为overflow:hidden。 当你往上拉过头的时候,refresh会自然而然的上来。不知道这样行不行。

最无脑的是用position:absolute实现:

<body style='margin: 0;font-size: 36px;'>
    <div id='bigbox' style='position: absolute;width: 100%;height: 100%;background-color: rgba(0,0,0,0.2);'>
        <span>大盒子</span>
        <div id='smallbox' style='position: absolute;width: 500px;height: 500px;background-color: red;bottom: 0;'>
            <span>小盒子</span>
        </div>
    </div>
</body>

图片描述

*要注意的是,大盒子也要设置position,小盒子的position才知道是和谁去对比,如果父级节点找不到position它会继续向上找直到找到有position的DOM节点

固定高度+margin负值

大的div绝对定位 小的div 相对定位 bottom 为0 不就可以了吗

用position:fixed然后调整到你需要的位置就可以了

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题