css - 正文未扩展以包含 Chrome 中动态添加的后代

标签 css google-chrome

我在使用 Chrome 时遇到了一个奇怪的问题,希望进行完整性检查。我有以下网页:

<html>
<head>
<style>

html {
  height: 100%;
}
body {
  min-height:100%;
  outline: 5px solid orange;
}

#app-container, .uof-page, .timeline-container {
    display: flex;
    flex-flow: column;
    flex: 1;
    min-height: 100%;
}
</style>
</head>
<body>
  <button id="btn">Click me to add tall element</button>
  <div id="app-container">
    <div class="uof-page">
      <div class="timeline-container">
        <div class="mdl-grid discussion-thread">
          <div class="discussion-messages">
            Some initial content
          </div>
        </div>
      </div>
    </div>
  </div>
</body>
<script>
document.querySelector('#btn').addEventListener('click', function() {
  var x = document.querySelector('.discussion-messages');
  x.innerHTML += '<p style="height:2000px;outline:1px solid red;">Foo</p>';
});
</script>
</html>

当我在我的本地文件系统上运行它时,Chrome 不会在单击按钮时展开正文以容纳新的后代。

我尝试使用 jsfiddle 设置测试用例,但无法复制该行为。 https://jsfiddle.net/r0ya42g9/

有人想知道为什么会发生这种情况吗?

最佳答案

我认为您的问题是,当您只应该将容器设为 flex 元素时,您却将每个子元素设为 flex 元素。一旦将容器设置为 flex,所有子项都是 flex。示例代码在任何浏览器上都没有给我扩展的 div。下面的这个 CSS 似乎对我有用。

<html>
<head>
<style>
html {
  height: 100%;
}
body {
  min-height:100%;
  outline: 5px solid orange;
}

#app-container {
   display: flex;        

   flex-flow: column;
   flex: 1;
   min-height: 100%;
outline: 1px solid blue;
}
</style>
</head>
<body>
<button id="btn">Click me to add tall element</button>
<div id="app-container">
<div class="uof-page">
  <div class="timeline-container">
    <div class="mdl-grid discussion-thread">
      <div class="discussion-messages">
        Some initial content
      </div>
    </div>
  </div>
</div>
</div>
</body>
<script>
document.querySelector('#btn').addEventListener('click', function() {
var x = document.querySelector('.discussion-messages');
x.innerHTML += '<p style="height:2000px;outline:1px solid red;">Foo</p>';
});
</script>
</html>

关于css - 正文未扩展以包含 Chrome 中动态添加的后代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38254068/

相关文章:

css - 在 chrome 调试器/DevTools 面板中卡住屏幕以进行弹出窗口检查?

javascript - 使用 Chrome 扩展从网页中删除图像

asp.net - 在 Google Chrome 中使用 KIOSK 模式进行静默打印(直接)

javascript - 使用带有括号的图像 URL 作为 jQuery 的背景

html - Bootstrap 和 CSS - 修复药片的格式

html - 页脚不是父 Div 的宽度

javascript - Chrome 中的 Bootstrap 4 轮播响应问题

google-chrome - 2020 年 8 月 10 日更新后,Chrome 不会在 iframe 中发回 cookie

css - 如何在两个 css 样式文件(rtl、ltr)vue.js 之间切换

css - 页脚下和页面右侧的空白