如何让我的@import样式表覆盖主样式表? [英] How do I get my @import stylesheet to override the main stylesheet?
问题描述
我在主样式表文件中使用 @import
导入了另一个样式表。我想要在 @import
样式表中所做的更改覆盖主样式表。这是可能吗?
I imported another stylesheet using @import
in the main style sheet file. I would like the changes I have made in the @import
stylesheet to override the main style sheet. Is this possible?
推荐答案
如果你的目标是通过导入另一个样式表来覆盖样式,你应该使用优先顺序。 / p>
If your goal is to override styles by importing another stylesheet, you should use the order of precedence.
<head>
<title>Title</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href="style-override.css" rel="stylesheet" type="text/css" />
</head>
这里 style.css
和 style-override.css
将包含您的新的自定义css。这些样式将覆盖 style.css
中的样式。这意味着你不需要使用!important
,因为样式被覆盖。
Here the style.css
is the original and style-override.css
would contain your new custom css. These styles will override the styles from style.css
. This means you won't need to use !important
because the style is overwritten.
避免!可以。
要执行@import
To do @import
<style type="text/css">
@import url("style.css");
@import url("style-override.css");
</style>
另外,如果你想从页面中删除所有样式,请使用css reset。
Also as a side note if you would rather remove all styles from the page, use a css reset.
<style type="text/css">
@import url("style.css");
@import url("reset.css");
@import url("style-override.css");
</style>
在 http://meyerweb.com/eric/tools/css/reset/ ,并将其添加到reset.css。
Check out a CSS reset at http://meyerweb.com/eric/tools/css/reset/ and add it to reset.css.
这篇关于如何让我的@import样式表覆盖主样式表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!