在CSS3中有个模块@font-face,其语法格式为
@font-face {
font-family
: <YourWebFontName>;
src
: <source> [<
format
>][,<source> [<
format
>]]*;
[
font-weight
: <weight>];
[
font-style
: <style>];
}
在css中应用这个样式后,可以使用浏览器机器上面没有的字体,页面会到
src
指定的地方去下相应的字体。但是在IIS中有些字体是不能被下载的,这时候可以给IIS加MIME Types,让字体可以被下载。
比如添加otf格式的文件如下图:
添加了MIME Types后重启一哈IIS,这时就可以下载到相应的字体了。
可以用ttf格式的字体,在http://fontface.codeandmore.com/这个地址或http://www.fontsquirrel.com/fontface/generator去生成其他需要的字体,
把生成的字体下下来,里面有demo,照demo使用就可以了
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CodeAndMore @font-face Demo</title>
<style type="text/css">
@font-face {
font-family: 'MyriadPro-Regular';
src: url('Fonts/myriadproregular.eot');
src: url('Fonts/myriadproregular.eot?#iefix') format('embedded-opentype'),
url('Fonts/myriadproregular.woff') format('woff'),
url('Fonts/myriadproregular.ttf') format('truetype'),
url('Fonts/myriadproregular.svg#myriadproregular') format('svg');
font-weight: normal;
font-style: normal;
}
</style>
</head>
<body style="font-family:'MyriadPro-Regular'; padding: 80px; text-align: center;">
<h1>test heading h1</h1>
<h2>test heading h2</h2>
<h3>test heading h3</h3>
<p>test normal paragraph</p>HOME asfdasdfasdfadsf
<p>Created by <a href="http://fontface.codeandmore.com">@font-face generator</a> on <a href="http://codeandmore.com">CodeAndMore</a> based on open source tools.</p>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CodeAndMore @font-face Demo</title>
<style type="text/css">
@font-face {
font-family: 'MyriadPro-Regular';
src: url('Fonts/myriadproregular.eot');
src: url('Fonts/myriadproregular.eot?#iefix') format('embedded-opentype'),
url('Fonts/myriadproregular.woff') format('woff'),
url('Fonts/myriadproregular.ttf') format('truetype'),
url('Fonts/myriadproregular.svg#myriadproregular') format('svg');
font-weight: normal;
font-style: normal;
}
</style>
</head>
<body style="font-family:'MyriadPro-Regular'; padding: 80px; text-align: center;">
<h1>test heading h1</h1>
<h2>test heading h2</h2>
<h3>test heading h3</h3>
<p>test normal paragraph</p>HOME asfdasdfasdfadsf
<p>Created by <a href="http://fontface.codeandmore.com">@font-face generator</a> on <a href="http://codeandmore.com">CodeAndMore</a> based on open source tools.</p>
</body>
</html>
使用的时候,要注意所用的字体是可以使用的,我就遇到了不能使用的字体,弄了好久,苦逼了,最后到网上去下了个字体,才整出来