For example I have this:

<div>
  <a href="#">sample 1</a>
  <a href="#">sample 2</a>
  <a href="#">sample 3</a>
</div>

I want to target the first link with CSS.

有帮助吗?

解决方案

You can use the first-child selector:

div > a:first-child { /* your css */ }

其他提示

Try this code:

div > a:first-child{
   //your css code
}
div a:nth-of-type(n)
{
   /* css */
} 

where n is the number of line you want.. in your case

div a:nth-of-type(1)
{
   /* css */
} 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top