Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Styling child element with multiple styles on child and parent

I’m looking to style an element inside a div with multiple classes and this element also has multiple classes:

<div class="breadcrumbsHolder dark-mode" id="breadcrumbHolderID">
  <ol class="breadcrumb">
    <li class="breadcrumb-item">Other</li>
    <li class="breadcrumb-item active" id="activeBreadcrumb">Active</li>
  </ol>
</div>

This doesn’t seem to work on the "Active" text:

.breadcrumbsHolder.dark-mode {
  color: orange;
}
.breadcrumbsHolder.dark-mode > .breadcrumb-item.active {
  color: white;
}

Neither does this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

.breadcrumbsHolder.dark-mode {
  color: orange;
}
.breadcrumbsHolder.dark-mode > #activeBreadcrumb {
  color: white;
}

Nor:

.breadcrumbsHolder.dark-mode {
  color: orange;
}
#breadcrumbHolderID > #activeBreadcrumb {
  color: white;
}

What am I doing wrong?

One thing to note is that the .breadcrumbsHolder.dark-mode works and applies to the outer parent div

>Solution :

You cannot use the angle bracket > because this picks only the direct child of the element, which isn’t the case here – the ol element would be the direct child.

Here are some compact selectors you could use:

#activeBreadcrumb
li.active
.breadcrumb-item.active

If you want to select the active item based on the outer element:

.breadcrumbsHolder.dark-mode .breadcrumb-item.active

Other ways, for the records:

.breadcrumbsHolder .active
.breadcrumbsHolder li.active
.breadcrumb .active
ol li.active
.breadcrumbsHolder > .breadcrumb > .active

Also see: How is the "greater than" or ">" character used in CSS?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading