简体   繁体   English

仅当类第一次或最后一次出现时才应用 CSS

[英]Apply CSS only if first or last occurence of a class

I have an HTML table with many rows我有一个包含多行的 HTML table

 ________________________
|_1______________________|
|_2______________________|
|_3______________________|
|_4______________________|
|_5______________________|

These rows are expandable, and a user might expand multiple of them这些行是可扩展的,用户可能会扩展其中的多个行

 ________________________
|_1______________________|
| 2                      |
| border-top             |
| border-bottom          |
|________________________|
|_3______________________|
| 4 ...                  |

I need to highlight with border-top and border-bottom the expanded rows.我需要用border-topborder-bottom突出显示展开的行。

However, if two adjacent rows are expanded, the border-bottom of the above one merges with the border-top of the below one.但是,如果扩展相邻的两行,则上面一行的border-bottom与下面一行的border-top合并。
Having a border of 1px results 1px + 1px , which I don't want.1px的边框会导致1px + 1px ,这是我不想要的。

Is this situation avoidable using CSS selectors?使用 CSS 选择器可以避免这种情况吗?

If I well understood: if 2 adjacents rows are open, the second row should hides its top-border to avoid a double border ?如果我很好理解:如果 2 个相邻的行打开,第二行应该隐藏它的上边框以避免双边框?

You can perform this with the sibling operator + .您可以使用同级运算符+执行此操作。

.row-expanded + .row-expanded {
  border-top: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM