如何使用CSS定位div内的第一个链接?

Dan*_*per 5 css pseudo-class targeting

例如我有这个:

<div>
  <a href="#">sample 1</a>
  <a href="#">sample 2</a>
  <a href="#">sample 3</a>
</div>
Run Code Online (Sandbox Code Playgroud)

我想用CSS定位第一个链接.

sti*_*ksu 13

您可以使用第一个子选择器:

div > a:first-child { /* your css */ }
Run Code Online (Sandbox Code Playgroud)


Ale*_*eri 8

试试这段代码:

div > a:first-child{
   //your css code
}
Run Code Online (Sandbox Code Playgroud)