Font Include Sass Mixin

Source: Internet
Author: User

Front-end development whqet, csdn, Wang haiqing, whqet, front-end development expert

We have previously introduced a google font mixin (for details, see Google Fonts Sass Mixin). Today we will further recommend a web font mixin.

To use web font, you must use @ font-face to import the font file before using it. The format of @ font-face is as follows:

@font-face {      font-family: <YourWebFontName>;      src: <source> [<format>][,<source> [<format>]]*;      [font-weight: <weight>];      [font-style: <style>];}
Because browsers cannot support different font formats, we need a brain to import the font format for several minutes. It seems like the following.

@font-face {    font-family: 'nfoswjeos3500regular';    src: url('3500-webfont.eot');    src: url('3500-webfont.eot?#iefix') format('embedded-opentype'),           url('3500-webfont.woff') format('woff'),           url('3500-webfont.ttf') format('truetype'),           url('3500-webfont.svg#nfoswjeos3500regular') format('svg');    font-weight: normal;    font-style: normal;}
It's so annoying and troublesome. As a programmer who focuses on efficiency and likes to be lazy, we certainly have to have a trick. Let's take a look at this mixin.

@mixin importfont($font-family, $font-filename, $font-weight : normal, $font-style :normal, $font-stretch : normal) {  @font-face {    font-family: '#{$font-family}';    src: url('#{$font-filename}.eot');    src: url('#{$font-filename}.eot?#iefix') format('embedded-opentype'),    url('#{$font-filename}.woff') format('woff'),    url('#{$font-filename}.ttf') format('truetype'),    url('#{$font-filename}.svg##{$font-family}') format('svg');    font-weight: $font-weight;    font-style: $font-style;    font-stretch: $font-stretch;  }}
Then use

@include importfont('Font Name', 'fonts/fontfilename', 400);
Is there any instant ease? Okay. You have time to play a game.

----------------------------------------------------------

Front-end development whqet, pay attention to front-end development, share related resources, welcome to likes, welcome to shoot bricks.
Bytes ---------------------------------------------------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.