SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Feb 2003
    Location
    eez
    Posts
    331
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Tricky CSS descending selector question

    Hi!

    Let's say we have this situation:

    HTML Code:
     <div>
    <div class="second"> 
    </div>
    </div>

    Is there a way to grab in CSS the first div with the help of the class second?

    I mean, something like this:

    div .second (now I get the second div but I want the first).

    I don't think it is possible... that's a real pity. Im I wrong?


    Thanks!

  2. #2
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not with CSS2. CSS3 will probably provide a parent pseudo-class, which will allow you do use
    Code:
    .second::parent {...}
    But that's in the future.
    Birnam wood is come to Dunsinane

  3. #3
    SitePoint Wizard silver trophybronze trophy Stormrider's Avatar
    Join Date
    Sep 2006
    Location
    Nottingham, UK
    Posts
    3,133
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Will you be able to chain those together:

    Code:
    ::parent::parent
    etc?

    I always thought CSS should have something like that, but using ^ or something to denote 'up'

    div.second ^ {

    }

    That would be quite cool.

  4. #4
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,158
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stormrider
    Will you be able to chain those together:
    I haven't studied the proposed recommendation in detail, so I don't know. Besides, anything can happen until it becomes a final recommendation.
    Birnam wood is come to Dunsinane

  5. #5
    SitePoint Wizard bronze trophy DaveWoods's Avatar
    Join Date
    Dec 2004
    Location
    Derbyshire - UK
    Posts
    2,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    agw, depending on the rest of your code it may be possible to use a class previous to this to select that specific div, although if you need to apply a specific class to that div alone then can't you just give it a class or id?

  6. #6

  7. #7
    In memoriam gold trophysilver trophybronze trophy Dan Schulz's Avatar
    Join Date
    May 2006
    Location
    Aurora, Illinois
    Posts
    15,476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I always assign classes or IDs to the parent selectors when I'm faced with a situation like this, and then work my way down, depending on my needs at the time.

  8. #8
    bronze trophy
    Join Date
    Dec 2004
    Location
    Sweden
    Posts
    2,670
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So far parent selector proposals have been rejected by the CSS WG, mostly due to performance concerns and incremental rendering problems.
    Simon Pieters


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
  •