19

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,816
  • 57
  • 73
  • 92
Mohammad
  • 7,150
  • 14
  • 46
  • 73
  • "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

47

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
  • 93,468
  • 54
  • 192
  • 264
Paul
  • 135,475
  • 25
  • 268
  • 257
  • +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