0

我正在尝试在 HTML中更改整个页面的字体。总的来说,我的意思是一切:按钮、表单等。有没有办法在 CSS 中做到这一点?

html {
    color: green;
}

这将使文本变为绿色,但不是按钮的文本。

4

5 回答 5

3

好吧,有通用选择器

* {
  color: green;
}

但是请注意,此选择器的特殊性是最低的(MDN)。

于 2013-08-13T20:44:27.967 回答
2

通配符选择器

* {
    color: green;
}

您可能需要覆盖内联 CSS 和 javascript 生成的 CSS。在这种情况下!important也使用

* {
        color: green !important;
    }
于 2013-08-13T20:44:55.453 回答
1

If you don't need to support IE < 8, and want something that's less smelly, set an explicit color only on html and force everything else to inherit the color. Colors are already inherited by default on most elements, but not all of them.

Since this means applying two different color declarations, you will need two separate rules:

html {
    color: green;
}

body * {
    color: inherit !important;
}
于 2013-08-14T06:32:47.340 回答
1

使用*通用CSS选择器。

通用选择器匹配任何元素类型。如果它不是简单选择器的唯一组件,它可以被暗示(因此被省略)。

选择器 div*将匹配以下 em 元素:

  • h1 元素中的“通用”(匹配<h1>
  • p 元素中的“强调”(匹配<p>
  • 第一个 li 元素中的“not”(匹配 the<ul>或 the <li>
  • 第二个 li 元素中的“type”(匹配 the<ul>或 the <li>

例子:

This rule set will be applied to every element in a document:

* {
  color: green;
}

另外要补充的是,它与大多数浏览器兼容,尽管它在Internet Explorer 5.5, 6.0, 7.0.

于 2013-08-13T20:50:11.410 回答
0

老实说,您不应该依赖通配符选择器来执行此操作。您应该利用 CSS 的原生继承。最好的办法是从您的样式表中删除特定的颜色声明(根据需要),并将颜色添加到您的正文或 html 标记中。使用通配符与此类似,除了您声明每个元素都应具有与本机继承相对的 CSS。

于 2013-08-13T20:50:57.990 回答