Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:10:04+00:00 2026-05-28T17:10:04+00:00

In short, I’d like to select a child element that has either Parent A

  • 0

In short, I’d like to select a child element that has either Parent A or Parent B.

I’m wondering if there’s a way to simplify my selectors in this scenario, or if what I have here is the only way to do it. Also, is there a best practice in this scenario? Below are some simplified examples:

/* long example (probably not best practice) */
    #parent-a .common-child {
        color: #000;
    }
    #parent-b .common-child {
        color: #000;
    }

/* shortest example I know of */
    #parent-a .common-child, #parent-b .common-child {
        color: #000;
    }

Is there any way to do something like:

#parent-a||#parent-b .common-child {
    color: #000;
}

It might not look like a big deal in these simple examples, but in my actual CSS I have several dozen selectors that chain down through the DOM a bit, and I want to optimize the file size / readability.

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:10:05+00:00Added an answer on May 28, 2026 at 5:10 pm
    /* shortest example I know of */
    #parent-a .common-child, #parent-b .common-child {
        color: #000;
    }
    

    This would be the most simplified solution. They have to be separated. All you can do is combine similar styles into one line like in the above.

    However, I would say that you’re almost leaving the realm of use for an ID selector. An ID is meant to be unique, and the styles that apply to it should be unique as well. If you ever add a parent-c or further, you should definitely consider adding a single class to those elements rather than selecting each one by its ID.

    color: #000 is a very broad style. If that were the only style being applied to both of these elements, it would make sense to set the style on a parent higher up so that it gets inherited by all its children, grandchildren, and so on.

    Without seeing more of your structure, we can’t really advise you on best practices. CSS and its optimization is very highly based on what else is around it and being specific.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short: Is there a way to have a route-definition that will pass the CONTROLLER/ACTION
Short of cutting and pasting, is there a way to sort the methods in
Short of copying the entire .netbeans directory is there any way to transfer custom
Short of rolling your own. There has to be something out there. FlexLM/FlexNet is
Short question: is there a way to make a jsonp request to a server,
Short question: is there a way to access the datatypes available in .net application
Short Question Is there a library that is supposed to replace mswinsoc.osx used to
Short Question : Since DNS is anycast, is there any way for a DNS
Short question: Is there a simple way in LINQ to objects to get a
Short description of my setup: There is an SQLObject base class which has an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.