Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax to include separate Sass file?

Tags:

css

sass

I can't confirm that this syntax is best practice. I would like to reference an external Sass file and have it prepend it to my final CSS file, this way my Sass sheet looks more clean, and I'm only still only making one HTTP request.

For example, take the "normalize" code and put it into a .sass file, then in my sass sheets simply refer to it:

@import src/normalize @import src/droidSans  rest of code here..... 

It works fine so far, but I can't find anything concrete if I'm headed in the right direction. Also I am just making static templates for the time being... not using Rails at the moment.

I have been playing around with Sass for a few hours and I love it!!!

like image 499
SkinnyG33k Avatar asked Nov 09 '11 06:11

SkinnyG33k


People also ask

How do I use multiple sass files?

Create 1 scss file called combined. scss (for example) then inside of this file @import all your scss files, then simply run sass --style compressed --watch combined. scss:combined. css and it will detect changes to the imported scss files and recompile as needed.

How do I import a sass file into another sass file?

sass or . scss file. You can also import CSS files. The @import directive imports the file and any variables or mixins defined in the imported file can then be used in the main file.

What is the syntax of sass?

SASS supports two syntaxes namely SCSS and Indented syntax. The SCSS (Sassy CSS) is an extension of CSS syntax. This means every valid CSS is a valid SCSS as well. SCSS makes much easier to maintain large stylesheets and can recognize vendor specific syntax, Many CSS and SCSS files use the extension .

How do I include a CSS file in another Sass file?

You can create small files with CSS snippets to include in other Sass files. Examples of such files can be: reset file, variables, colors, fonts, font-sizes, etc. Just like CSS, Sass also supports the @import directive. The @import directive allows you to include the content of one file in another.

What are the syntaxes supported by Sass?

Sass supports two syntaxes: SCSS Syntax: The SCSS (Sassy CSS) can be specified as an extension of CSS syntax. It simply means that every valid CSS is a valid SCSS also. SCSS makes it easy to maintain large style sheets. It uses the extension ".scss".

What is the difference between SCSS and Sass?

The SCSS syntax uses the file extension .scss. With a few small exceptions, it’s a superset of CSS, which means essentially all valid CSS is valid SCSS as well. Because of its similarity to CSS, it’s the easiest syntax to get used to and the most popular. The indented syntax was Sass’s original syntax, and so it uses the file extension .sass.

What is Sass indented syntax?

SASS Indented syntax or SASS is an alternative to CSS based SCSS syntax. It has the following features: It uses indentation rather than {and} to delimit blocks. It uses newlines instead of semicolons (;) to separate statements.


1 Answers

In order to prevent your partial from being converted into its own css file, prefix the filename with an underscore, _normalize.scss. Then you can import it the way you've indicated you're doing already:

@import "normalize"; 

Or import many files at once:

@import "normalize", "droidSans"; 

Or import from a relative directory:

@import "folder/file" 

Note the use of double-quotes and semi-colon; I'm using the SCSS syntax which is a later development to the SASS word. While both styles are valid, you may find yourself preferring one over the other depending on what other languages you dabble in.

Further reading can be found under Directives/Partials in the documentation.

like image 88
Sampson Avatar answered Sep 27 '22 20:09

Sampson