css - 在 chrome 版本 57 中,固定的 css 位置在其父容器的左侧发生变化时表现奇怪

标签 css google-chrome

当位置固定的子元素出现在具有相对位置且其左侧在 javascript 中发生更改的容器元素内时,子元素会随着 chrome 57 中的容器移动。下面的代码解释了此行为。

$(document).ready(() => {
  setInterval(() => {
    $('.container').animate({
      left: "-=10",
    })
  }, 10)
});
.container {
  width: 1000px;
  height: 100px;
  background: #ccc;
  margin-left: 500px;
  position: relative;
}

.fix {
  padding: 20px;
  position: fixed;
  background: #000;
  color: #fff;
  width: 800px;
  top: 30px;
  border-bottom: 3px dashed #fff;
}
<div class="container">
  <div class="fix">
    Fixed
  </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

但在 firefox 和 chrome 56 中,无论容器元素如何,子元素都保留在同一位置。

这是最新版 chrome 中的错误吗?还检查了 chrome 57 的变更日志,其中没有说明这一点。

最佳答案

如果不覆盖固定元素的顶部和左侧,它们将由 webkit 渲染引擎定义为其相对父元素的顶部和左侧。在本例中为变化的左侧。尝试向固定元素添加左、右、下或上位置。

$(document).ready(() => {
  setInterval(() => {
    $('.container').animate({
      left: "-=10",
    })
  }, 10)
});
.container {
  width: 1000px;
  height: 100px;
  background: #ccc;
  margin-left: 500px;
  position: relative;
}

.fix {
  left:0;
  padding: 20px;
  position: fixed;
  background: #000;
  color: #fff;
  width: 800px;
  top: 30px;
  border-bottom: 3px dashed #fff;
}
<div class="container">
  <div class="fix">
    Fixed
  </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

关于css - 在 chrome 版本 57 中,固定的 css 位置在其父容器的左侧发生变化时表现奇怪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43199983/

相关文章:

HTML 5/CSS (??) 如何使 div 元素位于下一行?

html - 如何在行之间的分隔线上添加一些文本?

html - 什么是<<伪:before>></<pseudo:before>> and is it useful to me?

google-chrome - 禁用的下拉菜单具有蓝色背景

html - 在 HTML5 数字输入中强制使用小数点而不是逗号(客户端)

google-chrome - SSL、谷歌浏览器和 "non-secure"页面/表单

javascript - Chrome 跨站点资源 - 网站无法正常工作

html - CakePHP-Bootstrap 崩溃不起作用

javascript - "style-src ' self ' https://maxcdn.bootstrapcdn.com/bootstrap/"。 'unsafe-inline' 关键字,哈希

解析颜色值时出现 CSS 错误