国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Manuel en ligne CSS / CSS Fonts (字體)

CSS Fonts (字體)


CSS字體屬性定義字體,加粗,大小,文字樣式。


serif和sans-serif字體之間的區(qū)別

serif.gif

在計(jì)算機(jī)屏幕上,sans-serif字體被認(rèn)為是比serif字體容易閱讀


CSS字型

在CSS中,有兩種類型的字體系列名稱:

  • 通用字體系列 - 擁有相似外觀的字體系統(tǒng)組合(如 "Serif" 或 "Monospace")

  • 特定字體系列 - 一個(gè)特定的字體系列(如 "Times" 或 "Courier")

Generic family字體系列說明
SerifTimes New Roman
Georgia
Serif字體中字符在行的末端擁有額外的裝飾
Sans-serifArial
Verdana
"Sans"是指無 - 這些字體在末端沒有額外的裝飾
MonospaceCourier New
Lucida Console
所有的等寬字符具有相同的寬度

字體系列

font-family 屬性設(shè)置文本的字體系列。

font-family 屬性應(yīng)該設(shè)置幾個(gè)字體名稱作為一種"后備"機(jī)制,如果瀏覽器不支持第一種字體,他將嘗試下一種字體。

注意: 如果字體系列的名稱超過一個(gè)字,它必須用引號,如Font Family:"宋體"。

多個(gè)字體系列是用一個(gè)逗號分隔指明:

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</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>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


字體樣式

主要是用于指定斜體文字的字體樣式屬性。

這個(gè)屬性有三個(gè)值:

  • 正常 - 正常顯示文本

  • 斜體 - 以斜體字顯示的文字

  • 傾斜的文字 - 文字向一邊傾斜(和斜體非常類似,但不太支持)

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</title>
<style>
p.normal {font-style:normal;}
p.italic {font-style:italic;}
p.oblique {font-style:oblique;}
</style>
</head>

<body>
<p class="normal">This is a paragraph, normal.</p>
<p class="italic">This is a paragraph, italic.</p>
<p class="oblique">This is a paragraph, oblique.</p>
</body>

</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


字體大小

font-size 屬性設(shè)置文本的大小。

能否管理文字的大小,在網(wǎng)頁設(shè)計(jì)中是非常重要的。但是,你不能通過調(diào)整字體大小使段落看上去像標(biāo)題,或者使標(biāo)題看上去像段落。

請務(wù)必使用正確的HTML標(biāo)簽,就<h1> - <h6>表示標(biāo)題和<p>表示段落:

字體大小的值可以是絕對或相對的大小。

絕對大?。?/p>

  • 設(shè)置一個(gè)指定大小的文本

  • 不允許用戶在所有瀏覽器中改變文本大小

  • 確定了輸出的物理尺寸時(shí)絕對大小很有用

相對大?。?/p>

  • 相對于周圍的元素來設(shè)置大小

  • 允許用戶在瀏覽器中改變文字大小

如果你不指定一個(gè)字體的大小,默認(rèn)大小和普通文本段落一樣,是16像素(16px=1em)。


設(shè)置字體大小像素

設(shè)置文字的大小與像素,讓您完全控制文字大?。?/p>

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</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>Specifying the font-size in px allows Internet Explorer 9, Firefox, Chrome, Opera, and Safari to resize the text.</p>
<p><b>注意:</b>這個(gè)例子在 IE9之前的版本不工作, prior version 9.</p>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

上面的例子可以在 Internet Explorer 9, Firefox, Chrome, Opera, 和 Safari 中通過縮放瀏覽器調(diào)整文本大小。

雖然可以通過瀏覽器的縮放工具調(diào)整文本大小,但是,這種調(diào)整是整個(gè)頁面,而不僅僅是文本


用em來設(shè)置字體大小

為了避免Internet Explorer 中無法調(diào)整文本的問題,許多開發(fā)者使用 em 單位代替像素。

em的尺寸單位由W3C建議。

1em和當(dāng)前字體大小相等。在瀏覽器中默認(rèn)的文字大小是16px。

因此,1em的默認(rèn)大小是16px??梢酝ㄟ^下面這個(gè)公式將像素轉(zhuǎn)換為em:px/16=em

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</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>Specifying the font-size in em allows all major browsers to resize the text.
Unfortunately, there is still a problem with older versions of IE. When resizing the text, it becomes larger/smaller than it should.
</p>
</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

在上面的例子,em的文字大小是與前面的例子中像素一樣。不過,如果使用 em 單位,則可以在所有瀏覽器中調(diào)整文本大小。

不幸的是,仍然是IE瀏覽器的問題。調(diào)整文本的大小時(shí),會比正常的尺寸更大或更小。


使用百分比和EM組合

在所有瀏覽器的解決方案中,設(shè)置 <body>元素的默認(rèn)字體大小的是百分比:

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</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>Specifying the font-size in percent and em displays the same size in all 
major browsers, and allows all browsers to resize the text!</p>

</body>
</html>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

我們的代碼非常有效。在所有瀏覽器中,可以顯示相同的文本大小,并允許所有瀏覽器縮放文本的大小。


更多實(shí)例

設(shè)置字體加粗
這個(gè)例子演示了如何設(shè)置字體的加粗。

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</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>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

可以設(shè)置字體的轉(zhuǎn)變
這個(gè)例子演示了如何設(shè)置字體的轉(zhuǎn)變。

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</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>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例

在一個(gè)聲明中的所有字體屬性
本例演示如何使用簡寫屬性將字體屬性設(shè)置在一個(gè)聲明之內(nèi)。

實(shí)例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>php中文網(wǎng)(php.cn)</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>

運(yùn)行實(shí)例 ?

點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例


所有CSS字體屬性

Property描述
font在一個(gè)聲明中設(shè)置所有的字體屬性
font-family指定文本的字體系列
font-size指定文本的字體大小
font-style指定文本的字體樣式
font-variant以小型大寫字體或者正常字體顯示文本。
font-weight指定字體的粗細(xì)。