sticker-footer 布局

sticker-footer

1、嵌套层级不深,可直接继承自 body width:100%; height:100%;

// html

    
我是内容
// css html,body{ width:100%; height:100%; } #sticker{ width:100%; min-height:100%; } .sticker-con{ padding-bottom:40px; // 40px 为 footer 本身高度 } .footer{ margin-top:-40px; // 40px 为 footer 本身高度 }

2、嵌套层级很深,无法直接从上级继承 百分比高度的

  • 第一种方法:给需要的 sticker-footer 创建一个 wrapper
    
        
我是内容
.wrapper{ position:fixed; // 这样 wrapper 就可以直接从 html,body 继承 百分比高度了 overflow:auto; // 当高度超过 100% ;时产生滚动条 width:100%; height:100%; // 继承自 body } // wrapper 内部包裹的结构,就如上所示了,css样式也一样

3. 当无法用百分比获取高度时,也可通过js方式获得

    //css样式同第一种, 只是 sticker 的 min-height 用css获取

    
        
我是内容
var sticker = document.querySelector('#sticker'); var h = document.body.clientHeight; sticker.style.minHeight = h - 44 + 'px'; //这种方式也可应对一些特殊情况,比如有头部导航栏的情况,可以灵活的处理 min-height:

4. 强大的 flex 布局 flex-direction:column

  • 将wrapper容器 display:flex; flex-direction:column
  • sticker: flex:1; 占据除footer以外的剩余空间



    
    
    sticker footer

    


    
我是头部
我是内容

你可能感兴趣的:(sticker-footer 布局)