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