CSS教程
CSS进阶

CSS font-variant

CSS font-variant属性指定如何设置元素的字体变量。其值可能是 normalsmall-caps。通过使用 small-caps 值,小写字母可转换为大写字母,但与原始大写字母相比较小。此属性指定文本是否应以 小写字母字体显示。
font-variant 属性生成的输出可以为受 text-transform 属性的值的影响。如果 font-variant 的值是 small-caps ,并且 text-transform 的值设置为 lowercase ,则字符将以小写形式出现。如果 font-variant 的值是 caps-caps ,并且 text-transform 的值设置为 uppercase ,则字符将以大写字母出现。
small-caps值如果源代码中的字母大写,CSS 属性将不起作用。假设我们有一个段落中的字母大写,并且我们将 font-variant 属性的值为 small-caps 应用于相应的段落,字体将显示为常规大写字母,而不是小写字母。

语法

font-variant: normal | small-caps | initial | inherit;

属性值

此CSS属性的值定义如下:
normal:这是默认值,用于指定普通字体。
small-caps:用于指定小写字体,其中小写字母显示为大写字母,但尺寸较小。
initial:它将属性设置为其默认值。
inherit: 它从其父元素继承属性。

示例

在此示例中,我们将 font-variant:small-caps; 应用于段落元素。在第一段中,文本已经是大写字母,因此 small-caps 值不会覆盖它。但是第二段中的文本受 small-caps 值的影响,因为它不是大写。
<!DOCTYPE html>
<html>
<head>
<style>
p {
font-variant: small-caps;
font-size: 25px;
}
h2 {
font-variant: normal;
}
</style>
</head>
<body>
<h2> This heading is shown in the normal font. </h2>
<p> HELLO WORLD </p>
<p> hello world. This text is affected by the <b> small-caps </b> value. </p>
</body>
</html>
输出
 CSS font-variant属性
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4