【发布时间】:2019-07-10 14:14:20
【问题描述】:
我需要一个像Fixed right column table scales to responsive design 中描述的表格但是当我使用 css 定义背景颜色时,该规则不适用于固定列
Jsfiddle:https://jsfiddle.net/3ckvkr1f/2/
谢谢!
HTML
<div class="table-responsive">
<table class="table-striped" cellpadding="9">
<thead>
<tr>
<th>
col1
</th>
<th>
col2
</th>
<th class="crud-links"> Options</th>
</tr>
</thead>
<tr>
<td>
R1col1 alçkfjalçkfjalkjflaksjflaksj
</td>
<td>
R1col2 aslkfjasklçfjaklçfjasklfjasçklfjas
</td>
<td class="crud-links">
x
</td>
</tr>
<tr>
<td style="white-space: nowrap;">
R2col1 alçkfjalçkfjalkjflaksjflaksj slkfjsçklafjaslfkjsldk
</td>
<td style="white-space: nowrap;">
R2col2 aslkfjasklçfjaklçfjasklfjasçklfjas
</td>
<td class="crud-links">
x
</td>
</tr>
<tr>
<td style="white-space: nowrap;">
R3col1 alçkfjalçkfjalkjflaksjflaksj slkfjsçklafjaslfkjsldk
</td>
<td style="white-space: nowrap;">
R3col2 aslkfjasklçfjaklçfjasklfjasçklfjas
</td>
<td class="crud-links">
x
</td>
</tr>
</table>
</div>
CSS:
.table-striped > tbody > tr:nth-of-type(2n+1) {
background-color: blue;
}
.page-header {
padding-bottom: 9px;
margin: 40px 0 20px;
border-bottom: 1px solid #eeeeee;
}
.table-hover th, .table-hover td {
padding: 9px;
}
.table-responsive {
width: inherit;
max-width: 80%;
margin-bottom: 15px;
overflow-x: scroll;
overflow-y: hidden;
border: 0;
}
.crud-links{
position: absolute;
overflow:hidden;
width: 91px;
right: 0;
}
.table-striped > tbody > tr:nth-of-type(2n+1) {
background-color: blue;
}
【问题讨论】:
-
你说的是
.crud-links类的人吗?如果是这样,只需执行tr .crud-links { background: something; }- 或者您是在谈论它们在主要部分中没有得到与其他颜色相同的颜色?这是第一个解决方案的一个小技巧:jsfiddle.net/3ckvkr1f/4,如果你想让它们相同,只需使用 (odd)-selector 重新制作它,与表的其余部分相同。 -
感谢 junkfoodjunkie 这解决了我的问题。我怎样才能为这个答案投票?
-
我会把它变成一个答案。