gpt4 book ai didi

html - 将 Div inside body 设置为 100% height less body

转载 作者:太空宇宙 更新时间:2023-11-04 03:22:44 25 4
gpt4 key购买 nike

我按照这个例子创建了一个基本布局:

<body>
<div id="header"></div>
<div id="content"></div>
</body>

应用了以下 CSS:

body {
height: 100%;
}

#header {
height: 70px;
}

#content {
height: 100%;
display: block;
}

我的内容标签是我的 body 标签的 100%,导致额外的 70 像素的 div 高度并导致溢出/滚动条。我希望页面能够响应浏览器的高度,但我不想在我的 body 内使用 % 设置两个 div,因为我需要我的标题始终保持 70px。我怎样才能做到这一点?

最佳答案

可以使用固定定位:

#header, #content {
position: fixed;
left: 0;
right: 0;
}
#header {
top: 0;
height: 70px;
background: red;
}
#content {
top: 70px;
bottom: 0;
background: green;
}
<div id="header"></div>
<div id="content"></div>

关于html - 将 Div inside body 设置为 100% height less body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27640144/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com