html - Flex with overflow 和 bootstrap navbar 在 Firefox/Chrome/Safari 中表现不同

标签 html css firefox flexbox bootstrap-4

当我使用 Firefox 显示下面的代码片段时,类 h-100div 被分配了整个页面高度 (100vh) ,然后添加 nav 的高度,以便生成第二个滚动条。

我想要的是只有 overflow-y: autodiv 应该有滚动条。

奇怪的是,代码在 Chrome 和 Safari 中的行为似乎符合我的要求。

我的 HTML/CSS 有问题吗?我该如何解决这种行为差异?

.grey {
  background-color: grey;
}

#foo {
  background-color: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<div id="root">
  <div style="height: 100vh; display: flex; flex-direction: column">
    <nav class="navbar navbar-dark navbar-expand bg-dark"><a class="navbar-brand" href="/">Title</a></nav>
    <div class="h-100" style="display: flex; flex-direction: row">
      <div style="flex: 1 1 auto; overflow-y: auto">
        <div id="foo" style="height: 1200px">
        </div>
      </div>
    </div>
  </div>
</div>

最佳答案

设置溢出隐藏到父div。

.grey {
  background-color: grey;
}

#foo {
  background-color: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>

<div id="root">
  <div style="height: 100vh; display: flex; flex-direction: column">
    <nav class="navbar navbar-dark navbar-expand bg-dark"><a class="navbar-brand" href="/">Title</a></nav>
    <div class="h-100" style="display: flex; overflow: hidden; flex-direction: row">
      <div style="flex: 1 1 auto; overflow-y: auto">
        <div id="foo" style="height: 1200px">
        </div>
      </div>
    </div>
  </div>
</div>

关于html - Flex with overflow 和 bootstrap navbar 在 Firefox/Chrome/Safari 中表现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53665488/

相关文章:

html - 如何使本网站的内容居中?

javascript - 使用 jQuery 单击将类添加到父类

javascript - firefox 插件 main.js 显示相同的请求响应,而不是更新

html - 如何垂直对齐填充页面的容器中的图像?

php - Y 轴上的值不会在 morris javascript 中传递

html - 使用 grep 从本地文件中的 HTML 标记中获取文本

html - CSS 居中多行文本但最短的行在最上面?

javascript - 根据第一个数字分割文本 javascript

javascript - 解析的 XML 文档中的 XPath 错误 (WrongDocumentError)

css - 如何使用 CSS 在 Mozilla Firefox 中启用子输入文本选择?