CSS选择< thead>或< tbody>来自< table>
我有以下问题。我有很多桌子,但是它们都有不同的结构:一个具有< table; ;
。
而且我需要将CSS应用于Thead(如果在表中设置)或Toby(始终设置)。我不应该为他们两个设置样式,而只是为第一个追随< table'
标签的样式。
因此,如果我有
<table>
<thead>...</thead>
<tbody>...<tbody>
</table>
CSS,则应仅适用于Thead。
反之亦然,如果我有:
<table>
<tbody>...</tbody>
<table>
则应将CSS应用于Tbody。
我希望有类似的东西“如果设置了thead,那么...'
I have the following problem. I have plenty of tables, but they all have different structure: one have <table><thead><tbody>
type, while the others have <table><tbody>
only.
And I need to apply css for thead (if it set in table) OR to tbody (it is set always). I shouldn't set styles for both of them, only for the first who goes after <table>
tag.
So if I have
<table>
<thead>...</thead>
<tbody>...<tbody>
</table>
then CSS should be applied only for thead.
And vice versa if I have:
<table>
<tbody>...</tbody>
<table>
then CSS should be applied for tbody.
I wish there was something like 'if thead is set then...'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果是一个选项,则可以使用
:First-Child
选择器。例如,您将选择其中一个,这是
&lt; table; table; gt;
的第一个孩子:在这种情况下,如果存在
thead
,则将不是第一个孩子。否则,如果没有thead
,则tbody
将是第一个孩子。在行动中看到它:
If that is an option, you could use a hack with
:first-child
selector.For example, you will select either one of them which is the first child of a
<table>
:In this case, if a
thead
is present,tbody
will not be the first child. Otherwise, if there is nothead
,tbody
will be the first child.See it in action: