gpt4 book ai didi

html - 在不使用 jquery/javascript 的情况下查找文本并添加 css

转载 作者:太空狗 更新时间:2023-10-29 15:07:57 26 4
gpt4 key购买 nike

我有这样的表:

表 1:

<table> 
<tr>
<th>Title1</th>
<th>Title2</th>
<th>Title3</th>
<th>Title4</th>
</tr>
<tr>
<td>Text1</td>
<td>Text2</td>
<td>Text3</td>
<td>Text4</td>
</tr>
<tr>
<td>Text1</td>
<td>Text2</td>
<td>Text3</td>
<td>Text4</td>
</tr>
</table>

表 2:

<table> 
<tr>
<th>Title1</th>
<th>Title2</th>
<th>Title4</th>
</tr>
<tr>
<td>Text1</td>
<td>Text2</td>
<td>Text4</td>
</tr>
<tr>
<td>Text1</td>
<td>Text2</td>
<td>Text4</td>
</tr>
</table>

表 3:

<table> 
<tr>
<th>Title4</th>
</tr>
<tr>
<td>Text4</td>
</tr>
<tr>
<td>Text4</td>
</tr>
</table>

这里我有 3 个表(3 个表不是常量。但是所有表都有 Title4 标题但位置不同。我只需要更改文本“Title4”的所有表的颜色而不使用 jquery/javascript。仅在 css 中使用。有什么建议吗?

最佳答案

来自@shaggy 的更新要点:你想要做的是添加一个类(类被多次使用)这是 css 选择器 .每个 <th>将包含 Title4 的元素。

<th class="blue">Title4</th>

.blue {
color: blue;
}

http://codepen.io/anon/pen/gpXQOM

留作引用,这应该可以使用第 n 个子选择器。它利用了能够选择元素的某个子元素的优势。它首先寻找任何 <table>那么 (4) 代表第四个 <th>在这里的表格中是 title4!

 table th:nth-child(4) {
background: blue;
}

关于html - 在不使用 jquery/javascript 的情况下查找文本并添加 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31043511/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com