!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!