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

select mulitple class in one parent the short way

I have this sample situation

<div class="main-class"></div>

in the css

.main-class {
    maring-top:1px
}

so sometimes in my div I add at run time some other class so it could be

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

<div class="main-class a"></div>

or

<div class="main-class b"></div>

or

<div class="main-class c"></div>

so in my css

.main-class.c{
    margin-top: 5px;
}
.main-class.a{
    margin-top: 5px;
}
.main-class.b{
  margin-top: 5px;
}

or simply

.main-class.c,
.main-class.a,
.main-class.b{
      margin-top: 5px;
    }

this is too long, is there any other ways to do this
if .main-class has any other (a , b , c) so the margin will be 5px?

I tried this

.main-class:has(.a, .b, .c)
{
margin-top :5xp;
}

and this does not work

>Solution :

Some notes to start with:

  • There is no CSS property called maring-top.
.main-class.c {
  margin-top: 5px;
}
.main-class.a {
  margin-top: 5px;
}
.main-class.b {
  margin-top: 5px;
}

can be simplified to

.main-class.c,
.main-class.a,
.main-class.b {
  margin-top: 5px;
}

and even further to

.main-class:is(.c, .a, .b) {
  margin-top: 5px;
}
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