1

嗨,我有一张像下面这样的表格,我只想为属于部分的 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>

如何限制此样式仅适用于标题部分。

4

4 回答 4

2

利用,

th
{
height:30px
}

否则你可以使用类

于 2013-07-17T05:48:38.273 回答
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>

这应该可以解决问题,如果通过单击左侧的勾号解决了您的疑问,请选择此作为正确答案。

于 2013-07-17T05:50:01.597 回答
1

尝试这个:

<style type="text/css">
tr
{
height:30px
}

thead > tr:first-child
{
//put anything you want here
}
</style>
于 2013-07-17T05:48:33.523 回答
1

像这样使用它

<tr class="my_class">

</tr>

然后在您的 CSS 中,使用“。”来引用它。在你的班级名前('my_class')

.myclass{
    //your styles go here
}
于 2013-07-17T05:53:54.800 回答