【发布时间】:2012-10-28 10:29:12
【问题描述】:
例如我有这个:
<div>
<a href="#">sample 1</a>
<a href="#">sample 2</a>
<a href="#">sample 3</a>
</div>
我想用 CSS 定位第一个链接。
【问题讨论】:
标签: css pseudo-class targeting
例如我有这个:
<div>
<a href="#">sample 1</a>
<a href="#">sample 2</a>
<a href="#">sample 3</a>
</div>
我想用 CSS 定位第一个链接。
【问题讨论】:
标签: css pseudo-class targeting
您可以使用第一个子选择器:
div > a:first-child { /* your css */ }
【讨论】:
试试这个代码:
div > a:first-child{
//your css code
}
【讨论】:
div a:nth-of-type(n)
{
/* css */
}
其中 n 是您想要的行数.. 在你的情况下
div a:nth-of-type(1)
{
/* css */
}
【讨论】:
:first-child 更简洁易读。更多浏览器也支持它。