Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of LESS's "import (reference) 'style'" in SASS

Tags:

sass

less

In addition to application.css.scss, I have multiple partials like homepage.css.scss. At the moment I have to add @import 'bootstrap' to each one of them in order to use bootstrap variables and mixins.

Let's say I want to change my default links colour to red, I'd add that to application.css.scss. But the links in homepage.css.scss will not be red because the bootstrap import will override it with blue.

In LESS, I can do @import (reference) "bootstrap", how can I do that in SASS?

like image 927
chh Avatar asked Apr 04 '14 00:04

chh


People also ask

What is import directive in Sass?

Sass Importing Files The @import directive allows you to include the content of one file in another. The CSS @import directive has a major drawback due to performance issues; it creates an extra HTTP request each time you call it.

Is Sass import deprecated?

As of October 2021 @import will be deprecated, along with global built-in functions, and one year after that (no later than October 2022) @import support will be dropped. Make sure you go check out the newly refreshed Sass documentation for the latest updates.

Is Sass and SCSS same?

SassScript is itself a scripting language whereas SCSS is the main syntax for the SASS which builds on top of the existing CSS syntax. It makes use of semicolons and brackets like CSS (Cascaded Style Sheets). SASS and SCSS can import each other. Sass actually makes CSS more powerful with math and variable support.

What is difference between @USE and @import?

The new @use is similar to @import . but has some notable differences: The file is only imported once, no matter how many times you @use it in a project. Variables, mixins, and functions (what Sass calls "members") that start with an underscore (_) or hyphen (-) are considered private, and not imported.


1 Answers

The closest you will get is a silent class / placeholder. These work a little different to how LESS and reference work, you can read more on them here: http://blog.teamtreehouse.com/extending-placeholder-selectors-with-sass

LESS

lib.less

.class {    background: red; } 

main.less

@import (reference) "lib";  .anotherClass {    &:extend(.class); } 

SASS

lib.sass

%class {   background: red; } 

main.sass

@import "lib";  .anotherClass {   @extend %class; } 

CSS Output

.anotherClass {   background: red; } 
like image 162
mikedidthis Avatar answered Oct 11 '22 21:10

mikedidthis