位置:相对于 webkit 中的锚点已损坏。解决方法?

发布于 2024-08-11 15:42:21 字数 496 浏览 1 评论 0原文

在我们的项目中,我们使用以下方法将用户链接到页面上的某个锚定区域:

<span style="position: relative; top: -100px; z-index: -1; visibility: hidden;"
                   id="anchor">&nbsp;</span>

这用于在确切的锚定元素(如表单)之前留出一点空间。

输入图片此处的描述

但由于 Safari 的某些最新版本,这种情况已被破坏,浏览器定位在元素的初始位置,而不考虑相对位置。

也许您也遇到了这个功能/错误,并且有一些解决方案可以提出,或者可以指出为什么我的方法不好。

In our project we used the following method to link users to some anchorred area on the page:

<span style="position: relative; top: -100px; z-index: -1; visibility: hidden;"
                   id="anchor"> </span>

This was used to leave a little space before the exact anchorred element like a form.

enter image description here

But since some late version of Safari this has broken and browser is positioning at the initial position of the element with no regard to the relative position.

Maby you have met this feature/bug too and have some work around to propose or can point out why my method is bad.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情愿 2024-08-18 15:42:21

是的!感谢 Developer Art 提供的不正确但可用的答案,我得到了解决方案!

如果我将 id 和相对位置应用于锚定到 #id 的 DIV,则开始使用相对滚动!

Yep! hanks to the incorrect but usable answer by Developer Art i got the solution!

If i apply id and relative position to the DIV anchoring to the #id starts working with telative scroll!

寒冷纷飞旳雪 2024-08-18 15:42:21

为什么不将 ID 属性添加到相关元素(即 FORM)中?如果你想在表单前添加垂直间距,你可以使用 CSS:

<form id="anchor" style="margin-top: 100px;">
 …
</form>

问题消除了,代码更简洁:)

Why don’t you just add the ID attribute to the element in question, i.e. FORM? If you want to add vertical spacing before the form, you can use CSS:

<form id="anchor" style="margin-top: 100px;">
 …
</form>

Issue eliminated, and much cleaner code :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文