Because there are three different ways to import style sheets and a wide variety of style selectors, it is inevitable that there are duplicate definitions in the definition of the CSS style.For browsers, we need to consider which definition should be executed first.stayBeijing website constructionIn CSS design, style first should not be ignored.
Orthographic priority
From the position where styles are written, their priorities are:
In line style sheet. Internal style sheet. External style sheet.
That is to say, under the same CSS definition, the style defined in the XHTML tag using style must have priority over the style written in<style></Style>. The next or last step is to call and apply external style sheets.
Selector priority
For id and class, the definition of id takes precedence over that of class.For example: <div id="layout" class="mylayout">{... Text...}</div>
When two selectors are defined at the same time, for example:
The div will execute the definition in the id, that is, the background color is blue.The priority of having a class attribute is greater than that of not having a class attribute, such as the following CSS definitions: .mylayout{ background-color:red; } div{ background-color:green; }
The div will execute the definition in the class, that is, the background color is red.From the priority of selectors: id>class>type selectors.Selector priority can help us optimize CSS definition code. div{ background-color:green; } div#news{ background-color:black; } The background color of all divs is green, but the background color of news is black.In this way, individual special cases can be designed separately under most of the same conditions.