mar*_*ark 5 css html-table padding
例:
<style type="text/css">
table {
border: 1px solid red;
border-collapse: collapse;
text-align: left;
}
#col-1 {
padding-left: 20px;
background-color: tan;
}
#specific-cell {
padding-left: 20px;
}
</style>
<table>
<col id="col-1">
<col id="col-2">
<tr>
<th>foo</th>
<th>bar</th>
</tr>
<tr>
<td>data1</th>
<td>data2</th>
</tr>
<tr>
<td id="specific-cell">data1</th>
<td>data2</th>
</tr>
<tr>
<td>data1</th>
<td>data2</th>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
颜色应用于列但不应用于填充.如果我直接在单元格上使用类/ ids,它就可以工作.
我被迫使用它们,还是有办法利用<col>标签?
它不应该工作,至少对于 CSS 2.1 来说是这样。您可以查看CSS 2.1 表列规范。
您可以通过使用:first-child和来规避此问题+:
/* first column */
td:first-child {
padding-left: 20px;
}
/* second column */
td:first-child + td {
padding-left: 10px;
}
/* third columns */ {
td:first-child + td + td {
padding-left: 0;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6065 次 |
| 最近记录: |