Kaiyaha
Kaiyaha

Reputation: 480

How to define a class for child tags?

Assume there is a bunch of tags:

<parenttag>
    <!-- a bunch of tags -->
</parenttag>

I want the child tags to belong to the same class. How can I refer them to this class without specifying the class for the each of them, like just specify it once in the parent tag? Is it possible?

Upvotes: 0

Views: 220

Answers (2)

MaxiGui
MaxiGui

Reputation: 6348

You should use general selector * so parenttag * this will select all tags into parent tag, direct child and there children, etc. If you just want to target direct child of paretn you can use child selector > to make it like: parenttag > *

Upvotes: 1

Moonlight.Y
Moonlight.Y

Reputation: 24

you can use parenttag > *,

sample:

<style type="text/css">
 .parent > * { color: red; }
</style>
<div class="parent">
  I am parent
  <p>I am child 1</p>
  <div>I am child 2 
    <span>I am child 2-1<span>
  </div>
</div>

Upvotes: 0

Related Questions