Randy
Randy

Reputation: 9849

Scss - element depth recursive styles

Is there a way to make Scss check the element depth, and apply recursively added margin to that element?

So say I've got this:

<span>
  <span>
    <span>

Then I would like to have this, but without me typing the resursion:

span {
  margin:10px;

  span {
    margin:20px;

     span {
       margin:30px;

I don't know the element depth and need this a lot, that's why I don't want to type this by hand. I don't know if I need a depth of 3, or a depth of up to 100.

Upvotes: 0

Views: 384

Answers (1)

martin
martin

Reputation: 96969

Just use the direct ancestor operator >:

span > span {
    margin: 10px;
}

Upvotes: 1

Related Questions