Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
Is there a css selector to take into account parent class?

I am creating a react e-commerce app where I need to use the same component for a cart, that takes the whole screen, and for a dropdown menu with the cart, that is much smaller.

What I want to do is to pass a class as prop when I'm rendering the dropdown cart, and use it in the container to then conditionally style every other element.

Code would be something like this:

  • Passing prop like this

          <CartContent className={"cart-overlay"} />
    
  • grabbing class in container like this:

              <div className={`cart-element ${className === "cart-overlay" && "cart-overlay"}`}>
    

And then what I want to do, and this is what I don't know how to do, in scss is something like this:

    .cart-overlay{
      &.child-of-cart-overlay{
        styles: cool;
        }
    }

How could I style that child of cart overlay, without having to grab the className in each one of the elements I want to syle and directly selecting with both classes?

media query won't work because it consider screen width and not element width, and there is something like container media query but they don't have almost any browser support today

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The CSS solution is to just redefine the styles for the elements when in the context of the overlay:

.cart-element{
   font-size:1rem;
}
.cart-button{
  padding:0.5rem 1rem;
}

.cart-overlay{
  .cart-element{
    font-size:0.8rem;
  }
  .cart-button{
    padding:0.25rem 1rem;
  }
}

This way, you don't need to apply any extra classes to the elements themselves.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!