wrap a .less css definitions in a namespace

前端 未结 5 584
情话喂你
情话喂你 2020-12-24 07:31

I wanted to use twitter bootstrap CSS only in a specific element in my web page.

I tried to do it like in code below. But after compiling this to a css file nothing

5条回答
  •  甜味超标
    2020-12-24 08:07

    LESS documentation has a section about namespaces.

    So you could define your lib in a separate document:

    #ns {
      .twitter () {
        // Instructions to be used later
        // Nothing will appear in compiled CSS except if called later (because of parenthesis)
      }
    }
    

    import this file at the beginning of the CSS file to be compiled and use these instructions:

    #my_div {
      #ns > .twitter;
    }
    

提交回复
热议问题