Home >Web Front-end >CSS Tutorial >A detailed introduction to how to use !important statement to force priority in CSS

A detailed introduction to how to use !important statement to force priority in CSS

黄舟
黄舟Original
2017-07-27 11:32:152523browse

!important statement enforces priority

There is another most invincible statement in CSS priority, which is !important.

In CSS style sheets, styles with !important declaration are used first, and their priority will override style declarations anywhere and in any way, including styles declared in the inline style attribute.

For example, the following code:

<style type="text/css"> 
p{ color:red !important; }  
</style> 
<p style="color: blue; ">这是一行文字</p>

This line of text here is still displayed in red font in the browser.

So, the priority of CSS style matching follows the following order:

(1) !important statement is above all else.

(2) Inline styles come second.

(3) The declarations in the style sheet are sorted by the weight of the selector.

(4) Finally, match styles according to the order in which the browser executes the style sheet, following the "last come first" principle.

Of course, one final point must be emphasized: if no style is set, the style of the parent node will be automatically inherited.

The above is the detailed content of A detailed introduction to how to use !important statement to force priority 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