如何使用 CSS 将第二个 select 放入具有特定 ID 的 table 的首字母中?
How to select the second th into the thead of a table having a specific ID using CSS?
我有一个呈现以下内容的脚本 table。我需要在第二个 th
元素上设置样式。 (包含值“2”的那个)
<table id="sentbox" class="standard-table-cls">
<thead>
<tr>
<th style="border-left: medium none;">1</th>
<th>2</th>
<th class="sortable">3</th>
<th class="sortable">4</th>
<th class="sortable">5</th>
<th class="sortable">6</th>
<th class="sortable">7</th>
</tr>
</thead>
.................................................
.................................................
.................................................
</table>
因为 table 是由脚本呈现的,所以我无法将 class 或任何内联 CSS 添加到 <th>2</th>
。
是否有 CSS 选择器可以让我定位有问题的元素?
CSS
#sentbox thead tr th:nth-of-type(2){
\css goes here
}
:nth-of-type()
selector matches every element that is the nth child, of a particular type, of its parent.
演示
#sentbox thead tr th:nth-of-type(2) {
background: yellow;
}
<table id="sentbox" class="standard-table-cls">
<thead>
<tr>
<th style="border-left: medium none;">1</th>
<th>2</th>
<th class="sortable">3</th>
<th class="sortable">4</th>
<th class="sortable">5</th>
<th class="sortable">6</th>
<th class="sortable">7</th>
</tr>
</thead>
</table>
当然,使用第 n 个子选择器
#sentbox thead tr th:nth-child(2) {
...
}
你应该这样尝试-
#sentbox th:nth-child(2){your style}
#sentbox tr th:nth-child(2){
}
我有一个呈现以下内容的脚本 table。我需要在第二个 th
元素上设置样式。 (包含值“2”的那个)
<table id="sentbox" class="standard-table-cls">
<thead>
<tr>
<th style="border-left: medium none;">1</th>
<th>2</th>
<th class="sortable">3</th>
<th class="sortable">4</th>
<th class="sortable">5</th>
<th class="sortable">6</th>
<th class="sortable">7</th>
</tr>
</thead>
.................................................
.................................................
.................................................
</table>
因为 table 是由脚本呈现的,所以我无法将 class 或任何内联 CSS 添加到 <th>2</th>
。
是否有 CSS 选择器可以让我定位有问题的元素?
CSS
#sentbox thead tr th:nth-of-type(2){
\css goes here
}
:nth-of-type()
selector matches every element that is the nth child, of a particular type, of its parent.
演示
#sentbox thead tr th:nth-of-type(2) {
background: yellow;
}
<table id="sentbox" class="standard-table-cls">
<thead>
<tr>
<th style="border-left: medium none;">1</th>
<th>2</th>
<th class="sortable">3</th>
<th class="sortable">4</th>
<th class="sortable">5</th>
<th class="sortable">6</th>
<th class="sortable">7</th>
</tr>
</thead>
</table>
当然,使用第 n 个子选择器
#sentbox thead tr th:nth-child(2) {
...
}
你应该这样尝试-
#sentbox th:nth-child(2){your style}
#sentbox tr th:nth-child(2){
}