HTML - 字体

字体在使网站更加用户友好并提高内容可读性方面发挥着非常重要的作用.字体和颜色完全取决于用于查看页面的计算机和浏览器,但您可以使用HTML < font> 标记为网站上的文字添加样式,大小和颜色.您可以使用< basefont> 标记将所有文字设置为相同的大小,面和颜色.

字体标记有三个属性调用大小,颜色来自定义字体.要在网页中随时更改任何字体属性,只需使用< font>标签.在您使用</font>关闭之前,后面的文字将保持不变标签.您可以在一个< font>中更改一个或所有字体属性.标签.

注意 : 不推荐使用 font basefont 标签应该在将来的HTML版本中删除.因此不应该使用它们,建议使用CSS样式来操作字体.但仍然为了学习目的,本章将详细解释字体和基本标签.

设置字体大小

您可以设置内容字体大小使用 size 属性.可接受值的范围从1(最小)到7(最大).字体的默认大小为3.

示例

<!DOCTYPE html>
<html>

   <head>
      <title>Setting Font Size</title>
   </head>

   <body>
      <font size = "1">Font size = "1"</font><br />
      <font size = "2">Font size = "2"</font><br />
      <font size = "3">Font size = "3"</font><br />
      <font size = "4">Font size = "4"</font><br />
      <font size = "5">Font size = "5"</font><br />
      <font size = "6">Font size = "6"</font><br />
      <font size = "7">Font size = "7"</font>
   </body>

</html>

Relative Font Size

您可以指定比预设字体大多少个尺寸或少几个小尺寸。 您可以将其指定为<font size =" n">或<font size =" n">

Example

<!DOCTYPE html>
<html>

   <head>
      <title>Relative Font Size</title>
   </head>

   <body>
      <font size = "-1">Font size = "-1"</font><br />
      <font size = "+1">Font size = "+1"</font><br />
      <font size = "+2">Font size = "+2"</font><br />
      <font size = "+3">Font size = "+3"</font><br />
      <font size = "+4">Font size = "+4"</font>
   </body>

</html>

Setting Font Face

您可以使用face属性设置字体,但是请注意,如果查看页面的用户未安装字体,则他们将无法看到字体。 而是,用户将看到适用于该用户计算机的默认字体。

Example

<!DOCTYPE html>
<html>

   <head>
      <title>Font Face</title>
   </head>

   <body>
      <font face = "Times New Roman" size = "5">Times New Roman</font><br />
      <font face = "Verdana" size = "5">Verdana</font><br />
      <font face = "Comic sans MS" size =" 5">Comic Sans MS</font><br />
      <font face = "WildWest" size = "5">WildWest</font><br />
      <font face = "Bedrock" size = "5">Bedrock</font><br />
   </body>

</html>

Specify alternate font faces

访客只有在计算机上安装了该字体后,才能看到您的字体。 因此,可以通过列出用逗号分隔的字体名称来指定两个或多个字体。

<font face = "arial,helvetica">
<font face = "Lucida Calligraphy,Comic Sans MS,Lucida Console">

加载页面后,他们的浏览器将显示第一个可用的字体。 如果未安装任何给定字体,则它将显示默认字体Faces New Roman。

注意:检查HTML标准字体的完整列表。

Setting Font Color

您可以使用color属性设置任何喜欢的字体颜色。 您可以通过颜色名称或该颜色的十六进制代码指定所需的颜色。

注意:您可以检查带有代码的HTML颜色名称的完整列表。

Example

<!DOCTYPE html>
<html>

   <head>
      <title>Setting Font Color</title>
   </head>
	
   <body>
      <font color = "#FF00FF">This text is in pink</font><br />
      <font color = "red">This text is red</font>
   </body>
	
</html>

The <basefont> Element

<basefont>元素应该为文档的未包含在<font>标记中的任何部分设置默认字体大小,颜色和字体。 您可以使用<font>元素覆盖<basefont>设置。

<basefont>标记还具有颜色,大小和面部属性,并且通过为较大的大小提供1的值或为较小的两个大小提供2的值,将支持相对字体设置。

Example

<!DOCTYPE html>
<html>

   <head>
      <title>Setting Basefont Color</title>
   </head>
	
   <body>
      <basefont face = "arial, verdana, sans-serif" size = "2" color = "#ff0000">
      <p>This is the page's default font.</p>
      <h2>Example of the &lt;basefont&gt; Element</h2>
      
      <p><font size = "+2" color = "darkgray">
            This is darkgray text with two sizes larger
         </font>
      </p>

      <p><font face = "courier" size = "-1" color = "#000000">
            It is a courier font, a size smaller and black in color.
         </font>
      </p>
   </body>
	
</html>