CSS rules can override each other, which we should be accustomed to. However, it is precisely because rules can override each other and child elements inherit the default behavior of parent elements that causes CSS conflicts. When encountering CSS conflicts, we usually add some more detailed rules to clarify how to display them to resolve the conflict. Usually the more detailed the rules, the higher the priority, but how is the priority defined?
First, distinguish according to the CSS definition position. The priority from low to high is as follows:
The rules for defining positions are also determined based on the number of selectors of different types. The priority of selectors from low to high is as follows:
That is, ID > Pseudo class > Attribute > Class > Element > Wildcard, first we count the number of IDs in the rule, the number of IDs The more rules, the higher the priority. If they are the same, count the pseudo-classes again, and so on.
Here is an example:
article p span{ color: blue;}#red{ color: red;}
Another example:
#wrapper header div nav #gnavi{ list-style-type: none;}#top #hright #gnavi{ list-style-type: square;}
In addition, the highest priority is the !import attribute. If !important is added, then continue to count the attributes and elements in the rules. number.
If you can avoid !important, don’t write it like this. This style is too difficult to extend.
Reference link:
Unless otherwise noted, this blog article is original. Please indicate the article address in the form of a link when reprinting: http://harttle.com/2015/07/16/css -priority.html

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment