Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

less @import not working

Tags:

css

web

less

<head>     <link rel="stylesheet/less" href="less/news.less"> </head> <body>     <script src="less.js"></script> </body> 

news.less looks like this;

@import: "libs/base.less" 

base.less looks like this;

@import "colors.less"; @import "mixins.less"; @import "bootstap.less"; @import "font-aweseome.less"  body {     background-color: @light-grey; } 

bootstrap.less and font-awesome.less are CSS files with an altered extension. All the files are in the right folders.

When looking in the browser, styling in base.less is being ignored, meaning that my imports are not working.

Can anyone give any tips?

Thanks!

like image 453
Kevin Lewis Avatar asked Mar 17 '13 10:03

Kevin Lewis


People also ask

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.

Does @import work in CSS?

The @import rule tells the CSS engine to import an external style sheet into another style sheet. This allows style rules from a style sheet to be added to another style sheet. This rule can also be used in combination with media queries to import a style sheet based on the device type.

What is the use of @import at rule?

Definition and Usage The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of the document (but after any @charset declaration). The @import rule also supports media queries, so you can allow the import to be media-dependent.

How do I import CSS into less?

With (css) , the @import directive will remain as-is, and as a result the CSS file will be loaded by the browser at runtime ; with (inline) , the CSS file's contents are actually imported into the compiled stylesheet, which is what you want if that file is out of your web root for example.


2 Answers

Your @import statements must follow this format:

@import "styles.less"; 

@import "font-aweseome.less" isn't working because there is no semicolon at the end.

@import: "libs/base.less" won't work because there is a colon after the import statement.

like image 125
jonschlinkert Avatar answered Sep 23 '22 10:09

jonschlinkert


Why the colon in:

@import: "libs/base.less" 

I think is better to have a semicolon after all @import-s.

Take a look in the console to make sure the paths are correct, and the browser isn't trying to load a less file from the wrong url.

like image 22
Tamás Pap Avatar answered Sep 25 '22 10:09

Tamás Pap