Anell Zheng
Anell Zheng

Reputation: 25

Making every children element to apply parent div class

I have created a simple css class:

.div-toolbar-content {
    margin-top: 0px;
    margin-bottom: 0px;
}

In the HTML code i want to apply this class to every element that is inside of the parent div:

<div>
    <svg></svg>
    <p></p>
    <select></select>
    <i></i>
    ....
</div>

I have tried putting the class in every element inside the div and it has worked, but is there a way to put the class like in parent div and automatically each element inside the div can apply the class?

Thanks for advices.

Upvotes: 0

Views: 733

Answers (2)

If you only want to set the styles for the immediate level children's

.div-toolbar-content > *{
    margin-top: 0px;
    margin-bottom: 0px;
},

otherwise:

.div-toolbar-content * {
    margin-top: 0px;
    margin-bottom: 0px;
}

Upvotes: 1

Amir Saadallah
Amir Saadallah

Reputation: 686

u can use css for that

div.main > * {
    margin-top: 0px;
    margin-bottom: 0px;
}

and your HTML

<div class='main'>
    <svg></svg>
    <p></p>
    <select></select>
    <i></i>
    ....
</div>

Upvotes: 3

Related Questions