【发布时间】:2016-12-17 04:24:52
【问题描述】:
我有以下。但是样式只适用于<th>。我尝试了#test-table td, #test-table th {} 和#test-table td th {},但没有任何应用。
css:
#test-table td, th {
color: white;
background-color: yellow;
text-align: left;
}
代码:
<table className="test-table">
<thead>
<tr>
<th>head1</th>
<th>head2</th>
<th>head3</th>
</tr>
</thead>
<tbody>
<tr>
<td>col1</td>
<td>col2</td>
<td>col2</td>
</tr>
</tbody>
</table>
如何将样式应用于<td> 和<th>? css 选择器尤其是 ReactJS 的正确层次结构通常是什么?例如容器通常是className 吗?任何内部元素都用id 定义?
编辑
如何实现:
尝试了以下方法但不起作用:
<table className="test-table">
<thead>
<tr>
<th colspan="2">List</th>
<th rowspan="2">Monday</th>
<th rowspan="2">Tuesday</th>
</tr>
<tr>
<th>Names</th>
<th>Class 1</th><th>Class 2</th>
<th>Class 1</th><th>Class 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>Kev</td>
<td>abc</td><td>def</td>
<td>ghi</td><td>jkl</td>
</tr>
</tbody>
</table>
【问题讨论】:
-
创建小提琴或sn-p请使用
!important -
在 CSS 中,类选择器是
.,而不是#符号。此外,类的 HTML 属性是class="",而不是className=""。 ReactJS 与您发布的代码或问题有什么关系? -
@TylerH 在反应中是
className因为class是 JS 的保留字 -
@JordanS 可能是这样,但用户在他的问题中发布了似乎是 HTML 的内容,即
class。 -
但是鉴于标题、描述、代码和标签,我猜这是反应......
标签: javascript html css reactjs