Sometimes in the process of writing CSS, some restrictions always do not work, which involves the CSS style overlay problems, as follows
CSS Code
- #navigator {
- Height: 100%;
- Width: 200;
- Position:absolute;
- Left: 0;
- Border:solid 2 #EEE;
- }
- . current_block {
- Border:solid 2 #AE0;
- }
Find some textbooks (w3schools, etc.), just say that the order of the CSS is "style on the element" > "style element on file header" > "External Style File", but the precedence of multiple same styles in the style file is not explained in detail. After testing and continuing the search, you know that the priority is listed as follows:
1. The more precise the element selector selection of a style sheet, the higher the style precedence:
The ID selector Specifies the style > class selector for the specified style > element type selector for the specified style
So in the example above, #navigator的样式优先级大于. Current_block priority, timely. Current_block is newly added and does not work.
2. For styles developed by the same type selector, the higher the precedence in the style sheet file
Note that this is the higher priority in the style sheet file, rather than the order in which the element class appears. For example. Class2 appears in the style sheet after the. Class1:
CSS Code
- . Class1 {
- Color:black;
- }
- . class2 {
- color:red;
- }
When an element is specified as class, it is specified in class= "Class2 Class1", at which point the Class1 is followed by Class2 when specified in the element, but because Class1 in the style sheet file is in front of Class2, At this point, the Class2 is still a higher priority, and the color property is red, not black.
3. If you want a style to have a higher priority, you can use!important to specify:
CSS Code
- . Class1 {
- Color:black!important;
- }
- . class2 {
- color:red;
- }
At this point, the class will use black rather than red.
There are two solutions for the problem at first:
1. Take the border out of the #navigator and put it in a class. block, and. Block before the. Current_block:
CSS Code
- #navigator {
- Height: 100%;
- Width: 200;
- Position:absolute;
- Left: 0;
- }
- . Block {
- Border:solid 2 #EEE;
- }
- . current_block {
- Border:solid 2 #AE0;
- }
Requires Moren to specify class= "block" for #navigator element
2. Use!important:
CSS Code
- #navigator {
- Height: 100%;
- Width: 200;
- Position:absolute;
- Left: 0;
- Border:solid 2 #EEE;
- }
- . current_block {
- Border:solid 2 #AE0!important;
- }
No other changes are required to take effect at this time. It can be seen that the second scenario is simpler.
Transferred from: http://spartan1.iteye.com/blog/1526735
Style overlay order (GO) in CSS style sheets