1. 为什么要用在线字体
问题
1.
精灵图(雪碧图)用作背景的时候不能轻易的放大缩小,会失真。
2.
低质量的位图在高清设备上放大后会有难看的锯齿,无法满足响应式页面的开发需求
在线字体带来的革命:
1.
在线字体本质就是文字,但是也可是像图形的文字。节省了带宽(相比图片)字体文件大小也不大(一般几百k)。
2.
在线字体本身是矢量的,放大缩小都不会失真
3.
可以灵活的通过css来控制字体图标的大小、颜色、阴影等
4.
可以方便的自定义字体图标
2. 在线字体
@font-face是CSS3中的一个模块,他主要是把自己定义的Web字体嵌入到你的网页中,允许我们不依赖操作系统的字体,做到全平台字体统一和定制
语法规则:
@font-face {
font-family: <YourWebFontName>;
src: <source> [<format>][,<source> [<format>]]*;
[font-weight: <weight>];
[font-style: <style>];
}
取值说明:
1.
YourWebFontName:此值指的就是你自定义的字体名称,他将被引用到你的Web元素中的font-family。如“font-family:“YourWebFontName”;”
2.
source:此值指的是你自定义的字体的存放路径,可以是相对路径也可以是绝路径;
3.
format:此值指的是你自定义的字体的格式,主要用来帮助浏览器识别,其值主要有以下几种类型:truetype,opentype,truetype-aat,embedded-opentype,avg等;
4.
weight和style:这两个值大家一定很熟悉,weight定义字体是否为粗体,style主要定义字体样式。
3. 字体兼容写法
@font-face {
font-family: 'YourWebFontName';
src: url('YourWebFontName.eot'); /* IE9 Compat Modes */
src: url('YourWebFontName.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('YourWebFontName.woff') format('woff'), /* Modern Browsers */
url('YourWebFontName.ttf') format('truetype'), /* Safari, Android, iOS */
url('YourWebFontName.svg#YourWebFontName') format('svg'); /* Legacy iOS */
}
h1 { font-family: 'YourWebFontName' }
4. bootstrap在线字体应用
第一种:直接应用bootstrap提供的样式类型
<!-- 引用bootstrap样式文件 -->
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div>
<!-- 在需要字体图标的地方添加i标签,并添加图标样式类 -->
<i class="glyphicon glyphicon-eur"></i>//斜体
<span class="glyphicon glyphicon-eur"></span>
</div>
第二种:直接下载bootstrap压缩包。
下载地址
解压后,把字体包fonts文件加载拷贝到项目的根目录下。
第二种之方式一:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>bootstrap字體</title>
<link rel="stylesheet" href="./lib/bootstrap-3.3.7-dist/css/bootstrap.min.css">
<style>
@font-face {
font-family: 'glyphicon';
src: url('./lib/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.eot');
/* IE9 Compat Modes */
src: url('./lib/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
url('./lib/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.woff') format('woff'), /* Modern Browsers */
url('./lib/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.ttf') format('truetype'), /* Safari, Android, iOS */
url('./lib/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.svg#./lib/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular') format('svg');
/* Legacy iOS */
}
.box {
font-size: 40px;
color: #090;
text-shadow: 3px 3px 5px #0f0;
font-family: 'glyphicon', sans-serif;
}
</style>
<link rel="stylesheet" href="./lib/bootstrap-3.3.7-dist/fonts/glyphicons-halflings-regular.eot">
</head>
<body>
<div class="box">
是是是; 四帶石鱸家
<!-- 第一種:使用boostrap的樣式類 ,是字体,所以设置font-size的时候照样会变大-->
<i class="glyphicon glyphicon-envelope"></i>
<i class="glyphicon glyphicon-heart"></i>
<!-- 第二種:之家寫unicode字符 -->
<sapn></sapn>
<sapn></sapn>
</div>
</body>
</html>
的找法
5. fontawesome在线字体应用
点击下载最新版
引用----------------使用如下
<link rel="stylesheet" href="./font-awesome-4.7.0/css/font-awesome.css">
<i class="fa fa-camera-retro"></i>
<i class="fa fa-camera-retro fa-lg"></i> fa-lg
<i class="fa fa-camera-retro fa-2x"></i> fa-2x
<i class="fa fa-camera-retro fa-3x"></i> fa-3x
<i class="fa fa-camera-retro fa-4x"></i> fa-4x
<i class="fa fa-camera-retro fa-5x"></i> fa-5x
<i class="fa fa-refresh fa-spin fa-fw" aria-hidden="true"></i>
<span class="sr-only">Refreshing...</span>
6.iconfont字体
地址
点击图标库------登录------把需要的图标加入购物车------选择添加项目至-------下载到本地------------------放到文件夹下面-----里面的.html文件有具体的用法
6.icomoon字体
地址
其余的和bootstrap的写法是一样的