在哪里设置 font-family: body 或 html 元素? [英] Where to set font-family: body or html element?

查看:47
本文介绍了在哪里设置 font-family: body 或 html 元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最好在哪里声明 font-family CSS 属性?在 htmlbody 元素上?

Where is it best to declare the font-family CSS property? On the html or body element?

html {
    font-family: sans-serif;
}

body {
    font-family: sans-serif;
}

我在网上搜索,但找不到确切的答案.

I searched online, but I cant find a definitive answer.

推荐答案

最佳实践是在body中设置font-family.

body {
   font-family: Arial !important;
}

!important 在这里很有用,因此如果您使用任何其他框架,您的 font-family 不会被覆盖.

The !important is useful here so that in case you are using any other framework, your font-family does not get overridden.

您也可以使用 * 选择器.

You can also use the * selector.

* {
    font-family: Arial !important;
}

*-selector 表示任何/所有元素,但在覆盖更具体的选择器时,它显然位于属性链的底部.

The *-selector means any/all elements, but will obviously be on the bottom of the property chain when it comes to overriding more specific selectors.

请注意,!important 标志会将 * 的字体样式呈现​​为绝对的,即使已使用其他选择器来设置文本(例如,body 或者一个 p).

Note that the !important flag will render the font-style for * to be absolute, even if other selectors have been used to set the text (for example, the body or maybe a p).

这篇关于在哪里设置 font-family: body 或 html 元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆