html - Safari/Chrome flex-parent 100% height + padding 和 100% height child

标签 html css google-chrome safari flexbox

Safari 使 child block 的高度大于 Chrome。

我需要在 Chrome 和 Safari 中实现相同的阻止行为。

Chrome 中的内边距会影响 child 的高度。 Safari 中的填充总和为 height

.body {
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
  height: 100%;
}

.header {
  height: 60px;
  width: 100%;
}

.ctn {
  height: 100%;
  width: 100%;
  padding-bottom: 80px;
}

.ctn__child {
  min-width: 100%;
  height: 100%;
}

https://jsfiddle.net/zqjpzLLb/

最佳答案

使用 JSFiddle 时,您的 iframe 客户端高度是否相同?因为这些也会影响高度。

我已经设法使用以下代码获得相同高度的跨浏览器:

* {box-sizing: border-box;}

body, html {
  height: 100%;
}

.body {
  display: flex;
  justify-content: flex-start;
  flex-direction: column;
  flex-wrap: nowrap;
  height: 100%;
  background-color: #4f4;
}

.header {
  height: 60px;
  width: 100%;
  background-color: #4a4;
}

.ctn {
  display: inherit; /* Inherit display flex for __child grow inside */
  flex-grow: 1; /* Make sure it fills up the remaining parent space */
  width: 100%;
  padding-bottom: 80px;
  background-color: blue;
}

.ctn__child {
  flex-grow: 1; /* Let the child fill all the remaining space inside the .ctn class */
  min-width: 100%;
  background-color: rgba(255, 100, 100, .8);
}
<div class="body">
  <div class="header">Header</div>
  <div class="ctn">
    <div class="ctn__child">
      child
    </div>
  </div>
</div>

https://jsfiddle.net/zqjpzLLb/17/

关于html - Safari/Chrome flex-parent 100% height + padding 和 100% height child,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39526896/

相关文章:

javascript - 样式选择选项最佳实践

Javascript 运动检测

java - 如何使用 Selenium 关闭 Chrome 的下载对话框(通过单击取消)

html - 媒体查询不适用于带有网格的响应式网页设计

html - 大图像仍然会破坏具有最大宽度和高度的引导列

javascript - 如何改进我使用 Textmate for Ruby on Rails、HTML、CSS 和 Javascript 的方式?

css - 两列 div 布局,文本右对齐

javascript - 如何为 Insomnia 或 Postman 等 'packed chrome apps' 启用 JavaScript?

google-chrome - 在 chrome 和 firefox 中启用 ActiveX 控件

html - 实时预览/所见即所得对 Notepad++ 的支持?