【问题标题】:Make a div inside a container to resize automatically在容器内创建一个 div 以自动调整大小
【发布时间】:2019-03-27 17:13:31
【问题描述】:

我有一个容器,里面有 3 个。前2个内容不大。我通过单击按钮显示和隐藏第一个(我正在使用 Angular)。第二个有静态内容。我不想为容器滚动。我只需要第三个 div 滚动,它有很大的内容。当我通过单击按钮显示我的第一个 div 后创建容器 overflow: hidden; 时,我的第三个 div 的一部分不显示。第三个有这个高度height: 100vh;。我是 CSS 和 HTML 的新手,我该如何解决这个问题?

<div class="container">
  <div *ngIf="showContent" class="1st-content"></div>
  <div class="2nd-content"></div>
  <div class="3rd-content"></div>
</div>

这是我的 CSS。

.container {
  overflow: hidden;
  height: 100%;
  width: 100%;
}

.3rd-content {
  height: 100%;
  width: 100%;
  overflow-y: scroll;
}

【问题讨论】:

  • “我想我错过了一些东西”——确实,您确实错过了发布一个实际的最小示例(包括代码)来展示您的情况。
  • 对不起,我已经包含了示例代码。

标签: html angular


【解决方案1】:

使用此解决方案。

body, html {
          padding: 0;
          margin: 0;
        }

.container {
          overflow: hidden;
          height: 100vh;
          width: 100%;
        }

.third-content {
          width: 100%;
          height: 100vh;
          overflow-y: scroll;
          box-sizing: border-box;
        }

【讨论】:

    猜你喜欢
    • 2015-02-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 2017-11-20
    • 1970-01-01
    相关资源
    最近更新 更多