@Import of less files into a limited scope

前端 未结 3 1849
遇见更好的自我
遇见更好的自我 2021-02-02 10:53

I want to import all styles from another less file, but into a limited scope. I\'m trying this:

\"my-site.less\"

.wrapper-class {
    @import \"path/to/s         


        
相关标签:
3条回答
  • 2021-02-02 11:19

    Since this question was posted and answered, pre-processors have implemented @import with scope. This now works in LESS, SASS and Stylus.

    example:

    .lt-ie9 {
      @import "ie8-fixes";
    }
    
    0 讨论(0)
  • 2021-02-02 11:27

    According to the css-spec, the @import-declaration has to come before all other declarations in the css-file. So your @import inside the rule is expected to fail. I guess the @importing at the end of the file not failing is goodwill of the browser-vendors.

    I guess LESS will abide by the same rules.

    EDIT: the question is, why do you want to have those styles scoped? With proper declarations, this should not be necessary.

    0 讨论(0)
  • 2021-02-02 11:34

    The syntax of LESS (and CSS) don't allow @imports into CSS rules. Try use namespace:

    styles.less

    .styles {
        [your code]
    }
    

    Then, replace the @import for namespace:

    .wrapper-class {
        .styles;
    }
    

    Reference:

    http://lesscss.org/features/

    0 讨论(0)
提交回复
热议问题