css - css 中第一个可见的 td 和最后一个可见的 td

标签 css

我正在尝试为 tr 中第一个和最后一个可见的 td 设置样式。 我可以使用 jquery 实现上述目标,但在我的情况下需要处理许多场景并且测试需要时间。

经过大量研究,我无法在 css 中得到任何东西。

是否有任何其他简单的 hack 或解决方法,以便我只能使用 css 实现。

下面是几个我试过的选项

.visible {
display : block;
}

.hidden {
display : none;
}

td:first-child {
}

td:last-child {
}

td.visible:first-child {
}

td.visible:last-child {
}

最佳答案

There is not in css move to backward,so we can't select td with class cant with pure css.

.hidden  {
  visibility: hidden;
}

.cant {
  background-color: orange!important;
}

tr td.hidden + td:not(.hidden) , tr td:not(.hidden):first-child { 
  background-color: red;
}

tr td.hidden + td:not(.hidden) ~ td , tr td:not(.hidden):first-child ~ td { 
  background-color: unset;
}

tr td:not(.hidden):last-child,tr td:not(.hidden):last-child {
  background-color: red!important;
}
<table border="1">
  <tr>
    <td class="hidden">This is TR1_TD1</td>
    <td>This is TR1_TD2</td>
    <td class="hidden">This is TR1_TD3</td>
    <td>This is TR1_TD4</td>
    <td>This is TR1_TD5</td>
  </tr>
 <tr>
    <td>This is TR2-TD1</td>
    <td class="hidden">This is TR2-TD2</td>
    <td class="hidden">This is TR2-TD3</td>
    <td class="cant">Can't with Pure Css</td>
    <td class="hidden">This is TR2-TD5</td>
  </tr>
</table>

关于css - css 中第一个可见的 td 和最后一个可见的 td,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50443591/

相关文章:

html - SVG 动画在悬停时重置

html - Visual Composer 文本对齐

javascript - 当网站内容溢出时,无法向上滚动?

css - 如何使用 Rails、Cucumber 和 Capybara 测试 Dropzone.js 上传?

css - 如何切断两个并排div中第二个的下半部分?

html - bootstrap v3.3.6 - 垂直对齐 bootstrap 列中的内容

浏览器调整大小时 CSS 100% 宽度

html - Border-radius 在应用时会在美学上中断.. Bug?

javascript - 使用 angularJS 在表中禁用行向上/向下移动的第一列

css - 继承属性然后在特定站点上更改一些属性(css)