【问题标题】:Chrome/Firefox difference with negative margin bottom percentageChrome/Firefox 与负边距底部百分比的差异
【发布时间】:2016-09-05 10:31:58
【问题描述】:

我在 webkit 和 Firefox 之间使用父母的高度 100% 来解释盒子大小的差异。

HTML:

<header>
  Lorem ipsum dolor amet
</header>
<div class="wrapper">
  <div class="content">
    My background depends on my ancestor sibling
  </div>
</div>
<div class="red">
  <p class="white">
  Amet ipsum dolor
  </p>
</div>

CSS:

header {
  height: 150px;
  background: #fff;
}
.red {
  background: red;
  padding: 6em 0;
}
.content {
  background: rgba(28,28,28, .3);
  margin-bottom: -100%;
}
.wrapper {
  position: relative;
  height: 100%;
}
p.white {
  background: #fff;
  width: 70%;
  margin: 0 auto;
}

这里的JS小提琴https://jsfiddle.net/m1fobvwv/

Chrome 上的结果(预期):

FF 上的错误结果:

【问题讨论】:

标签: css height percentage


【解决方案1】:

我的一位同事找到了解决方法:

position: absolute; width: 100%; 添加到.content

更新小提琴https://jsfiddle.net/m1fobvwv/3/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-01
    • 2017-02-07
    • 2019-05-08
    • 2011-08-30
    • 2015-02-09
    • 2018-06-22
    • 2020-04-03
    • 2014-08-01
    相关资源
    最近更新 更多