質問

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