请问css布局整个窗口上下布局

上面270px
下面自适应
请问怎么写?

阅读 7.2k
5 个回答
<!DOCTYPE html>
<html>
  <head>
    <style>
    html,body {
      margin: 0;
      padding: 0;
    }
    .top {
        height: 270px;
    }
    .bottom {
        position: absolute;
        top: 270px;
        bottom: 0;
        left: 0;
        right: 0;
        height: auto;
        width: auto;
    }
    </style>
  </head>
  <body>
    <div class="top" style="background: red;"></div>
    <div class="bottom" style="background: blue;"></div>
  </body>
</html>

clipboard.png

我没读懂题主的意思,意思是单栏布局,上边距为270像素?

1、table实现
2、百分比
3、js自己实现,下面的高度=整个高度-上面的高度

除去上边说的,还可以使用:
1. 绝对定位
2. html body 的 height设置为100%,然后body的padding-top设置270,加上box-sizing:border-box,此时设置你的下边元素高度设置为100%就可以了;那上边的元素可以绝对定位 可以相对定位 还可以利用负margin 把他弄上去就可以了
3. 2的变种,利用css的 calc

如果是ie8+兼容 用content-box就很好做

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