我要解决的问题非常简单,但我发现很难使用我的 CSS 技术实现我想要的。
我想要的是将高度设置为相对值(例如:100% 或 30%)的某种父 div
。请不要问我为什么需要它,因为这只是一个部分,解释整个布局超出了这个问题。
在这个父级中,我需要有一个 header h1
,后跟包含大量文本的子级 div
。 最重要的,我只需要在子 div 中有滚动条,这样标题将始终附加到容器的顶部。
标记:
<div class="wrapper">
<h1>Test</h1>
<div class="text">
Lorem ipsum (... lots of text)
</div>
</div>
(不)工作 fiddle : http://jsfiddle.net/CodeConstructors/BEVSS/
最佳答案
是this你想实现什么?
HTML
<div class="wrapper">
<div class="header">
HEADER
</div>
<div class="content">
Lorem ipsum (... lots of text)
</div>
</div>
CSS
html, body {
height: 100%;
margin: 0px;
padding: 0px;
}
.wrapper {
width: 400px;
height: 100%;
background-color: #fec;
margin: auto;
position: relative;
}
.header {
height: 40px;
background-color: green;
color: #fff;
}
.content {
position:absolute;
bottom:0px;
top: 40px;
width:100%;
overflow: auto;
background-color: #333;
color: #666;
}
关于html - 当父项具有相对高度时,如何在子项 div 上强制滚动条?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17017774/