Nth-child


#1


https://www.codecademy.com/en/courses/web-beginner-en-WF0CF/3/5?curriculum_id=50579fb998b470000202dc8b#

I have used 2 brakelines betwen the Links(a) and While I was typing the a:nth-child(2) in the stylesheet.css tab, I've noticed that it counts <br/> as a <a> too. I mean if I wanted to select the second <a> I had to type 3 in the selector.
can someone plz tell me why?


#2

I'm sorry I don't understand what you mean. Its counting <br /> as a child ?


#3

look. first they asked me to write three links. so i did that. i used a linebrake instead of a list to make each link be in a seperated line. then i went to the stylesheet tab to apply the color with the code a:nth-child(3){color:#FFC125} . and then i saw that instead of the third link, the second link changed its color. after deleting the br , everything got back to normal and the third link changed it's color. i wanted to ask why this is happening and the linebraker is a problem here?


#4

Let me explain this to you

a:nth-child(3) :arrow_right: This bit of code checks if the 3rd child is an a element and then applies the style

Now when you added <br>

Your code looked like this (I'm guessing):

<a href="#">ddb</a>   <!-- first child -->
<br>                  <!-- second child -->
<a href="#">fdfd</a>  <!-- third child -->
<br>                 <!-- forth child -->
<a href="#">fve</a>  <!-- fifth child -->

You understand what happened ?


#5

tnx Mam. I didn't knew that it worked this way : "This bit of code checks if the 3rd child is an a element and then applies the style"


#6

Read this article for further explanation on how it works


#7

I just wanted to know whats the need to use the nth child or first child??
we can simply select that particular paragraph and style it right?


#8

Its good to know the different ways of styling,

many don't like inline styling so they will use this method or class's/id's


#9

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.