【问题标题】:How to target table with ID?如何使用 ID 定位表?
【发布时间】:2014-09-23 22:51:06
【问题描述】:

我正在使用数据表并使用下面的 css 来隐藏表格的标题。

table.dataTable thead {
    display: none;
}

现在发生的事情是我有两个表,ID 为 userList1userList2

我想要做的只是将此 css 应用于 id 为 userList1 的表。

知道如何完成这项工作吗?

我试过了

#userList1.table.dataTable thead {
    display: none;
}

#userList1 > table.dataTable thead {
    display: none;
}

但没有一个工作。

我不确定上面是对还是错,但我试过了。我是 CSS 新手。


HTML代码是

表 1

<table id="userList" class="responsive dataTable" dir="LTR" style="width: 100%;border: 0px;" aria-describedby="userList_info">

表 2

<table id="userList:2:userList2" class="responsive appointments" dir="LTR"></table>
<table id="userList:1:userList2" class="responsive appointments" dir="LTR"></table>
<table id="userList:0:userList2" class="responsive appointments" dir="LTR"></table>

注意:我有两张桌子..

表 1 有内表作为表 2...

所以我的桌子是

<table id="userList" class="responsive dataTable" dir="LTR" style="width: 100%;border: 0px;" aria-describedby="userList_info">

    <table id="userList:2:userList2" class="responsive appointments" dir="LTR"></table>
    <table id="userList:1:userList2" class="responsive appointments" dir="LTR"></table>
    <table id="userList:0:userList2" class="responsive appointments" dir="LTR"></table>

</table>

注意我使用的是 JSF 语言,内表 ID 是由 JSF 创建的...

JSFiddle Link

【问题讨论】:

  • 这里#userList1.dataTable thead 或只是#userList1 thead 你的原始代码不起作用,因为table 不是一个类,所以#userList1.table 没有任何目标。如果这些不起作用,那么您将需要提供表格标记。只是表格标签就可以了,不需要它的胆量
  • 请提供您的 HTML 示例
  • 为什么不只是#userList1 thead {display: none;}
  • #userList&gt;thead{...} ?
  • 下次如果您使用实际使用的 HTML 更新而不是多次更新它会非常好。

标签: html css jsf jsf-2


【解决方案1】:

试试这个:

#userlist.dataTable thead {
display:none;
}

你应该使用 display:none;仅适用于您要隐藏的标题。

对于只隐藏一个标题,您可以使用内联样式。

    <table id="userList" class="dataTable" border="1">
        <thead style="display:none;">
            <tr>
                <td>This is what I want to hide</td>
            </tr>
        </thead>

JSFIDDLE

【讨论】:

  • 您可以编辑 HTML 并使用内联样式。我编辑了答案。
【解决方案2】:

如果要隐藏外表的表头:

#userList thead {
  display: none;
}

如果要隐藏所有内表的表头:

#userList table thead {
  display: none;
}

如果你想隐藏其中一个内表的表头,基于@steveax的解决方案:

#userList #userList\:2\:userList2 thead {
  display: none;
}

【讨论】:

  • @FahimParkar 您要定位到哪个表,只需执行#tableID thead 就可以了
  • 如果我使用您的代码,表格标题内部也会被隐藏...请再次查看我的问题,我已经更新了代码..查看内部表格 ID...我认为这会导致问题。 ..
  • 我的代码正在生成这样的 id.. 我没有生成......我正在使用 JSF 及其生成的 id 这样......
  • 请再检查一次更新的问题。我已经简单明了...看看我最后的表格...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-08-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-01
  • 2014-05-30
  • 2017-03-20
相关资源
最近更新 更多