覆盖 CSS 中继承的 h1 和 h3 值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11630365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 04:35:03  来源:igfitidea点击:

override inherited h1 and h3 values in CSS

csstwitter-bootstrap

提问by Khuram Malik

I have the following CSS that is being inherited (the original CSS):

我有以下正在继承的 CSS(原始 CSS):

h1 { 
    font-size:30px;
    line-height:36px;
}
h1 small {
    font-size:18px;
}

I have a class whereby i want to override the h1property like so:

我有一个类,我想像这样覆盖h1属性:

.logo h1 {
  font-family: "Euphemia UCAS";
  font-size: 200px !important;
  font-weight: normal;
  color: #222222;
}

How can I do this without modifying the original CSS? The !importantvalue did not help.

如何在不修改原始 CSS 的情况下执行此操作?该!important值没有帮助。

link: https://dl.dropbox.com/u/3417415/Storify/mockups/screen1.html

链接:https: //dl.dropbox.com/u/3417415/Storify/mockups/screen1.html

回答by Michael Giovanni Pumo

You are applying your CSS selector incorrectly.

您错误地应用了 CSS 选择器。

Your .logoclass is ON the header tag itself, from what I can see in your code.

你的.logo类是在标题标签本身,从我可以在你的代码中看到。

Your CSS should instead be:

你的 CSS 应该是:

h1.logo {
  font-family: "Euphemia UCAS";
  font-size: 200px !important;
  font-weight: normal;
  color: #222222;
}

Just double check where this class is exactly being applied.

只需仔细检查该类的确切应用位置。

Also, just checked your HTML again and it looks like this:

另外,再次检查您的 HTML,它看起来像这样:

<h3 class="logo">Storify</h3>

So your CSS should really be:

所以你的 CSS 应该是:

h3.logo {
  font-family: "Euphemia UCAS";
  font-size: 200px !important;
  font-weight: normal;
  color: #222222;
}

Or am I misunderstanding you at all?

还是我完全误解了你?

回答by Paretozen

You can use a script element in your html.

您可以在 html 中使用脚本元素。

Within the script Add an event handler via

在脚本中添加一个事件处理程序通过

addEventListener('load', function () {
   // Change your css properties here.
});

This way you are sure no inheritance of css styles can occur.

通过这种方式,您可以确定不会发生 css 样式的继承。