我想要并且无法获得滚动条以显示在box-content div中。添加'overflow-y:auto'不起作用。无法在子div中获取垂直滚动条
我的要求:
- 整个布局必须调整到浏览器的高度。这就是为什么我 有#wrap {...身高:50vh; ...}
- 滚动条不得包含 标题。它只能应用于box-content div。我希望标题的高度可以根据内容进行调整,并在必要时包裹它们。
这里的CSS
#wrap {
margin: 10px;
height: 50vh;
border: 2px solid black;
}
.container {
border: 4px solid red;
padding: 4px 3px;
margin: 0;
max-height: 90%; /* As a percentage of the parent. */
/* height: 300px; /* This causes the scroll bar to appear, but its not what I want. */
}
.box-header {
background-color: green;
padding: 5px 10px;
color: white;
}
.box-content {
border: 3px solid blue;
overflow:auto;
padding: 5px;
padding-top: 10px;
max-height:100%;
}
和HTML
<div id="wrap">
<div class="container">
<div class="box-header"> Header String</div>
<div class="box-content">
<p>line 1</p>
<p>line 2</p>
<p>line 3</p>
<p>line 4</p>
<p>line 5</p>
<p>line 6</p>
<p>line 7</p>
<p>line 8</p>
<p>line 9</p>
<p>line 10</p>
<p>line 11</p>
<p>line 12</p>
<p>line 13</p>
<p>line 14</p>
<p>line 15</p>
<p>line 16</p>
<p>line 17</p>
<p>line 18</p>
<p>line 19</p>
</div>
</div>
</div>
下面是一个小提琴链接:https://jsfiddle.net/mjvancouver905/5vswprfw/
感谢。
工作正常!当我更改浏览器窗口大小时,它起作用,并且它在标题文本位于多行时也起作用。 – user3341576
@ user3341576真棒,Flex在这样的布局真的很棒。 –