gpt4 book ai didi

html - 窗口的第一个 Div 全尺寸,空白

转载 作者:太空宇宙 更新时间:2023-11-04 13:58:23 28 4
gpt4 key购买 nike

ONLINE SAMPLE

我想让第一个 div layer1(红色 block )显示窗口的完整大小,可缩放。Layer2(蓝色 block )假设始终在 layer1 之下。但是,当我将窗口高度变短时,我发现 layer2 到了 layer1 的中间,请看下图

enter image description here

所以我尝试在 layer1 上应用 overflow:hidden,但是 layer2 蓝色区域仍然重叠在 layer1 上。如何以正确的方式做到这一点。好像跟手机一样改变窗口大小,看起来不对:(

请看手机 View

enter image description here

如果有人能帮忙。谢谢

HTML

   <div class="layer1">
<h1>HELLO WORLD</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>

<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</div>
<div class="layer2">
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum
</div>

CSS

html,body{
height: 100%;

}
body{
padding: 0;
margin: 0;
}
.layer1{
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
background:red;

}
.layer2{
background:blue;
position:relative;
top:100%;
}

最佳答案

如果您将样式更改为以下内容

html,body{ height: 100%; padding: 0; margin: 0;}
.layer1{ width: 100%; min-height: 100%; background:red; overflow:auto;}
.layer2{ background:blue; position:relative; overflow:auto;}

它应该做你想做的事:fiddle

关于html - 窗口的第一个 Div 全尺寸,空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21675895/

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