【问题标题】:Bootstrap scrollable div引导可滚动的 div
【发布时间】:2016-02-17 22:00:14
【问题描述】:

我想制作一个始终与屏幕高度相同的 div,即使其中包含更多内容。 div 显示 的列表,如果屏幕中包含的内容超出了 div 的范围,则会在 div 的一侧显示滚动条。

<div class = "Row">
   <div class ="col-sm-2">
       <ul>
           <li>
               <h1>record1</h1>
           </li>
           <li>
               <h1>record2</h1>
           </li>
       </ul>
   </div>
</div> 

我在网上搜索过,但只找到了与我的问题无关的答案,例如可滚动模式和其他滚动问题。请用步骤和完整代码充分解释您的答案。

【问题讨论】:

  • 也许您使用了错误的关键字在线搜索?
  • 我特意添加了最后一行,因为人们会用一个词回答,假设我知道他们的意思。
  • @那我不知道正确的关键字。我已经尝试了所有我能想到的组合,但没有找到任何东西。
  • @rosa 你可以看看这里:link 然后这里link stackoverflow 上非常基本的搜索关键字
  • 使用 vh 和 % 的工作示例:jsfiddle.net/Laa87pkw

标签: javascript html css twitter-bootstrap


【解决方案1】:

默认情况下,网页的body 仅与放入其中的内容一样高,因此我们需要告诉它是全视口高度(浏览器窗口的大小)

html, body {
  margin: 0;
  height: 100%;
}

现在,为了让您的 row div 也成为全高度,我们将其设置为高度

.row {
  height: 100%;
}

最后,为了在内容超过高度时出现滚动条,我们添加

.row {
  overflow: auto;
}

我刚刚添加的background: #eee; 覆盖了整个浏览器窗口

height: 100% 现在将使row div 自动填满整个视口(浏览器窗口),无论大小或调整大小。

示例代码sn-p

html, body {
  margin: 0;
  height: 100%;
}
.row {
  height: 100%;
  background: #eee;
  overflow: auto;
}
<div class = "row">
   <div class ="col-sm-2">
       <ul>
           <li>
               <h1>record1</h1>
           </li>
           <li>
               <h1>record2</h1>
           </li>
           <li>
               <h1>record3</h1>
           </li>
           <li>
               <h1>record4</h1>
           </li>
           <li>
               <h1>record5</h1>
           </li>
           <li>
               <h1>record6</h1>
           </li>
       </ul>
   </div>
</div>

【讨论】:

  • 我不能使用 height: 100% 因为行没有固定的高度。我需要 row 自动成为屏幕的高度。
  • @rosa 这正是100% 所做的,让它成为浏览器窗口的100%
猜你喜欢
  • 1970-01-01
  • 2016-12-18
  • 2021-12-15
  • 2018-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多