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

issue selecting only the specific elements within a div in CSS

I’m using #acts h3, p to select only the H3’s and P’s inside of the div (id=acts). But it’s also selecting P and h3 tags outside of the ‘acts’ div?
Yet it works just fine when I select them one at a time, like this

#acts h3
 {
  color: red;
}

#acts p {
  color: red;
}

but not when I try to select them at once, what’s the issue?

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

>Solution :

In CSS, every comma works as beginning with a complete new selector, and not in the way you expect it to work.

This means that your selector #acts h3, p selects both #acts h3 & p, the latter targeting all p elements.

Instead your selector should look like this:

#acts h3, #acts p {
  color: red;
}
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