Is it possible to add a parent selector in LESS?

后端 未结 2 530
广开言路
广开言路 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
    }
    
    0 讨论(0)
  • 2021-01-07 05:48

    Unless I am completely missunderstanding you, and there is a possibility, then the ampersand-parent-selector is exactly what you need!

    .menu{
      .loggedIn & {
        color: red
      }
    }
    

    Should result in

    .loggedIn .menu {
      color: red
    }
    
    0 讨论(0)
提交回复
热议问题