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.
URLs with an # followed by an anchor name link to a certain element within a document. The element being linked to is the target element. The :target selector can be used to style the current active target element.
The :first-child selector allows you to target the first element immediately inside another element. It is defined in the CSS Selectors Level 3 spec as a “structural pseudo-class”, meaning it is used to style content based on its relationship with parent and sibling content.
Or you can select by ID: #elementID. div[id="elementID"]
The CSS selector div:first-of-type only selects the very first element of its type and styles it. The div span:first-of-type selects the first span in each div since the div is the parent element.
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 */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With