javascript - 在 Safari 中使用表格滚动边距顶部?
问题描述
我有一些粘性标题和指向表中行的锚链接。我试图找出一种方法让 safari 滚动到这些行而不将它们隐藏在粘性标题后面。在其他浏览器 scroll-margin-top 作品中,如何在 Safari 中进行这项工作?我尝试了一些使用负边距或伪元素的技巧,但没有成功。纯 CSS/HTML 解决方案可以做到这一点吗?
.heading {
background: #ccc;
height: 50px;
line-height: 50px;
margin-top: 10px;
font-size: 30px;
padding-left: 20px;
position: -webkit-sticky;
position: sticky;
top: 0px;
}
.section, tr {
margin: 0;
scroll-margin-top: 50px;
}
<body>
<article class="section" id="config"><h2 class="heading">My Header</h2>
<a href="#test">test</a><br>
<a href="#moretest">moretest</a><br>
<a href="#testagain">testagain</a><br><br><br><br><br><br><br><br><br><br><br><br>
</article>
<article class="section" id="config"><h2 class="heading">Table</h2>
<br>
<table>
<tr id="test">
<td>test</td>
<td>content</td>
<td>hello</td>
</tr>
<tr id="moretest">
<td>moretest</td>
<td>morecontent</td>
<td>hello</td>
</tr>
<tr id="testagain">
<td>testagain</td>
<td>content again</td>
<td>hello again</td>
</tr>
</table>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>...
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>...
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>...
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>...
</article>
</body>
解决方案
推荐阅读
- apache - Apache 安全设置 - 不确定在 Config 文件中的位置
- python - `TfidfVectorizer` 以什么方式处理个位数的数字?
- kendo-ui - 更改剑道文本框值会丢失格式
- python - XGBoost 与多标签
- angular - Angular Material Object(...) 不是函数
- ios - Stripe paymentContext 确实将 paymentContext.selectedPaymentOption 设置为默认卡
- reactjs - 如何将事件处理程序添加到第三方表单组件中的按钮
- bash - 在 Jenkins 作业中共享数据 beetwen 脚本
- python - 如何将包含空格的字符串添加到 Tkinter Treeview 列
- javascript - JavaScript如何同时过滤两个数组