HTML网站外部字体包的引用和兼容写法@font-face

@font-face外部字体包的引用和兼容

一. 常用的字体格式有 woff,ttf,eot,otf,svg

字体兼容写法

@font-face{
	font-family:"tl01";
	src: url("../font/PlayfairDisplay-Bold.woff") format("woff"),
       url("../font/PlayfairDisplay-Bold.ttf") format("truetype"),
       url("../font/PlayfairDisplay-Bold.eot") format("embedded-opentype"),
       url("../font/PlayfairDisplay-Bold.otf") format("opentype"),
	   url('../font/PlayfairDisplay-Bold.svg') format('svg');
}

二. @font-face属性介绍

font-family: 自定义字体名称
src: 引用的字体路径位置
font-style: normal italic oblique (默认正常)
font-weight: 定义字体的粗细。默认值是"正常"

  1. 这里需要自定义一套字体,需要有正常,细,粗不同的效果(前面引入字体发现只有 blod 可以加粗,lighter没有生效,现在来优化一下)
    注: 同一套字体font-family的名称要一致
    这里可以看出同一字体和样式下,定义了font-weight和未定义的区别
    效果图
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style>
			@font-face{
				font-family:"Source";
				src:url("css/font/SourceHanSansCN-Normal.otf") format("opentype");     
			}
			@font-face{
				font-family:"Source";
				src:url("css/font/SourceHanSansCN-Light.otf") format("opentype");     
				font-weight: 300;
			}
			@font-face{
				font-family:"Source";
				src:url("css/font/SourceHanSansCN-Bold.otf") format("opentype");     
				font-weight: 600;
			}
			@font-face{
				font-family:"Sans";
				src:url("css/font/SourceHanSansCN-Normal.otf") format("opentype");     
			}
			.list01 p{font-family: Source;}
			.list02 p{font-family: Sans;}
			.min{width: 500px;margin: 100px auto;}
			h3{font-size: 40px;color: #f00;margin: 10px auto;font-weight: bold;}
			p{font-size: 32px;color: #333;line-height: 60px;margin: 0;}
			p:nth-of-type(1){font-weight: 300;}
			p:nth-of-type(3){font-weight: 600;}
		</style>
	</head>
	<body>
		<div class="min">
			<div class="list01">
				<p>哈哈哈哈,我是细体</p>
				<p>哈哈哈哈,我是正常</p>
				<p>哈哈哈哈,我是加粗</p>
			</div>
			<h3>以下是未定义对比</h3>
			<div class="list02">
				<p>哈哈哈哈,我是细体</p>
				<p>哈哈哈哈,我是正常</p>
				<p>哈哈哈哈,我是加粗</p>
			</div>
		</div>
	</body>
</html>

三. 这里分享一个我常用的字体转码网站

字客网:https://www.fontke.com/tool/convfont/

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值