CSS3自定义字体写法

CSS3自定义字体写法 ps:最好英文 中文字体太大 影响加载速度 (中文字体网上的ttf大多数是gb2312 不过页面UTF-8格式可以用 不会乱码 <meta charset="UTF-8"> 会自动转化为utf-8)
<pre>
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<style>
@font-face
{
font-family: myFirstFont;
src: url('Sansation-Light.ttf')
}

.ew
{
font-family:myFirstFont;
}
</style>
</head>
<body>

<div class="ew">
With CSS3, websites can finally use fonts other than the pre-selected "web-safe" fonts
</div>


</body>
</html>
</pre>

myFirstFont这个是自定义字体标识 可以自定义 注意和上面font-face对应就行了
ps:一定要在window.onload 后面显示该文字 因为一定要确保字体下载好后显示

 

 

ps:字体只有display:block的时候才会加载 具体可以看谷歌浏览器inspect中的 font  

2如果inspect中 font没有加载字体说明加载失败  看看console.log是不是提示 can't decode 字体 如果是 只能换字体了 不是所有ttf字体都能用的

posted @ 2019-11-12 15:27  newmiracle宇宙  阅读(118)  评论(0编辑  收藏  举报