:lang()
        
        
          
                Baseline
                
                  Widely available
                
                 *
              
        
        
        
          
                
              
                
              
                
              
        
        
      
      This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
* Some parts of this feature may have varying levels of support.
尝试一下
*:lang(en-US) {
  outline: 2px solid deeppink;
}
<p lang="en-US">
  Music during road trips and long commutes aren’t a problem, but using
  headphones isn’t the best thing to do while driving in your car.
</p>
<p lang="pl-PL">
  Gdy widzimy znak z narysowaną czaszką i napisem
  <strong lang="en-US">DANGER</strong> to lepiej nie wchodzić do środka.
</p>
语法
>形式语法
css
:lang(<language-code>) {
  /* ... */
}
参数
示例
在这个例子中,:lang() 伪类使用子组合器来匹配引用元素 (<q>) 的父元素。需要注意的是,此处演示的方法并不是唯一的,最好的方法需要依据文档类型来确定。还需要注意的是,Unicode 值用于指定一些特殊字符的引用。
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>  | 
            
浏览器兼容性
Loading…
参见
- 语言相关伪类:
:lang、:dir - HTML 
lang属性 - HTML 
translate属性 - RFC 5646: 用于标识语言的标签(也称为 BCP 47)