[英]Apply different font-family to <p> tag according to HTML lang attribute
I have two font styles, and i want to apply each different font to <p>
tag when lang attribute in html changed.我有两种字体 styles,当 html 中的 lang 属性发生变化时,我想将每种不同的字体应用于<p>
标签。 For example when lang set to fr change <p>
font-family
to fr-font.例如,当 lang 设置为 fr 时,将<p>
font-family
更改为 fr-font。
You can select your elements with CSS' attribute selectors .您可以使用CSS 的属性选择器select 您的元素。 Your code might look like this:您的代码可能如下所示:
html[lang=fr] p {
font-family: sans-serif;
}
Use the :lang
pseudo-class which matches an element based on what language it is specified to be (and languages are inherited so you don't need to worry about targetting an element with a specific attribute, descendant combinators, or nesting).使用:lang
伪类,它根据指定的语言匹配元素(并且语言是继承的,因此您无需担心使用特定属性、后代组合符或嵌套来定位元素)。
p:lang(en) { font-style: italic; } p:lang(fr) { color: blue; }
<div lang="en"> <p>Is this English?</p> <p lang="fr">Est-ce français?</p> </div> <div lang="fr"> <p lang="en">Is this English?</p> <p>Est-ce français?</p> </div>
u can use the :lang()
attribute in css like this你可以像这样使用 css 中的:lang()
属性
p:lang(fr) {
font-family: yourFont;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.