css - 位置固定不起作用就像绝对一样

标签 css

<分区>

我的问题很简单。我在移动版的页面上工作,我们希望将“snag it”黄色按钮固定在底部,但固定位置不起作用,它的工作方式类似于绝对位置,我不知道为什么。

我正在处理的页面:https://www.thechivery.com/products/everything-is-j-ok-tee

谢谢, 路易斯

最佳答案

这里的问题在于您的 .content-container 包装器类,它具有 webkit-transform: translate3d(0,0,0) 的 CSS 声明。转换声明,如 this answer illustrates , 将定位上下文从视口(viewport)更改为旋转元素,这实际上意味着您的 fixed 元素的行为就好像它是绝对定位的一样。下面的示例显示了转换后的 div 内的固定元素与该 div 外的固定元素之间的区别。

.rotate {
  transform: rotate(30deg);
  background: blue;
  width: 300px;
  height: 300px;
  margin: 0 auto;
}
.fixed {
  position: fixed;
  background: red;
  padding: 10px;
  color: white;
  top: 50px;
}
<div class="rotate">
  <div class="fixed"> I am fixed inside a rotated div.</div>
</div>
<div class="fixed"> I am fixed outside a rotated div.</div>

为了一切正常,您需要从 .content-container 中删除 transform3d 声明。

关于css - 位置固定不起作用就像绝对一样,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36855473/

相关文章:

css - 无限宽度的宽 div

html - 如何删除 CSS 中的悬停样式

javascript - 在滚动 div 中添加选中复选框的值

css - Angular 5 : How to define color pallet in a central file

javascript - 如何获取文档的整个宽度和高度(无 jQuery)

javascript - 希腊语和文本转换 :uppercase

asp.net - 运行时网页发生变化

CSS3/HTML 5/PNG 模糊元素后面的内容

html - 在 flexbox 中保持一个元素居中于两个不同宽度的元素之间

html - CSS 背景图像。在文本上的位置