Home > Software design >  issue selecting only the specific elements within a div in CSS
issue selecting only the specific elements within a div in CSS

Time:12-06

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?

CodePudding user response:

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;
}
  • Related