嗨我有一个像下面这样的表格,我想只为那个属于section的tr应用样式。
<table>
<thead>
<tr>
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
</thead>
<tbody>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>
当我尝试以下时,它会申请所有trs,包括trs。
<style type="text/css">
tr
{
height:30px
}
</style>
如何限制此样式仅适用于标题部分。
答案 0 :(得分:2)
使用,
th
{
height:30px
}
否则你可以使用课程
答案 1 :(得分:1)
试试这个:
<style type="text/css">
tr
{
height:30px
}
thead > tr:first-child
{
//put anything you want here
}
</style>
答案 2 :(得分:1)
您可以向该tr添加一个类,并在css中指定该类,如下所示:
<table>
<thead>
<tr class="give-style">
<th>1</th>
<th>2</th>
<th>3</th>
<th>4</th>
</tr>
</thead>
<tbody>
<tr>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
</tr>
</tbody>
</table>
在css中:
<style type="text/css">
.give-style
{
height:30px
}
</style>
这应该可以解决问题,如果它通过单击左侧的刻度符号来解决您的疑问,请选择此作为正确的答案。
答案 3 :(得分:1)
像这样使用
<tr class="my_class">
</tr>
然后在你的CSS中,使用“。”引用它。你的类名前面('my_class')
.myclass{
//your styles go here
}