Home >Web Front-end >CSS Tutorial >css hack principle
I recently read a few articles about css hack and thought it would be a good idea to sort them out.
Many people don’t understand the principle of css hack. In fact, everyone knows that different browsers have different parsing levels of CSS, which will lead to different effects on the generated pages; especially for browsers like IE that are addictive. For browsers, at this time we need to write different CSS for different browsers (especially IE). This process is called css hack. Instead of that hack, it can be said that css hack is a method that relies on different browsers. It is a strategy of "saving the country through curves" to achieve compatibility due to different rules and standards. Even so, we still hope that the world will be unified and have a unified standard that can unify browser specifications T T
css hack is mainly based on
1 .Browsers have different support for CSS and parsing results;
2. Priority relationship in CSS.
There are three commonly used CSS hacks, CSS internal hacks, selector hacks, and HTML header references. The first one is the most commonly used.
A.css internal hack:
CSS internal hack syntax is like this selector{?property:value?;} For example, IE6 can recognize underline "_" and asterisk "*", IE7 can recognize asterisk "*", But the underscore "_" cannot be recognized, and firefox cannot recognize both. Regarding the writing order, the CSS of browsers with strong recognition capabilities is generally written at the end.
<style> div{ background:green;/*forfirefox*/ *background:red;/*forIE6 IE7*/ } </style>
In this case, you have successfully hacked IE6 and 7;
For another example, only IE6 cannot recognize the writing method of "!important", but other versions of IE and modern browsers can recognize it
Other versions of IE and modern browsers, as well as "+", "