@font-face The practice of making small icons

Source: Internet
Author: User

1, why to use Font-face to make small icons

1) Applicability: An icon font to be smaller than a series of images, once the font icon loaded, the icon will be displayed immediately, do not need to download an image.

2) Extensibility: You can use Font-size to set the size of the icons, which makes it possible to output icons of different sizes at any time, but if it is a picture, you need to output different files for different sizes of pictures.

3) Flexibility: You can add any text effect to the icon, and can be displayed in any context.

4) Compatibility: Web fonts support all modern browsers, including the low version of IE.

2. Implementation steps

First, convert SVG into a Web font. Using the website: Icomoon

Click the ' Import Icons ' button to import an icon that needs to be converted to a Web font. When selected, click the ' Generate Font ' button to download the Web fonts.

There is a demo.html in the download file, open the file, you can see the different icons corresponding to the wildcard characters:

Second, the font is called.

Statement @font-face:

@font-face{
Font-family:' Icomoon ';
SRC:url (' Fonts/icomoon.eot ');  /*IE Dedicated*/
SRC:url (' fonts/icomoon.eot #iefix ') format (' Embedded-opentype '),/*IE*/
URL (' fonts/icomoon.woff ') format (' Woff '),/*Chrome,firefox,ie9+,safari,opera*/
URL (' Fonts/icomoon.ttf ') format (' TrueType '),/*ios4.2+*/
URL (' fonts/icommon.svg ') format (' SVG ');                       /*IOS*/
Font-weight:Normal;
Font-style:Normal;

        }

Use fonts:

[Class ^= "icon-"],[class*= ' icon-']{
Font-family:' Icomoon ';
}
. Icon-1:before{
Content:"\e600";

        }


Test code:

<!DOCTYPE HTML>
<HTML>
<Head>
<MetaCharSet= "Utf-8">
<title>Font-face test Page</title>
<style>
@font-face{
Font-family:' Icomoon ';
SRC:url (' Fonts/icomoon.eot ');  /*IE Dedicated*/
SRC:url (' fonts/icomoon.eot #iefix ') format (' Embedded-opentype '),/*IE*/
URL (' fonts/icomoon.woff ') format (' Woff '),/*Chrome,firefox,ie9+,safari,opera*/
URL (' Fonts/icomoon.ttf ') format (' TrueType '),/*ios4.2+*/
URL (' fonts/icommon.svg ') format (' SVG ');                       /*IOS*/
Font-weight:Normal;
Font-style:Normal;
}

[Class ^= "icon-"],[class*= ' icon-']{font-family:' Icomoon ';}
. Icon-1:before{content:"\e600";}
. Icon-2:before{content:"\e601";}
. Icon-3:before{content:"\e602";}
. Wrap ul{List-style:None;}
. Wrap ul Li{Line-height:28px;font-size:28px;}
</style>
</Head>
<Body>
< Sectionclass= "Wrap">
<ul>
<Liclass= "Icon-1">First Li</Li>
<Liclass= "Icon-2">A second Li</Li>
<Liclass= "Icon-3">A third Li</Li>
</ul>

</ Section>
</Body>

</ HTML >

@font-face The practice of making small icons

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.