css - 表行(:after)中的绝对定位元素不滚动
问题描述
对于一个客户,我正在改变他们网站的设计。我只能重写 CSS,我不能触摸 HTML。他们使用很多表格来展示他们的内容。当您单击表格行时,它会处于活动状态。使用绝对定位的:after
元素,我在行尾添加了一个箭头,起初看起来不错。但是(即使我添加position: relative;
到行中)当您向下滚动时箭头不会滚动。我添加了一个带有类似代码的 codepen 作为示例:
https://codepen.io/johnnynas/pen/oKoddz
是否可以通过仅更改 CSS而不更改 HTML来使箭头滚动?
.scroll-wrapper {
height: 275px;
overflow-x: hidden;
overflow-y: auto;
width: 500px;
}
table {
border-spacing: 0;
font-family: sans-serif;
line-height: 32px;
width: 100%;
}
tbody tr:nth-child(odd) {
background-color: #eee;
}
tbody tr.is-active {
background-color: blue;
color: white;
position: relative;
}
tbody tr.is-active:after {
border-color: transparent;
border-left-color: blue;
border-style: solid;
border-width: 16px 0 16px 8px;
content: "";
height: 0;
position: absolute;
width: 0;
}
td {
padding: 0 8px;
}
<div class="scroll-wrapper">
<table>
<thead>
<tr>
<th>Title 1</th>
<th>Title 2</th>
<th>Title 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr class="is-active">
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
<tr>
<td>Content</td>
<td>Content</td>
<td>Content</td>
</tr>
</tbody>
</table>
</div>
解决方案
推荐阅读
- reactjs - 在 Microsoft Graph Toolkit 中使用不同的配置文件图像大小
- c# - 防止`IndexOf`匹配全角“?”寻找半角“?” 当 LC_ALL 为“ja.UTF-8”时
- xamarin - 如何在 C# 中为 Xamarin 网格元素指定行跨度?
- r - 将来自不同数据框的条形图并排
- python - 尝试计算语义分割任务的平均 IoU
- javascript - 如何在表单中触发没有按钮标签的ngSubmit?
- javascript - 实现对象的默认字符串描述的跨浏览器方式
- node.js - 猫鼬中的保存功能不起作用
- json - 如何使用 Delphi 和 REST 组件将流包含到 json'body 中
- c++ - pthread_exit() 抛出警告:从不同大小的整数转换为指针 [-Wint-to-pointer-cast] 警告