Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to import fonts from the directory with scss?

Tags:

sass

I have a scss file with font import implemented this way:

@import url(https://fonts.googleapis.com/css?family=PT+Sans+Caption:400,700&subset=latin-ext,cyrillic);  

I understand that using CDN gives advantages in caching for user but this is internal site and it could be used on server without access to the wide web. And I'm not sure that user machine will have access to the Internet too. So I want to serve fronts with other pages static files.

Is there a way in SCSS to import fonts from the some directory on server? Something like:

@import dir(/path/to/fonts/file) 

Or SCSS has not this feature?

like image 250
Paul Avatar asked May 22 '16 09:05

Paul


People also ask

How add Google fonts to SCSS?

@import "https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600;700&display=swap"; give the same, exact result compiled from Sass to CSS. Then, if you add one of these in a . scss file, you don't have to worry at all.

Can you import CSS into SCSS?

scss files, Sass can import plain old . css files. The only rule is that the import must not explicitly include the . css extension, because that's used to indicate a plain CSS @import .

Is Sass and SCSS the same?

SASS (Syntactically Awesome Style Sheets) is a pre-processor scripting language that will be compiled or interpreted into CSS. SassScript is itself a scripting language whereas SCSS is the main syntax for the SASS which builds on top of the existing CSS syntax.


2 Answers

As far as I know you can't import fonts using @import in SCSS. You can include fonts using @font-face. For example:

@font-face {     font-family: 'Open Sans';     src: url(path/to/file) format(Example: 'truetype' or 'opentype' depending on the file extension of your font); }   // USAGE body {     font-family: 'Open Sans', sans-serif; } 
like image 151
JTrixx16 Avatar answered Sep 25 '22 12:09

JTrixx16


Usually it's used to import CSS fragments or files and not fonts. Try this workaround if you are using Ruby SASS/SCSS and try without brackets.

@import "https://fonts.googleapis.com/css?family=PT+Sans+Caption:400,700&subset=latin-ext,cyrillic.css";  

I put a .css behind it. Works for me with Ruby SASS/SCSS but not with LibSass though.

like image 29
Thielicious Avatar answered Sep 25 '22 12:09

Thielicious