怎样使用CSS来改变字体
HTML4取消了FONT元素,也不是HTML5规格的一部分。因此,如果你想改变你的网页的字体,你应该学会怎么使用CSS(层叠样式表)。
难度:一般
所需时间:5分钟
如下:
使用文本HTML编辑器打开一个网页,它可能是一个新的或者现有的网页。
写一些文本:
文本字体为Arial
用SPAN元素环绕文本:
<span>This tex is in Arial</span>
4.添加属性style="" to the span tag:
<span style="">This tex is in Arial</span>
在style 属性里, 使用font-family style 改变字体:
<span style="font-family: Arial;">This tex is in Arial</span>
技巧:
Separate multiple font choices with a comma (,). For example:
用逗号(,)分隔多个字体选择.比如:
字体系列: Arial, Geneva, Helvetica, sans-serif;
在你的字体列表里至少要有两种字体,以便于如果浏览器没有首字体,它也能使用第二种字体代替。
每个CSS样式都是以分号(;)结束.当只有一个样式时,是不需要的,但是这是一种好的习惯。
这个例子使用了一致的样式,但是样式的最好的类型应该是外部的样式,以便于你能作用于多个元素。你可以使用一个分类设置文本块的样式。比如:
<span class="arial">This tex is in Arial</span>
Using the CSS:
.arial { font-family: Arial; }