SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: targeting the first instance of a html tag type in a div

  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,484
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    targeting the first instance of a html tag type in a div

    I'm trying to use CSS to give the first table in the div (#content) a bottom-padding of 10px.
    This is what I have so far, but is it not working?

    #content table:first-child {
    padding-bottom:15px;
    }
    Im trying to apply it here...
    http://fixmysite.us/gmpc/?page_id=365#
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    19,937
    Mentioned
    216 Post(s)
    Tagged
    2 Thread(s)
    The table is not the first child of the #content div. (The H1 is.)

    You could try something like

    Code:
    #content > table {}

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,484
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    dang... its not working.
    Since it always the first table after the h1 tag in the #content div, shouldn't the adjacent selector work?
    h1 + table {
    padding-bottom:15px;
    border-color:#00FF00
    }
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    Community Advisor silver trophybronze trophy
    dresden_phoenix's Avatar
    Join Date
    Jun 2008
    Location
    Rockford, IL
    Posts
    2,361
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I hope you are aware of the browser compatibility limitations of :first-of pseudo classes. That being said, let's clear up some concepts.

    PAR >EL , will select ANY 'EL' that's a DIRECT CHILD of PAR ( in other words it will not target other lower descendants)
    PAR EL:first-child, will select said 'EL' only if it happens to be the FIRST DIRECT CHILD.

    Along the same line, '+' selects the only if the element is the very NEXT element. (<h1></h1><table>...) but not (<h1></h1><div></div><table>)
    "~" would target the ANY AND ALL tables after THE H1 ( you could always reset h1~table{}/h1 ~table~table{} but that's convoluted, I think)




    you may be looking for :PAR EL:first-of-type
    Again do note the limited support.


    Hope that helps

  5. #5
    It's all Geek to me silver trophybronze trophy
    SitePoint Award Recipient ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, Australia
    Posts
    19,937
    Mentioned
    216 Post(s)
    Tagged
    2 Thread(s)
    Anyhow, the padding is not showing visibly because of some weirdness with the tables, which you don't need to be using here anyhow.

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
  •