Home >Web Front-end >Front-end Q&A >What is the conflict with css?

What is the conflict with css?

藏色散人
藏色散人Original
2021-03-22 15:19:162713browse

CSS conflict means that when multiple CSS styles are applied to the same element, there may be different formatting of the same attribute between these styles; when a conflict occurs, the browser follows the priority principle Or the latest principles to solve CSS conflict problems.

What is the conflict with css?

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

CSS conflicts and resolution

When multiple CSS styles are applied to the same element, there may be different formatting of the same attribute between these styles. When conflicts occur, the browser resolves CSS conflicts by following the following principles.

1. Priority principle

2. Recent principle

3. For style definitions of the same attribute, styles defined later will overwrite previously defined styles.

Priority principle: It means that the style with the highest priority is valid, among which inline style > inline style | link external style, that is, inline style has the highest priority, while inline style and link external style The priority of styles is determined by the position where they appear. Whoever appears later has higher priority. In styles of the same type, there are also different priorities between selectors. The priority of selectors is specified as: ID selector>class selector|pseudo-class selector|attribute selector>element selector|pseudo Element selector > Wildcard selector | Child element selector | Adjacent sibling selector, that is, the ID selector has the highest priority.

Latest principle: Mainly for inherited styles. The closer to the parent class style of the formatted element, the higher the priority. For example:

, set the style for the

tag, and its priority will be higher than the

tag style.

In addition, adding !important after the style can raise the priority of the style to the highest level (higher than the inline style)

[Recommended learning: css video tutorial

The above is the detailed content of What is the conflict with 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