CSS字体

设置文本的字体

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p.serif{font-family:"Times New Roman",Times, serif;}
			p.sansserif{font-family:Arial,Helvetica,sans-serif;}
		</style>
	</head>
	<body>
		<h1>CSS font-family</h1>
		<p class="serif">这一段的字体是 Times New Roman </p>
		<p class="sansserif">这一段的字体是 Arial.</p>

	</body>
</html>

设置字体大小

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			h1 {font-size:250%;}
			h2 {font-size:200%;}
			p {font-size:100%;}
		</style>
	</head>
	<body>
		<h1>This is heading 1</h1>
		<h2>This is heading 2</h2>
		<p>This is a paragraph.</p>

	</body>
</html>

用px设置字体的大小

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			h1 {font-size:40px;}
			h2 {font-size:30px;}
			p {font-size:14px;}
		</style>
	</head>
	<body>
	<h1>This is heading 1</h1>
	<h2>This is heading 2</h2>
	<p>This is a paragraph.</p>
	<p>允许在 Internet Explorer 9, Firefox, Chrome, Opera, 和 Safari 中通过缩放浏览器调整文本大小。</p>
	<p><b>注意:</b>这个例子在 IE9之前的版本不工作, prior version 9.</p>

	</body>
</html>

用em设置字体的大小

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			h1 {font-size:2.5em;} /* 40px/16=2.5em */
			h2 {font-size:1.875em;} /* 30px/16=1.875em */
			p {font-size:0.875em;} /* 14px/16=0.875em */
		</style>
	</head>
	<body>
		<h1>This is heading 1</h1>
		<h2>This is heading 2</h2>
		<p>This is a paragraph.</p>
		<p>使用 em 单位,允许在所有浏览器中调整文本大小。
		不幸的是,仍然是IE浏览器的问题。调整文本的大小时,会比正常的尺寸更大或更小。
		</p>

	</body>
</html>

用百分百和em设置字体的大小

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			body {font-size:100%;}
			h1 {font-size:2.5em;}
			h2 {font-size:1.875em;}
			p {font-size:0.875em;}
		</style>
	</head>
	<body>
		<h1>This is heading 1</h1>
		<h2>This is heading 2</h2>
		<p>This is a paragraph.</p>
		<p>在所有浏览器中,可以显示相同的文本大小,并允许所有浏览器缩放文本的大小。</p>

	</body>
</html>

设置字体的样式

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p.normal {font-style:normal;}
			p.italic {font-style:italic;}
			p.oblique {font-style:oblique;}
		</style>
	</head>
	<body>
		<p class="normal">这是一个段落,正常。</p>
		<p class="italic">这是一个段落,斜体。</p>
		<p class="oblique">这是一个段落,斜体。</p>

	</body>
</html>

设置字体的异体

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p.normal {font-variant:normal;}
			p.small {font-variant:small-caps;}
		</style>
	</head>
	<body>
		<p class="normal">My name is Hege Refsnes.</p>
		<p class="small">My name is Hege Refsnes.</p>
	</body>
</html>

设置字体的粗细

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p.normal {font-weight:normal;}
			p.light {font-weight:lighter;}
			p.thick {font-weight:bold;}
			p.thicker {font-weight:900;}
		</style>
	</head>
	<body>
		<p class="normal">This is a paragraph.</p>
		<p class="light">This is a paragraph.</p>
		<p class="thick">This is a paragraph.</p>
		<p class="thicker">This is a paragraph.</p>
	</body>
</html>

在一个声明中设置所有字体的属性

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8"> 
		<title>自学教程(如约智惠.com)</title> 
		<style>
			p.ex1
			{
				font:15px arial,sans-serif;
			}

			p.ex2
			{
				font:italic bold 12px/30px Georgia,serif;
			}
		</style>
	</head>
	<body>
		<p class="ex1">This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.</p>
		<p class="ex2">This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph. This is a paragraph.</p>
	</body>
</html>

参考:

https://www.yuque.com/docs/share/13dd32c1-bb61-438f-9abc-44d88cdd5ae8

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值