网站布局,高度不满一屏时尾部显示在最底部,大于一屏时正常展示

90 阅读1分钟

网站布局,分为头部、内容、尾部三个板块,需求是整体高度不满一屏时页脚显示在最底部,大于一屏时正常展示 margin-bottom负值,元素不会移位,会减少自身提供给css读取的高度

  <body>
      <div class="header"></div>
      <div class="content"></div>
      <div class="footer"></div>
  </body>
    html,body{
        width:100%;
        height:100%;
    }
    .header{
        background:red;
        height:200px;
        margin-bottom:-200px;
    }
    .content{
        width:100%;
        min-height:100%;
        padding:200px 0 300px;
    }
    .footer{
        background:blue;
        height:300px;
        margin-top:-300px;
    }