html - 列出具有逐渐增加的 CSS 属性的项目
问题描述
我正在处理table
呈现的 HTML,以便所有这些rows
都position
absolute
具有逐渐增加的top
属性。
.table{
position: relative;
}
tr{
position: absolute;
height: 25px;
text-align: center;
}
td, th{
width: 80px;
}
tr:nth-child(1){
top: 0;
}
tr:nth-child(2){
top: 25px;
}
tr:nth-child(3){
top: 50px;
}
<table>
<tr>
<th>header 1</th>
<th>header 2</th>
<th>header 3</th>
</tr>
<tr>
<td>c1</td>
<td>c2</td>
<td>c3</td>
</tr>
<tr>
<td>c11</td>
<td>c22</td>
<td>c33</td>
</tr>
我想做一些类似的事情,tr:nth-child(n){top: n*25px;}
而不是为每一行重复它。有没有办法使用纯CSS 做到这一点?
我知道这不是渲染表格的正确方法,我仍然很好奇是否有办法实现它。
解决方案
仅使用纯 css 您无法做到...
您可以使用 sass 文件执行此操作:
见这里:https ://jsfiddle.net/vpj3ek24/1/
.table{
position: relative;
}
tr{
position: absolute;
height: 25px;
text-align: center;
}
td, th{
width: 80px;
}
@mixin child($n) {
&:nth-child(#{$n}){
top:$n*25px;
}
}
div{
@include child(n);
}
推荐阅读
- python - 为什么 BigQuery API 调用需要这么长时间?
- java - 无法解析为变量 println
- google-apps-script - Google Scripts px 打印单元
- dart - 错误:编译失败。飞镖功能失败
- javascript - AXIOS:第一次调用 API 返回默认状态
- swagger - 定义具有固定和每个端点组件的全局响应结构的方法?
- sql-server - 从字符串插入仅插入第一行
- javascript - Highcharts:如何按类别对柱形图进行分组
- r - data.frames R 列表中元素的平均值
- javascript - JS:forEach 中的异步存在时间问题