Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于以下标记的CSS选择器_Css_Css Selectors - Fatal编程技术网

用于以下标记的CSS选择器

用于以下标记的CSS选择器,css,css-selectors,Css,Css Selectors,我有一些html代码如下: <table> <tr> <td>first line </td> <td>second line </td> <td>third line </td> </tr> </table> 一线 第二线 第三行 我只希望“第一行”是红色的。 *我无法为标记使用内联样式或设置类。我可以使用外部CSS文件。您可以使用选择器

我有一些html代码如下:

<table>
  <tr>
    <td>first line </td>
    <td>second line </td>
    <td>third line </td>
  </tr>
</table>

一线
第二线
第三行
我只希望“第一行”是红色的。 *我无法为标记使用内联样式或设置类。我可以使用外部CSS文件。

您可以使用选择器。从文件开始:

:first child
CSS伪类表示一组同级元素中的第一个元素

演示:

表tr td:第一个孩子{
颜色:红色;
}

一线
第二线
第三行

您可以使用类型的第一个

表td:第一种类型{
颜色:绿色;
}

一线
第二线
第三行