0

Is it possible in Less CSS to get the parent of the parent?

I'm wondering if it's possible to do something like this:

#parent1 {
  #parent2 {
    #grandparent & & {
      /* stuff */
    }
  }
}

to equate to:

#grandparent #parent1 #parent2 { /* stuff */ }

Thoughts?

Mr Mikkél
  • 2,577
  • 4
  • 34
  • 52

1 Answers1

2

I pasted your code here: http://less2css.org/

Instead of:

#parent1 {
  #parent2 {
    #grandparent & & {
      /* stuff */
    }
  }
}

I tried

#parent1 {
  #parent2 {
    #grandparent & {
      /* stuff */
    }
  }
}

And that equates to: #grandparent #parent1 #parent2 { /* stuff */ }

Is this what you're asking for?

Timber
  • 859
  • 9
  • 25
  • Oh, so it's going all the way up the tree? I would have thought that would equate to: #parent1 #grandparent #parent 2 { ... } – Mr Mikkél Jul 09 '13 at 15:25
  • 1
    If you do this `grandparent {` then it will go up by one, but if you `#grandparent &` that goes all the way up. I think... lol. – Timber Jul 09 '13 at 15:29
  • 2
    The "position" of the `&` has no bearing on how many levels up it goes. It always goes all levels. I give a brief explanation of it at the beginning of [this answer](http://stackoverflow.com/questions/14472776/referencing-parent-with-multiple-levels-of-nesting-in-less/14476912#14476912), and the discussion with [this answer](http://stackoverflow.com/questions/11537260/less-css-abusing-the-operator-when-nesting/11544805#11544805) might be useful also. – ScottS Jul 09 '13 at 16:29
  • @ScottS Thank you for clarifying that, I've read the beginning part of the answer you've linked. I'm going to read rest once I wrote this comment. I'm sorry MrA for giving you the wrong information, my comment above is completely false. Thanks again ScottS. – Timber Jul 09 '13 at 16:42