sample 1 sample 2

How to target the first link inside a div using CSS?

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 using CSS.

+4
source share
3 answers

You can use the first-child selector:

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

Try this code:

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

where n is the number of the desired line. in your case

 div a:nth-of-type(1) { /* css */ } 
+2
source

Source: https://habr.com/ru/post/1444752/


All Articles