50

I'm trying to apply CSS to any immediate child of a parent container element. How do I use CSS's descendant < selector to select any immediate child regardless of type (div / span / etc).

user2019515
  • 4,495
  • 1
  • 29
  • 42
mheavers
  • 29,530
  • 58
  • 194
  • 315

2 Answers2

107

I assume you mean the child selector. It's >, not <.

.parent > *

That will select any element. You can of course use any other selector as the child (an element, class, id, etc.)

Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
  • 4
    And the descendant selector is the space, not "<". And an obligatory inane comment about how `*` is bad for performance, etc, as if performance matters to anyone. – BoltClock Mar 08 '13 at 20:44
  • @BoltClock not just bad for performance, but probably suggestive of something bad in the design – Explosion Pills Mar 08 '13 at 20:59
17

If you are in SCSS then

.parent {
  & > * {
    
  }
}
Emmanuel
  • 4,933
  • 5
  • 46
  • 71
Ifart Mitul
  • 188
  • 1
  • 8