SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Targeting several divs at once

    Hi,
    Can someone help with this, I've been puzzling over it.
    If I have several divs e.g. button1, button2, button3
    and I want to target a p in all of them at once instead of writing a separate rule for each, how do I do that?
    I tried #button1 #button2 #button3 p but it didnt work, (and I think that would be button3 in a button2 in a button 1 - is that correct?)
    Grateful for any help, I'm just getting the hang of CSS so there will probably be alot more questions.
    Thanks
    from
    Richard

  2. #2
    Mouse catcher silver trophy
    Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,830
    Mentioned
    111 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by RichardSc View Post
    Hi,
    Can someone help with this, I've been puzzling over it.
    If I have several divs e.g. button1, button2, button3
    and I want to target a p in all of them at once instead of writing a separate rule for each, how do I do that?
    I tried #button1 #button2 #button3 p but it didnt work, (and I think that would be button3 in a button2 in a button 1 - is that correct?)
    Grateful for any help, I'm just getting the hang of CSS so there will probably be alot more questions.
    Thanks
    from
    Richard
    Unfortunately there is no way to say "a <p> in each of these IDs" without spelling the selectors out in full, but you can list multiple selector matches for one rule, separate them by commas. Something like:
    Code:
    #button1 p, #button2 p, #button3 p {rules go here}
    Or another option would be to give each <div> a class as well as an ID, and then you could just have
    Code:
    .button p {rules go here}

  3. #3
    SitePoint Member
    Join Date
    May 2013
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that Stevie, I'll use that.
    Makes sense!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •