What does css important mean?

藏色散人
Release: 2023-01-05 16:07:50
Original
2796 people have browsed it

important in css is a syntax used to increase the application priority of specified style rules. Its syntax format is such as "{sRule!important}"; high-priority css styles will override low-priority css styles. style.

What does css important mean?

The operating environment of this article: Windows7 system, HTML5&&CSS3 version, Dell G3 computer.

In HTML web pages, css styles are used based on priority. CSS styles with high priority will override styles with low priority, and many css attributes are inherited, which will affect us. Web page display, we can use !important to change this situation.

!important is a syntax defined in 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.

【Recommended learning: css video tutorial

The above is the detailed content of What does css important mean?. 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