Reputation: 355
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.
Upvotes: 7
Views: 15014
Reputation: 35973
Try this code:
div > a:first-child{
//your css code
}
Upvotes: 10
Reputation: 3738
You can use the first-child selector:
div > a:first-child { /* your css */ }
Upvotes: 18
Reputation: 32130
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 */
}
Upvotes: 3