Is it possible to add a parent selector in LESS?

后端 未结 2 553
广开言路
广开言路 2021-01-07 05:09

My css is structured in components, each component is stand-alone.

example:

.menu {
  background: black;
}

The framework I\'m using

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-07 05:42

    You can reference the parent selector using &: http://lesscss.org/features/#parent-selectors-feature

    LESS

    .menu {
       background: black;
      .loggedIn & {
        color: red
      }
    }
    

    Will compile to CSS

    .menu {
       background: black;
    }
    .loggedIn .menu {
        color: red
    }
    

提交回复
热议问题