Nathaniel Lew Aquino
Nathaniel Lew Aquino

Reputation: 13

Child of any element under class

I want to set all paragraphs to color green regardless of what element the parent is and also regardless of the number of parents and sub-parents, as long as they are inside the class "main_class".

<style>
     .main_class > (?) > p { color: green; }
</style>

<div class="main_class">
    <p> Test </p>
    <div>
        <p> Test </p>
    </div>
    <td> Test </p>
    <div>
        <div>
            <td>
                <p> Test </p>
            </td>
        </div<
    </div>
</div>

Upvotes: 1

Views: 65

Answers (2)

Sarabjit Singh
Sarabjit Singh

Reputation: 611

It is simply to add css as following:-

.main_class p {color: green;}

Upvotes: 2

Mr. Alien
Mr. Alien

Reputation: 157334

The selector you are using will only select the p which are directly nested under .main_class

so use the following selector. This will select any p element at any nested level as long as it's nested under .main_class

.main_class p { 
  color: green; 
}

Would also like to add here that your Markup is invalid. You are mixing up the td, div & p. For more info, refer to W3C HTML Validator to validate your markup.

Upvotes: 2

Related Questions