--- title: text-transform slug: Web/CSS/text-transform tags: - CSS3 - text-transform - uppercase translation_of: Web/CSS/text-transform ---
{{CSSRef}}
text-transform CSS属性指定如何将元素的文本大写。它可以用于使文本显示为全大写或全小写,也可单独对每一个单词进行操作。
text-transform属性考虑特定于语言的案例映射规则,如:
in Turkic languages, like Turkish (tr
), Azerbaijani (az
), Crimean Tatar (crh
), Volga Tatar (tt
), and Bashkir (ba
), there are two kinds of i, with and without the dot, and two case pairings: i
/İ
and ı
/I
.
In German (de
), the ß
becomes SS
in uppercase.
In Dutch (nl
), the ij
digraph becomes IJ
, even with text-transform: capitalize
, which only put the first letter of a word in uppercase.
In Greek (el
), vowels lose their accent when the whole word is in uppercase (ά
/Α
), except for the disjunctive eta (ή
/Ή
). Also, diphthongs with an accent on the first vowel lose the accent and gain a diaeresis on the second vowel (άι
/ΑΪ
).
In Greek (el
), the lowercase sigma character has two forms: σ
and ς
. ς
is used only when sigma terminates a word. When applying text-transform: lowercase
to an uppercase sigma (Σ
), the browser needs to choose the right lowercase form based on context.
在其他一些其他特定的情况下,映射规则不被任何浏览器考虑在内:
ga
), a prefix letter remains in lowercase when the base initial is capitalised, so in this example the h-
should not be capitalized: text-transform: uppercase
will change Meud na h-aplacaid
to MEUD NA H-APLACAID
which violates the locale orthographic rules, as it ought to be MEUD NA h-APLACAID.
语言由 lang HTML属性或 xml:lang
XML属性定义。
对于这些特定情况的支持因浏览器而异,因此请检查浏览器兼容性表。
{{cssinfo}}
/* Keyword values */
text-transform: capitalize;
text-transform: uppercase;
text-transform: lowercase;
text-transform: none;
text-transform: full-width;
/* Global values */
text-transform: inherit;
text-transform: initial;
text-transform: unset;
capitalize
这个关键字强制每个单词的首字母转换为大写。其他的字符保留不变(它们写在元素里的文本保留原始大小写)。字母是Unicode字符集或者数字里定义的字符 {{experimental_inline}};因此单词开头的任何标点符号或者特殊符号将会被忽略。
Authors should not expect capitalize
to follow language-specific titlecasing conventions (such as skipping articles in English).
uppercase
lowercase
none
full-width
{{experimental_inline}}none
<p>Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</strong> </p>
<p>text-transform: none <strong><span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...
</span></strong> </p>
span {
text-transform: none;
}
strong { float: right; }
This demonstrates no text transformation.
{{ EmbedLiveSample('none', '100%', '100px') }}
capitalize
(普通)<p>Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...</strong> </p>
<p>text-transform: capitalize<strong>
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...
</span></strong>
</p>
span {
text-transform: capitalize;
}
strong { float: right; }
This demonstrates text capitalization.
{{ EmbedLiveSample('capitalize_(General)', '100%', '100px') }}
<p>Initial String <strong>(this) “is” [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transform!
</strong> </p>
<p>text-transform: capitalize<strong>
<span>(this) “is” [a] –short– -test- «for» *the* _css_ ¿capitalize? ?¡transform!
</span></strong>
</p>
span {
text-transform: capitalize;
}
strong { float: right; }
This demostrates how initial punctuations of a word are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category.
{{ EmbedLiveSample('capitalize_(Punctuation)', '100%', '100px') }}
<p>Initial String <strong>ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl
</strong> </p>
<p>text-transform: capitalize<strong>
<span>ⓐⓑⓒ (ⓓⓔⓕ) —ⓖⓗⓘ— ⓙkl
</span></strong>
</p>
span {
text-transform: capitalize;
}
strong { float: right; }
This demonstrates how initial symbols are ignored. The keyword target the first letter, that is the first Unicode character part of the Letter or Number general category.
{{ EmbedLiveSample('capitalize_(Symbols)', '100%', '100px') }}
<p>Initial String <strong lang="nl">The Dutch word: "ijsland" starts with a digraph.
</strong> </p>
<p>text-transform: capitalize<strong>
<span lang="nl">The Dutch word: "ijsland" starts with a digraph.
</span></strong>
</p>
span {
text-transform: capitalize;
}
strong { float: right; }
This demonstrates how the Dutch ij digraph must be handled like one single letter.
{{ EmbedLiveSample('capitalize_(Dutch_ij_digraph)', '100%', '100px') }}
uppercase
(普通)<p>Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...
</strong> </p>
<p>text-transform: uppercase<strong>
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...
</span></strong>
</p>
span {
text-transform: uppercase;
}
strong { float: right; }
This demonstrates transforming the text to uppercase.
{{ EmbedLiveSample('uppercase_(General)', '100%', '100px') }}
<p>Initial String <strong>Θα πάμε στο "Θεϊκό φαΐ" ή στη "Νεράιδα"
</strong> </p>
<p>text-transform: uppercase<strong>
<span>Θα πάμε στο "Θεϊκό φαΐ" ή στη "Νεράιδα"
</span></strong>
</p>
span {
text-transform: uppercase;
}
strong { float: right; }
This demonstrates how Greek vowels except disjunctive eta should have no accent, and the accent on the first vowel of a vowel pair becomes a diaeresis on the second vowel.
{{ EmbedLiveSample('uppercase_(Greek_Vowels)', '100%', '100px') }}
lowercase
(普通)<p>Initial String <strong>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...
</strong> </p>
<p>text-transform: lowercase<strong>
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit, ...
</span></strong>
</p>
span {
text-transform: lowercase;
}
strong { float: right; }
This demonstrates transforming the text to lowercase.
{{ EmbedLiveSample('lowercase_(General)', '100%', '100px') }}
<p>Initial String <strong>Σ IS A greek LETTER that appears SEVERAL TIMES IN ΟΔΥΣΣΕΥΣ.
</strong> </p>
<p>text-transform: lowercase<strong>
<span>Σ IS A greek LETTER that appears SEVERAL TIMES IN ΟΔΥΣΣΕΥΣ.
</span></strong>
</p>
span {
text-transform: lowercase;
}
strong { float: right; }
This demonstrates how the Greek character sigma (Σ
) is transformed into the regular lowercase sigma (σ
) or the word-final variant (ς
), according the context.
{{ EmbedLiveSample('lowercase_(Greek_Σ)', '100%', '100px') }}
full-width
(普通)<p>Initial String <strong>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</strong> </p>
<p>text-transform: full-width<strong>
<span>0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&()*+,-./:;<=>?@{|}~</span></strong>
</p>
span {
text-transform: full-width;
}
strong { width: 100%; float: right; }
Some characters exists in two formats, normal width and a full-width, with different Unicode code points. The full-width version is used to mix them smoothly with Asian ideographic characters.
{{ EmbedLiveSample('full-width_(General)', '100%', '175px') }}
Specification | Status | Comment |
---|---|---|
{{SpecName('CSS4 Text', '#text-transform', 'text-transform')}} | {{Spec2('CSS4 Text')}} | From {{SpecName('CSS3 Text', '#text-transform', 'text-transform')}}, adds the full-size-kana keyword and allows the full-width keyword to be used together with another keyword. |
{{SpecName('CSS3 Text', '#text-transform', 'text-transform')}} | {{Spec2('CSS3 Text')}} | From {{SpecName('CSS2.1', 'text.html#caps-prop', 'text-transform')}}, extends letters to any Unicode character in the Number or Letter general category. Modifies the behavior of capitalize to apply to the first letter of the word, ignoring initial punctuations or symbols. Adds the full-width keyword to mix smoothly ideographic characters and alphabetical characters. |
{{SpecName('CSS2.1', 'text.html#caps-prop', 'text-transform')}} | {{Spec2('CSS2.1')}} | From {{SpecName('CSS1', '#text-transform', 'text-transform')}}, extends letters to non-latin bi-cameral scripts |
{{SpecName('CSS1', '#text-transform', 'text-transform')}} | {{Spec2('CSS1')}} | Initial definition |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoDesktop("1")}} | 4.0 | 7.0 | 1.0 |
capitalize (CSS3 version) |
{{CompatUnknown}}[1] | {{CompatGeckoDesktop("14")}}[1] | {{CompatUnknown}}[1] | {{CompatUnknown}}[1] | {{CompatUnknown}}[1] |
full-size-kana |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
full-width |
{{CompatNo}} | {{CompatGeckoDesktop("19")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
ß → SS |
{{CompatUnknown}} | {{CompatGeckoDesktop("1")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
i → İ and ı → I |
{{CompatNo}} | {{CompatGeckoDesktop("14")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatNo}} |
Dutch IJ digraph |
{{CompatNo}} | {{CompatGeckoDesktop("14")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Greek accented letters | 30 | {{CompatGeckoDesktop("15")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Σ → σ or word-final ς |
30 | {{CompatGeckoDesktop("14")}} | {{CompatNo}} | {{CompatNo}} | 6.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | 1.0 | {{CompatGeckoMobile("1")}} | 6.0 | 6.0 | 1.0 |
capitalize (CSS3 version) |
{{CompatUnknown}}[1] | {{CompatGeckoMobile("14")}}[1] | {{CompatUnknown}}[1] | {{CompatUnknown}}[1] | {{CompatUnknown}}[1] |
full-size-kana |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
full-width |
{{CompatNo}} | {{CompatGeckoMobile("19")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
ß → SS |
{{CompatUnknown}} | {{CompatGeckoMobile("1")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
i → İ and ı → I |
{{CompatNo}} | {{CompatGeckoMobile("14")}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatNo}} |
Dutch IJ digraph |
{{CompatNo}} | {{CompatGeckoMobile("14")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Greek accented letters | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Σ → σ or word-final ς |
{{CompatNo}} | {{CompatGeckoMobile("14")}} | {{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
[1] The capitalize
keyword was under-specified in CSS 1 and CSS 2.1. There were differences between browsers in the way the first letter was calculated (Firefox considered - and _ as letters, but not the others. Both Webkit and Gecko incorrectly considered letter-based symbols like ⓐ
to be real letters. Internet Explorer 9 was the closest to the CSS 2 definition, but with some weird cases). By precisely defining the correct behavior, CSS Text Level 3 cleans this mess up. The capitalize
line in the browser compatibility table contains the version the different engines started to support this now precisely defined behavior.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////