html - 在内部 div 上滚动

标签 html css

所以我正在尝试制作面板。每个面板都有一个标题和一个内容。现在我希望能够只滚动内容。

CSS:

.content-div{
    float:left;
    height: 400px;
    overflow-x:hidden;
    overflow-y:hidden;
    white-space: nowrap;
}

.panel-div{
    height:100%;
    background-color: red;
    display: inline-block;
    overflow-y:hidden;
}

.panel-content{
    padding: 5px;
    height:100%;
    overflow-y:auto;
 }

.panel-header{
    height:100px;
    width:400px;
    text-align:right;
    padding:5px;
    background-color: blue;
}

和 HTML:

<div class="content-div">
    <div class="panel-div">
        <div class="panel-header">
        </div>
        <div class="panel-content">
           <p>test</p>
        </div>
    </div>
</div>

问题是 panel-content div 获得了 content-div 的完整高度,我无法想出一个很好的解决方案来说明如何使它成为 100% 的 content-div 并从标题中去掉 100px。我知道 css3 中有计算器,但还有其他方法吗?

最佳答案

您应该能够通过更改以下内容来实现您想要的:

.content-div {
  float: left;
  height: 400px;
  white-space: nowrap;
}
.panel-div {
  height: 100%;
  background-color: red;

  /* add the following */
  padding-top: 100px;
  box-sizing: border-box;
}
.panel-content {
  height: 100%;
  overflow-y: auto;
  padding: 5px;

  box-sizing: border-box;  /* add this*/
}
.panel-header {
  height: 100px;
  width: 400px;
  text-align: right;
  padding: 5px;
  background-color: blue;

  /* add the following */
  box-sizing: border-box;
  margin-top: -100px;
}
<div class="content-div">
  <div class="panel-div">
    <div class="panel-header">
      <p>head</p>
    </div>
    <div class="panel-content">
      <div class="padded">
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
        <p>test</p>
      </div>
    </div>
  </div>
</div>

但是如果你的 div 是 400px,你可以将你的 .panel-content div 设置为 300px 并将滚动条放在上面

关于html - 在内部 div 上滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34392537/

相关文章:

php - PHP 中的 session 注销问题

html - sp_send_dbmail 发送 HTML 而不是 HTML 格式的电子邮件

html - 根据图片方向将固定大小更改为网页中的宽度或高度

javascript - JQuery.css ("display") = "block"不工作

css - 样式按钮和按钮 :hover from transparent png

javascript - 如何使用 jqplot 将数据标签放置在带有线条的圆环图之外?

javascript - 如何关闭灯箱和背景覆盖?

类里面的 PHP session

html - 将悬停颜色更改添加到备用链接颜色

css - Z-Index IE 错误修复?