CSS参考手册
选择 | Selectors
:lang
该:lang
CSS伪类基于所选定的语言匹配元素。在HTML中,语言是由lang
属性,<meta>
元素的组合来确定的,有时也可能由来自协议的信息(如HTTP首部)确定。对于其他文档类型,可能有其他文档方法来确定语言。
/* Matches paragraphs, but only if they are specified
as being en (English language) */
p:lang(en) {
quotes: '\201C' '\201D' '\2018' '\2019';
}
在HTML 4.0规范中指定了可接受的language-code
字符串。
语法
形式语法
:lang( <language-code> )
参数
语言编码language-code,
即要为其选择的字符串。
实例
在这个例子中,:lang
伪类用于使用子选择器来匹配一个quote元素的父元素。但请注意,这并不是唯一的方法,甚至有时也不是正确的方法(这取决于文档的类型)。请注意,Unicode值用于指定特殊的引号字符。
HTML
:lang(en) > q { quotes: '\201C' '\201D' '\2018' '\2019'; }
:lang(fr) > q { quotes: '« ' ' »'; }
:lang(de) > q { quotes: '»' '«' '\2039' '\203A'; }
CSS
<div lang="en"><q>This English quote has a <q>nested</q> quote inside.</q></div>
<div lang="fr"><q>This French quote has a <q>nested</q> quote inside.</q></div>
<div lang="de"><q>This German quote has a <q>nested</q> quote inside.</q></div>
结果
规范
Specification |
Status |
Comment |
---|---|---|
Selectors Level 4The definition of ':lang()' in that specification. |
Working Draft |
No change. |
Selectors Level 3The definition of ':lang()' in that specification. |
Recommendation |
No significant change. |
CSS Level 2 (Revision 1)The definition of ':lang()' in that specification. |
Recommendation |
Initial definition. |
浏览器兼容性
Feature |
Chrome |
Edge |
Firefox (Gecko) |
Internet Explorer |
Opera |
Safari |
---|---|---|---|---|---|---|
Basic support |
1.0 |
(Yes) |
1.0 (1.7 or earlier) |
8.0 |
8.0 |
3.1 |
Feature |
Android |
Edge |
Firefox Mobile (Gecko) |
IE Mobile |
Opera Mobile |
Safari Mobile |
---|---|---|---|---|---|---|
Basic support |
1.0 |
(Yes) |
1.0 (1) |
8.0 |
8.0 |
3.1 |
选择 | Selectors相关

层叠样式表( Cascading Style Sheets )是一种用来表现 HTML 或 XML 等文件样式的计算机语言。CSS 不仅可以静态地修饰网页,还可以配合各种脚本语言动态地对网页各元素进行格式化。