Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Import of less files into a limited scope

Tags:

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/styles.less"; } 

But this doesn't work at all. I'm using the browser-based less.js option, and I can see the GET statement that is run when it actually does the import. But the resultant CSS does not contain any of the styles from the other sheet. If I do it like this, it works:

.wrapper-class  {     /* ... */ } @import "path/to/styles.less"; 

But this defeats the original purpose. So is there any way to do a limited-scope @import like this in Less? Thanks!

like image 885
ShravanP Avatar asked Mar 08 '12 19:03

ShravanP


People also ask

What is @import rule in less?

The @import rule is used to import one style sheet into another style sheet. This rule also support media queries so that the user can import the media-dependent style sheet. The @import rule must be declared at the top of the document after any @charset declaration.

How do I import less files?

The @import directive is used to import the files in the code. It spreads the LESS code over different files and allows to maintain the structure of code easily. You can put the @import statements anywhere in the code. For instance, you can import the file by using @import keyword as @import "file_name.


1 Answers

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"; } 
like image 50
Albin Avatar answered Sep 27 '22 15:09

Albin