处于粘性位置,何时为“保证金盒”未用作“位置框”?
w3.org在其定义中提到粘性定位,以下:以下:
位置框是其边缘框,除了在其边缘边缘和包含块的相应边缘之间的距离的任何一侧都小于其相应的边缘,该距离使用代替该边缘。
我试图复制这种情况
.container {
height: 100px;
background: lightgray;
overflow: auto;
}
.content {
background: gray;
border: 1px dotted red;
}
button {
position: sticky;
top: 40px;
margin: 30px 0;
}
.spacer {
height: 300px;
}
<div class="container">
<div class="content">
<button>sticky</button>
</div>
<div class="spacer"></div>
</div>
现在,粘性元素的边缘边缘与其包含块的相应边缘之间的距离是0
,它比其相应的边距小(40px
),因此根据W3.org的定义位置框不应是保证金框,而是粘性元素的大小加上0
。但是,如您在示例中看到的那样,位置框仍在尊重边距。
请说明为什么位置框与边距框相同。
w3.org mentions in it's definition of Sticky positioning, the following:
The position box is its margin box, except that for any side for which the distance between its margin edge and the corresponding edge of its containing block is less than its corresponding margin, that distance is used in place of that margin.
I have tried to replicate this scenario
.container {
height: 100px;
background: lightgray;
overflow: auto;
}
.content {
background: gray;
border: 1px dotted red;
}
button {
position: sticky;
top: 40px;
margin: 30px 0;
}
.spacer {
height: 300px;
}
<div class="container">
<div class="content">
<button>sticky</button>
</div>
<div class="spacer"></div>
</div>
Now the distance between sticky element's margin edge and the corresponding edge of its containing block is 0
which is less than the its corresponding margin(40px
), so according to w3.org's definition the position box should not be the margin box, instead should be sticky element's size plus 0
. But as you can see in the example, position box is still respecting the margin.
Please explain why is position box still same as margin box.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论