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!!!
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.
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.
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 .
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.
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".
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With