你怎么读!在CSS中重要? [英] How do you read !important in CSS?

查看:328
本文介绍了你怎么读!在CSS中重要?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何CSS属性属性!important read?

How is the CSS attribute property !important read?

重要,感叹号重要,...?

在下面的答案中,似乎只是简单地读取 important bang important

Answer: From the answers below, it seems to be read simply important, or bang important.

推荐答案


一个!important声明(分隔符符号!和关键字
important 遵循声明)优先于正常的
声明。

an "!important" declaration (the delimiter token "!" and keyword "important" follow the declaration) takes precedence over a normal declaration.

http://www.w3.org/TR/CSS2/cascade.html#important-rules

基本上,两个样式规则是相同的...它给予标记!important 更大的重要性,并将应用这些样式。

Basically, where two style rules are the same... it gives the one marked !important greater importance and will apply those styles.

示例

div{
    opacity:0 !important;
}

div.jason{
    opacity:1;
}

即使第二个规则更具体元素+一个类而不是一个元素)

The first rule would be applied even though the second rule is more specific (one element + one class as opposed to one element)

注意:IE6忽略!important 当你有两个相同的属性,其中一个是重要的 - 它总是应用最后一个声明,无论它是否被标记为重要。 **从 @BoltClock 的评论。

Note: IE6 ignores !important when you have two of the same property and one of them is important - it'll always apply the last declaration, whether or not it was marked important. **Added from @BoltClock's comment below.

警告: !important 是一个锤子,应该只在绝对必要时使用。几乎总是,最好是使用更具体的选择器来实现更高的特异性,并以您想要的方式应用您的样式。 !important 可能会使未来的开发人员很难找到并更改您的代码。

Warning: !important is a hammer that should only be used when absolutely necessary. Almost always, it is better to use more specific selectors to achieve greater specificity and have your styles applied the way you want. !important can make it very difficult for future developers to find and make changes to your code.

一个很好的用例: !important 非常适合用户定义的样式,用户希望在特定方式在他的浏览器(说,使所有的背景黑色和文本黄色)。无需担心特殊性,用户可以向某些元素(如 body )添加样式,并使样式呈现。

One good use case: !important is great for user-defined styles, where a user wants to manipulate Web site pages in specific way in his browser (say make all the backgrounds black and the text yellow). Without having to worry about specificity, the user can add styles to certain elements (like body) and make the styles render.

这篇关于你怎么读!在CSS中重要?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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