css - 背景附件效果:fixed but with img blocks and position

标签 css position

有没有办法实现background-attachment: fixed的效果, 而不是使用 background-image使用<img /> block 。

我想在不使用 background-image 的情况下实现这种效果https://codesandbox.io/s/kind-currying-iop7l

这样当滚动时,图像在它们之间转换时没有可见的接缝线。

我的布局如下

<body>
<section><img></section>
<section><img></section>
</body>

但无论我尝试什么,我都无法让 img 被它的父级剪辑 <section> .

我试过了 position: fixed对于 img .我用 z-index 试过了以及。 position: sticky在这种情况下不起作用,因为 img被它包含的父级推高而不是被剪掉。

最佳答案

我真的不明白你想要实现什么,但尝试使用父级的“溢出”属性。

[parent_selector]
{
    overflow: hidden;
}

关于css - 背景附件效果:fixed but with img blocks and position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57904005/

相关文章:

css - 为什么 <a> 和 <button> 元素的填充计算方式不同?

html - 如何阻止我网站的页眉移动?

Python Selenium - 纯粹基于其基于主体元素偏移量的位置点击元素

html - 部分彼此重叠

css - Internet Explorer 不显示具有相对定位和正确 float 的按钮

css - 文本渗入另一个 DIV 元素

Css 分层问题

c++ - 读取 std::vector<unsigned char> 中特定位置的数据

javascript - 带滚动的圆形 slider (jquery+css3)

html - 中间对齐包含字形图标和面包屑的 div