CSS font-style 屬性定義了要顯示的字體類型。它可以是斜體、斜體或正常的。此 CSS 屬性用於定義元素文本內容的字體樣式。
用法
font-style:normal | italic | oblique | initial | inherit;
屬性值
此 CSS 屬性的屬性值列表如下:
關鍵字 | 描述 |
---|---|
normal | 這是默認值。使用此值,瀏覽器將顯示正常的字體文本。 |
italic | font-style 屬性的該屬性值用於使字體變為斜體。斜體字體是字體的草書版本。 |
oblique | font-style 屬性的這個屬性值用於使字體傾斜。傾斜字體是字體的傾斜版本。 |
initial | 使用此值,瀏覽器將顯示默認的初始字體樣式。本質上,此值將屬性設置為其默認值。 |
inherit | 它從其父元素繼承屬性。 |
如果給定的 font-family 具有嵌入的斜體或斜體字體,瀏覽器將選擇該字體。如果沒有斜麵或斜麵可用,瀏覽器將模仿傾斜效果。如果我們定義了斜體值,並且沒有可用的斜體,瀏覽器會在嘗試模仿斜體之前檢查斜體。
同樣的過程將應用於斜麵,就好像沒有斜麵可用一樣,瀏覽器在嘗試模仿斜麵之前首先檢查斜麵。
為了防止瀏覽器添加傾斜或斜體的模仿版本,我們可以使用 font-synthesis 屬性(如果支持)。
讓我們通過一個例子來理解上麵的屬性值。
示例
在此示例中,我們使用 font-style 屬性的所有值。
<!DOCTYPE html>
<html>
<head>
<style>
p
{
font-size:200%;
}
</style>
</head>
<body>
<p> This is an example of using the font-style property in CSS. </p>
<h2 style = "font-style:normal;"> font-style:normal; This heading is shown in normal font. </h2>
<h2 style = "font-style:italic;"> font-style:italic; This heading is shown in italic font. </h2>
<h2 style = "font-style:oblique;"> font-style:oblique; This heading is shown in oblique font. </h2>
</body>
</html>
輸出:

相關用法
- CSS font-style用法及代碼示例
- CSS font-stretch用法及代碼示例
- CSS font-stretch屬性用法及代碼示例
- CSS font-size-adjust用法及代碼示例
- CSS font-size用法及代碼示例
- CSS font-synthesis屬性用法及代碼示例
- CSS font-weight用法及代碼示例
- CSS font-family用法及代碼示例
- CSS font-variant-caps屬性用法及代碼示例
- CSS font-feature-settings屬性用法及代碼示例
- CSS font-variant-alternates屬性用法及代碼示例
- CSS font-variant-ligatures屬性用法及代碼示例
- CSS font-variant屬性用法及代碼示例
- CSS font-variant-position屬性用法及代碼示例
- CSS font-display用法及代碼示例
- CSS font-kerning用法及代碼示例
- CSS font-optical-sizing屬性用法及代碼示例
- CSS font-variant-settings屬性用法及代碼示例
- CSS font-variant-numeric屬性用法及代碼示例
- CSS flex-grow用法及代碼示例
注:本文由純淨天空篩選整理自 CSS font-style property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。