我有一个 HTML 表格,带有 <thead>
+ <tbody>
+ <tfoot>
.我需要显示 <tfoot>
仅当 <tbody>
没有行。我知道如何使用 JS/jQuery 来实现,但也许有纯 CSS 解决方案?
最佳答案
使用 :empty
Demo (当tfoot
没有行时显示tbody
)
table tbody:empty + tfoot {
display: table-footer-group;
}
table tbody + tfoot {
display: none;
color: red;
}
隐藏tfoot
什么时候tbody
有一些内容
table tbody:not(:empty) + tfoot {
display: block;
}
table tbody + tfoot {
display: none;
color: red;
}
解释:
修改太多,我只想提供2个选择器,第一个是table tbody:empty + tfoot
这将选择 tfoot
如果tbody
IS EMPTY,第二个是table tbody:not(:empty) + tfoot
这将选择 tfoot
如果tbody
不是空的。
Note: I am using
+
which is an adjacent selector, so as you see, I havetfoot
element, after thetbody
element, if it is beforetbody
than you need to useJS
orjQuery
as you select reverse in CSS. Also, make sure you usedisplay: table-footer-group;
as pointed by Mr Lister fortfoot
element and notdisplay: block;
关于html - CSS。仅当 TBODY 没有行时显示 TFOOT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19420117/