I need a CSS selector for inside a div but I want it to only select the element if its the first element of a specific class inside that div.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As your title implies “if first child is”:
div > .test:first-childwill select the first child of any<div>if it has the classtest.But if the first child of the
<div>doesn’t have the classtest, then it won’t continue searching the<div>until it finds a child with the classtest— it just won’t match anything. I’m not sure if that’s what you want.