html - 是否可以让 scroll-margin-top 在 Safari 中工作?

标签 html css safari

我在 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/

相关文章:

javascript - window.onresize 在 iPad 上连续调用

javascript - 将 html5 canvas 保存为图像

Python Bottle <br/> 不工作?

jquery - `overflow-x: hidden` 内的元素仍然有宽度(Safari)

mobile - 通过 HTML 在 Mobile Safari 上实现 UIPickerview

css - 如何在 mvc razor 中对齐编辑器的文本框?

html - 字体大小使用 em 还是 px?

javascript - 获取td文本jquery过滤后tr的索引

html - 使用 CSS 动态调整最小和最大尺寸之间的 div 高度

javascript - 如何确保文本/链接的 CSS 不透明度更改不会更改 Firefox/Windows 中的颜色值?