.footer{
        bottom:0px;
        position:fixed;
        height: 100%;
        width: 100%;
        .footer-content{
            position: absolute;
            right: 0;
            left: 0;
            bottom: 0;
            height: auto;
            overflow: hidden;
            overflow-y: scroll;
            max-height: 100%;

        }
    }
}

要可以滑动的话,元素一定要有一个高度,但是有时候我们这个高度不能够固定,因为我们需要将里面的元素靠近底部。html里面的元素都是按照从上往下排的,如果高度过高,那么元素就会距离底部太远。

所以我们需要做的就是将父级元素的高度固定,不一定需要定位,只需要有个固定高度,然后子级元素需要设置position:absolute;bottom:0;height:auto;max-height:100%;overflow: hidden;overflow-y: scroll;最重要的是这个height和max-height。因为这个高度不固定,所以需要设置auto,但是又可能超过父级高度,所以还要限制max-height为父级的高度。

收藏 打印