你会如何使用 CSS 样式background-attachment
并将其应用到<img>
tag?
<img src="ok.jpg">
CSS:
img {
background-attachment: fixed;
}
添加这个以防其他人来到这里想要复制的行为background-attachment: fixed;
当使用一个img
HTML 中的标签。
您不能在<img>
按要求标记,但您可以通过使用复制它的行为position: fixed
在图像上和clip-path
在它的容器上。
Example:
div {
position: relative;
height: 200px;
margin: 50px 10px;
clip-path: inset(0);
}
img {
object-fit: cover;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
body {
min-height: 400px;
}
<div>
<img src="https://picsum.photos/id/237/200/300">
</div>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)