我在 anchor 上使用 scroll-margin-top 为我的粘性标题添加空间,但它在 Safari 中不受支持。
这些文档在这里 - https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-margin指出这个错误 -
Scroll margin is not applied for scrolls to fragment target or scrollIntoView(), see bug 189265.
Aternate Name Uses the non-standard name: scroll-snap-margin
有没有办法解决这个错误?
最佳答案
这是迄今为止我发现的唯一在 Safari 和 Firefox 中都有效的解决方案......特定于 Safari 的选择器。这并不理想,因为在 Safari 元素中使用填充会限制您可以使用的样式,但它胜过我尝试过的所有其他方法。
.anchor { scroll-margin-top: 130px; }
.anchor::-webkit-full-page-media, .anchor:future, .anchor:root .safari_only { padding-top: 130px;}
关于html - 是否可以让 scroll-margin-top 在 Safari 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63637410/