我有一个从数据库生成的列表,所以我没有特定的长度,我没有每行的HTML代码.. 但是我需要在列表的第一行设置一个特定的样式。 所以我问是否有可能告诉css只将样式应用于第一个元素,如果列表是动态的。
<tr>
<td class="align-center"><? echo $myvariable; ?></td>
</tr>
如果此TD生成例如40次,则只有第一个TD必须具有某种样式。这是可能的? 谢谢你的建议。
答案 0 :(得分:2)
如果您想首先定位tr
,请使用
table tr:first-child {
/* Styles goes here */
}
如果您想首先定位td
的{{1}},请使用
tr
如果您想定位每个table tr:first-child td:first-child {
/* Styles goes here */
}
td
tr
只是为了确保您定位到正确的table tr td:first-child {
/* Styles goes here */
}
,至少向table
提供class
或id
并在您的选择器中使用它。