20

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.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Mohammad
  • 7,344
  • 15
  • 48
  • 76
  • "for inside a div"? "the first element of a specific class inside that div"? – BoltClock Jul 18 '11 at 21:21
  • 1
    Could this be what you're looking for? http://stackoverflow.com/questions/3615518/css-selector-to-select-first-element-of-a-given-class – BoltClock Jul 18 '11 at 21:25

1 Answers1

52

As your title implies "if first child is": div > .test:first-child will select the first child of any <div> if it has the class test.

But if the first child of the <div> doesn't have the class test, then it won't continue searching the <div> until it finds a child with the class test — it just won't match anything. I'm not sure if that's what you want.

Paul D. Waite
  • 96,640
  • 56
  • 199
  • 270
Paul
  • 139,544
  • 27
  • 275
  • 264
  • +1 For the right answer. And OP (now?) _is_ clear about being the element of a specific class. – NGLN Jul 18 '11 at 21:52