【问题标题】:Chrome 55: position: fixed; in div overflow: hidden; doesn't workChrome 55:位置:固定;在 div 溢出:隐藏;不工作
【发布时间】:2017-05-04 08:12:16
【问题描述】:

我将我的 chrome 更新到版本 55,现在我在 div overflow: hidden; 中的 position: fixed; 不再工作了。

这是一个例子: http://codepen.io/PRDev/pen/mOvwOO

.container {
  background: #d3d3d3;
}

.overflow {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  z-index: 1;
}

.parallax {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #dfdfdf;
}

.next-section {
  position: relative;
  z-index: 10;
  height: 200vh;
}
<div class="container">
  <div class="overflow">
    <div class="parallax">
      <h1>Headline</h1>
      <p>Lorem ipsum</p>
    </div>
  </div>
  <div class="next-section">
  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </div>
</div>

当我向下滚动时,文本在 div 溢出隐藏之外仍然可见,在 safari 和 chrome 54 上它是隐藏的,但在最新的 Chrome 55 中不可见。

在 .overflow 中的 chrome 54 文本隐藏在下一节中的文本后面,在 chrome 55 上,溢出中的此文本在下一节后面可见

【问题讨论】:

  • 您能否更清楚地说明这个问题?我的意思是,很明显你的“溢出”类不会将“下一节”中的文本作为子元素,那么你为什么希望它在溢出时隐藏
  • 你需要什么
  • 当你向下滚动你想隐藏.parallax div 对吗?
  • 在 .overflow 中的 chrome 54 文本隐藏在 .next-section 中的文本后面,在 chrome 55 上,.overflow 中的此文本在 .next-section 后面可见
  • @JishnuVS 是的,我想隐藏 .parralax div

标签: html css google-chrome


【解决方案1】:

我不认为这是如何溢出的问题:隐藏;作品。这决定了溢出其父级的内容会发生什么。您正在做的是将一个 div 移到另一个上,您看到后面的原因是因为 .next-section 没有背景。

.next-section同样的bg颜色background: #dfdfdf;

body {
  margin: 0;
}
.container {
  background: #d3d3d3;
}
.overflow {
  position: relative;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  z-index: 1;
}
.parallax {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #dfdfdf;
}
.next-section {
  background: #dfdfdf;
  position: relative;
  z-index: 10;
  height: 200vh;
}
<div class="container">
  <div class="overflow">
    <div class="parallax">
      <h1>Headline</h1>
      <p>Lorem ipsum</p>
    </div>
  </div>
  <div class="next-section">
    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor
    in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </div>
</div>

【讨论】:

  • 我知道当我添加背景时,它会正常工作。这不是我的问题。我有隐藏溢出的 div,我不想看到该 div 外面的元素。它在以前版本的 chrome 上工作正常
  • 您误解了溢出属性的作用。你有一个溢出的 div:hidden;这意味着任何流出该 div 的内容都将被隐藏(与滚动条相反)。那么你的 .overflow div 只包含 2 行

    Headline

    Lorem ipsum

    。它的高度为100vh;所以没有什么溢出......溢出不是决定下一部分是否隐藏它的原因。您一定更改了其他内容。
  • 好的,但是为什么这在 chrome 54 和更早版本上运行良好?我想要与 chrome 54、safari 等相同的效果。你能帮我解决这个问题吗?
  • 我已经在 chrome 55、FF IE11 和 Edge 中运行了您的 codepen,它们的工作方式完全相同。我不确定 safari,无法访问它。你一定改变了别的东西。您的真实代码在我可以查看的实时网站上可用吗?
  • 我把这个小提琴放在一起,希望能更好地解释溢出jsfiddle.net/bqncdg6t希望它有助于理解溢出做什么和不做什么。
猜你喜欢
  • 1970-01-01
  • 2014-10-10
  • 1970-01-01
  • 2012-08-09
  • 2013-07-29
  • 2015-09-03
  • 2012-09-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多