0

I want to add specific style property on all child elements of this .feature-section-heading class. I know i can do that using below trick

.feature-section-heading > h1 {...}

But above logic will implement on just h1 tag. So is there possible that i can add style property on all child elements? I searched about that and find accepted answer, but it does not work.

2
  • .feature-section-heading > * {...} would apply the style to all immediate children (but there may be a better way to achieve what you are trying to do). The universal selector, * is not considered efficient css. What is it that you are trying to apply?
    – ne1410s
    Commented Feb 1, 2016 at 12:49
  • this was asked previously stackoverflow.com/questions/26349987/…
    – n4gys4nyi
    Commented Feb 1, 2016 at 15:22

5 Answers 5

2

Use a universal selector instead of a type selector.

.feature-section-heading > *
2

CSS

.feature-section-heading > * {...}

You can use the * as all element selector.

1

You Can use * (Asterik Selector)

Here is the Demo

CSS

.foo *{background:red}

HTML

<div class="foo">

<span>1</span>
<p>2</p>
<div>3</div>

</div>
0

Access All childrens with Css * selector as in code snippet below:

.feature-section-heading > * {
    background: red;
}
1
  • That matches all descendants, not just children.
    – Quentin
    Commented Feb 1, 2016 at 12:49
0

Please find the jsfiddle link that illustrates the desired behavior.

HTML

<div class="feature-section-heading">
    I am parent div
    <br />
    <h1>
        Heading
    </h1>
    <div>
        Child DIV
    </div>
    <div>
        Child DIV
    </div>
    <p>
        Child paragraph
    </p>
    <p>
        Child paragraph
    </p>
    <p>
        Child paragraph
    </p>
    <span>
        Child span
    </span>
</div>

CSS

.feature-section-heading {
  color: red;
}
.feature-section-heading > :not(:empty){
    color: darkgreen;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.