:lang()

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

* Some parts of this feature may have varying levels of support.

Псевдо-класс CSS :lang() выбирает элементы основываясь на языке, на котором они определены.

css
/* Выбирает все <p>, что на английском (en) */
p:lang(en) {
  quotes: "\201C" "\201D" "\2018" "\2019";
}

Примечание: В HTML язык определяется комбинацией атрибута lang, элемента <meta> и иногда информацией из протокола (такой, как заголовки HTTP ). Для других типов документов могут быть другие методы определения языка.

Синтаксис

Формальный синтаксис

Error: could not find syntax for this item

Параметр

<language-code>

<string>, представляющая язык, который вы хотите отобрать. Допустимые значения указаны в документации HTML.

Пример

In this example, the :lang() pseudo-class is used to match the parents of quote elements (<q>) using child combinators. Note that this doesn't illustrate the only way to do this, and that the best method to use depends on the type of document. Also note that Unicode values are used to specify some of the special quote characters.

HTML

html
<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>

CSS

css
:lang(en) > q {
  quotes: "\201C" "\201D" "\2018" "\2019";
}
:lang(fr) > q {
  quotes: "« " " »";
}
:lang(de) > q {
  quotes: "»" "«" "\2039" "\203A";
}

Результат

Спецификации

Specification
Selectors Level 4
# lang-pseudo

Совместимость с браузерами

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
:lang()
Comma-separated list of language codes as :lang(A, B)
Matching language codes with wildcards as :lang(*-Latn)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

Смотрите также