0

So I have a bunch of nested classes. I'd like to target the IMMEDIATE parent from deep within the nest. So for example, I have:

.navbar {
   ul {
      li {
         a {
            .ACTIVE & {
              background: red;
            }
        }
      }
   }
}

The above results in:

.ACTIVE .navbar ul li a {
   background: red;
}

But what I am trying to achieve is:

.navbar ul li.ACTIVE a {
   background: red;
}

Is this possible?

user2726041
  • 359
  • 4
  • 20
  • I don't think you can do that - http://stackoverflow.com/questions/11519931/less-css-accessing-classes-further-up-the-dom-tree-from-within-a-nested-class?rq=1 – Paulie_D Jul 12 '16 at 11:00
  • ..or http://stackoverflow.com/questions/14472776/referencing-parent-with-multiple-levels-of-nesting-in-less?rq=1 – Paulie_D Jul 12 '16 at 11:01

1 Answers1

0

Do get to that path using LESS, you'd do something like

.navbar {
   & > ul {
      & > li {
         & > a {
            &.active {
              background: red;
            }
        }
      }
   }
}

This will result the following selector:

.navbar > ul > li > a.active { background: red; }

EDIT:

Sorry, totally missed the most important part.... So, to get what you're trying to achieve :

.navbar {
    ul {
       li {
         &.ACTIVE{
           a {
              background: red;
           }
         }
      }
   }
}
Alon Eitan
  • 11,997
  • 8
  • 49
  • 58