Home > Web Front-end > Front-end Q&A > css important what is

css important what is

藏色散人
Release: 2023-01-04 09:38:23
Original
2379 people have browsed it

css important is a syntax defined by CSS1. Its function is to increase the application priority of specified style rules and allow the browser to execute this statement first. Its syntax format is such as "{ sRule !important }", which is generally used Doing hacks.

css important what is

The operating environment of this article: windows10 system, css3, thinkpad t480 computer.

Recommendation: "css video tutorial"

!important in CSS is generally used for hacking, followed by the !important css statement, so that Browsers prefer to execute this statement.

Because css has inherited styles, adding !importanrt can override the parent style. It cannot be recognized in IE6, but can be used in IE7 and other browsers to handle browser compatibility.

!important

!important is a syntax defined by CSS1, which is used to increase the application priority of specified style rules. The syntax format { sRule!important } is written directly at the end of the definition, such as:

p{color:green !important;}
Copy after login

Note: IE has never supported this syntax, but other browsers do. Therefore, we can use this to define styles for FF and IE browsers respectively.

If a style A is defined, such as font-size, and you do not intend to let the style A overwrite this font-size in the future, you can also use !important. And if the new style is also used! important will still be forcibly overwritten

.A{
 font-size:12px !important;
}
.A{
 font-size:14px;   //不会生效
}
.A{
 font-size:14px !important; //生效
}
Copy after login

Note that it must be a style with the same name, that is, a style with both style names called A. It will not work if it is a parent and a child, for example :

<html>
<head>
<style>
.father{
font-size:12px !important;
}
.child{
font-size:14px;
}
</style>
<body>
<div class="father">
 <div class="child">I am child </div>
</div>
</body>
</html>
Copy after login

In this case, the child's font-size is 14px and is not affected by the father.

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template