Share via


:lang

在文件中,選取使用指定之語言的元素。

語法

:lang (C) { sRules }

可能的值

sRules

指定一或多個階層式樣式表 (CSS) 屬性/值組的字串。

C

指定元素應符合之語言代碼的字串。

備註

當 C 的值符合元素語言值或者是這個值的子字串 (以連字號分隔) 時,便會套用設定的規則。C 的值應該是 RFC3066: Tags for the Identification of Languages (RFC3066:語言識別標籤) Gg721781.xtlink_newWindow(zh-tw,Expression.40).png 所指定的語言代碼。

如果 C 是空白或無效,選取器將不會有任何作用。

範例

下列程式碼範例使用 :lang 虛擬類別,在明確指定 en 語言值或其子集 (以連字號分隔) 的任何 p 元素上套用色彩。第一個段落包含 en-us ( en 的子集),因此變成綠色。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" 
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>

<head>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
<title>:lang pseudo-class</title>
<style type="text/css">
p:lang(en) {
color: green;
}
</style>
</head>

<body>
<div class="body">
<h1>:lang(C) Sample</h1>

<!-- This paragraph gets "en-us" (a subset of "en") and thus turns green. -->
<p lang="en-us">This paragraph's language is set to "en-us", so it's green.</p>

<!-- This paragraph has no language value and thus does not turn green. -->
<p>This paragraph has no language attribute, so it doesn't turn green.</p>

<!-- This paragraph is actually a div; therefore, even though its language value 
    is "en-us", it does not turn green. -->
<div lang="en-us">This div's language is set to "en-us", but this page's :lang 
    pseudo-class only applies to paragraphs, so it doesn't turn green.</div>
</div>
</body>
</html>

標準資訊

您可以在 CSS Selectors Level 3 (CSS 選取器層級 3) Gg721781.xtlink_newWindow(zh-tw,Expression.40).png 找到此虛擬類別的定義。

適用範圍

a , address , b , big , blockquote , body , br , button , caption , cite , code , dd , dfn , div , dl , dt , em , hn , i , img , input type=file , input type=image , input type=password , input type=text , kbd , label , legend , li , listing , marquee , menu , ol , p , plaintext , pre , s , samp , small , span , strike , strong , sub , sup , table , tbody , td , textarea , tfoot , th , thead , tr , tt , u , ul

另請參閱

概念

虛擬類別
虛擬類別與虛擬元素