Home  >  Article  >  Web Front-end  >  How to use important in css

How to use important in css

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-04-15 17:38:077749browse

In CSS, you can write "!important" after the style to increase the application priority of the specified style rule. The syntax is "selector {style: value!important;}". It is not recognized in IE6, but can be used in IE7 and other browsers to handle browser compatibility.

How to use important in css

The operating environment of this tutorial: Windows 7 system, CSS3&&HTML5 version, Dell G3 computer.

CSS written in different places has different priorities. The definition in the css file < attribute in the element style, but if you use !important, it will increase the application priority of the specified style rules, syntax format { sRule!important }, that is, written at the end of the definition

!important syntax

selector {style: value!important;}

!important provides developers with a way to increase the weight of styles. It should be noted that !important is a declaration of the entire style, including the attributes and attribute values ​​of this style

Example

 
 
     !important实例  

For the above code, if the important attribute is not added, the hyperlink will The color is blue, but after adding important, the priority is increased and the display color is green.

Note:

  • If !important is used for a shorthand style attribute, then the sub-properties represented by this shorthand style attribute will be affected by !important .

  • The keyword !important must be placed at the end of a line of styles and before the semicolon on the line, otherwise it will have no effect. (However, the space before the semicolon will not affect it)

  • If for some special reasons, you have to declare two same properties in one code block, then please add !important after the first attribute, because doing so will give the first attribute more weight in all browsers except IE6 (this is a hack that is only available in IE6, but will not affect your CSS)

Recommended learning: css video tutorial

The above is the detailed content of How to use important in css. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn