有没有办法实现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/