* + Html and * html are unique tags of IE, which are not supported by firefox at the moment. * + html is also unique to IE7. Therefore, to solve the compatibility problem of padding, we need to rely on the labels mentioned above.
Taking sccas-site as an example, the left-side navigation bar produces ie6, ie7, and ff browser incompatibility on padding. The modification code is as follows:
# Menu7 li {
Height: 25px;
/* Border-right: 1px solid #666666 ;*/
Text-decoration: none;
Margin: 0px 0px 0px-40px! Important; (firefox can recognize and make the overall position of the navigation bar the same as that in ie)
Margin: 0px 0px 0px 0px;
}
# Menu7 li a: link {/* Identify the css of this link in firefox */
Float: none;
Color: #000;
Display: block;
Font-weight: bold;
Background-color: # CCCCCC;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 20px;
}
* Html # menu7 li a: link {/* Identify css of this link in ie6 */
Float: none;
Color: #000;
Display: block;
Font-weight: bold;
Background-color: # CCCCCC;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 10px;
}
* + Html # menu7 li a: link {/* Identify css of this link in ie7 */
Float: none;
Color: #000;
Display: block;
Font-weight: bold;
Background-color: # CCCCCC;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 60px;
}
# Menu7 li a: visited {
Color: #000;
Display: block;
Font-weight: bold;
Background-color: # CCCCCC;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 20px;
}
* Html # menu7 li a: visited {
Color: #000;
Display: block;
Font-weight: bold;
Background-color: # CCCCCC;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 10px;
}
* + Html # menu7 li a: visited {
Color: #000;
Display: block;
Font-weight: bold;
Background-color: # CCCCCC;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 60px;
}
# Menu7 li a: hover {
Color: # FF0000;
/* Text-decoration: underline ;*/
Background-color: # E6E6E6;
Font-weight: bold;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 20px;
}
* Html # menu7 li a: hover {
Color: # FF0000;
/* Text-decoration: underline ;*/
Background-color: # E6E6E6;
Font-weight: bold;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 10px;
}
* + Html # menu7 li a: hover {
Color: # FF0000;
/* Text-decoration: underline ;*/
Background-color: # E6E6E6;
Font-weight: bold;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 60px;
}
NOTE: If multiple css attributes are tied together, you need to add the recognition tags respectively. As follows:
# Menuleft li a: link, # menuleft li a: visited {
Float: none;
Text-align: left;
Color: #000;
Background: url (../images/arrow3.gif) no-repeat 90% 50%;
Background-color: # CFF3F6;
Padding-top: 8px;
Padding-left: 20px;
}
* Html # menuleft li a: link, * html # menuleft li a: visited {
Float: none;
Text-align: left;
Color: #000;
Background: url (../images/arrow3.gif) no-repeat 90% 50%;
Background-color: # CFF3F6;
Padding-top: 8px;
Padding-left: 10px;
}
* + Html # menuleft li a: link, * + html # menuleft li a: visited {
Float: none;
Text-align: left;
Color: #000;
Background: url (../images/arrow3.gif) no-repeat 90% 50%;
Background-color: # CFF3F6;
Padding-top: 8px;
Padding-left: 50px;
}
Note: Adding * and * + inside the attribute does not work. The following error occurs:
# Menu7 li a: visited {
Color: #000;
Display: block;
Font-weight: bold;
Background-color: # CCCCCC;
Border-top: 1px solid # fff;
/* Border-left: 1px solid #333333;
Border-bottom: 1px solid #333;
Border-right: 1px solid #333 ;*/
Padding: 8px 0 0 20px;
* Padding: 8px 0 0 10px;
* + Padding: 8px 0 0 60px;
}
The following are some tips:
I. CSS HACK
The following two methods can solve almost all today's HACK.
1 ,! Important
With IE7! Important Support ,! The important method is only for the HACK of IE6. (note the writing method. Remember to advance the declaration position .)
<Style>
# Wrapper
{
Width: 100px! Important;/* IE7 + FF */
Width: 80px;/* IE6 */
}
</Style>
2, IE6/IE7 for FireFox
* + Html and * html are unique tags of IE, which are not supported by firefox at the moment. * + html is also a unique tag of IE7.
<Style>
# Wrapper
{
# Wrapper {width: 120px;}/* FireFox */
* Html # wrapper {width: 80px;}/* ie6 fixed */
* + Html # wrapper {width: 60px;}/* ie7 fixed, pay attention to the Order */
}
</Style>
Note: * + html must ensure that the following statements are made at the top of the HTML header for IE7 HACK:
<! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd">
2. Universal float closure (very important !)
For details about the principle of clear float, refer To [How To Clear Floats Without Structural Markup]
Add the following code to Global CSS and add class = "clearfix" to the div to be closed.
<Style>
/* Clear Fix */
. Clearfix: after
{
Content :".";
Display: block;
Height: 0;
Clear: both;
Visibility: hidden;
}
. Clearfix
{
Display: inline-block;
}
/* Hide from IE Mac */
. Clearfix {display: block ;}
/* End hide from IE Mac */
/* End of clearfix */
</Style>
Iii. Other compatibility skills)
1. Setting padding for div under FF will increase the width and height, but IE will not. (available! Important solution)
2. center problem.
1). vertical center. Set line-height to the same height of the current div, and then use vertical-align: middle. (Note that do not wrap the content .)
2). horizontal center. margin: 0 auto; (of course not omnipotent)
3. To add a style to the content of tag a, set display: block)
4. The difference between FF and IE in understanding BOX leads to the 2px difference. There are also issues such as div set to float and margin doubling under ie.
5. ul labels are listed-style and padding by default under FF. It is recommended to declare them in advance to avoid unnecessary troubles. (commonly seen in navigation labels and content lists)
6. Do not set the height of the external wrapper div. It is best to add overflow: hidden to achieve highly adaptive.
7. about hand-shaped cursor. cursor: pointer. And hand only applies to IE.
1. css style for firefox ie6 ie7
Most of them are used now! Important comes to hack. It can be displayed normally for ie6 and firefox tests,
But ie7! Important can be correctly explained, and the page will not be displayed as required! Find a needle
The good hack Method for IE7 is to use "* + html". Now you can use IE7 to browse it. It should be okay.
You can write a CSS file as follows:
#1 {color: #333;}/* Moz */
* Html #1 {color: #666;}/* IE6 */
* + Html #1 {color: #999;}/* IE7 */
The font color in firefox is displayed as #333, the font color in IE6 is displayed as #666, And the font color in IE7 is displayed as #999.
2. center problem in css layout
The main style definition is as follows:
Body {TEXT-ALIGN: center ;}
# Center {MARGIN-RIGHT: auto; MARGIN-LEFT: auto ;}
Note:
First, define TEXT-ALIGN: center in the parent element. This means that the content in the parent element is centered. for IE, this setting is enough.
However, it cannot be centered in mozilla. The solution is to add "MARGIN-RIGHT: auto; MARGIN-LEFT: auto;" when the sub-element is defined ;"
It should be noted that, if you want to use this method to center the entire page, it is recommended that you do not set it in one DIV. You can split multiple divs in sequence,
You only need to define MARGIN-RIGHT: auto; MARGIN-LEFT: auto; in each split div.
3. Different explanations for the box model.
# Box {width: 600px; // for ie6.0-w \ idth: 500px; // for ff + ie6.0}
# Box {width: 600px! Important // for ff width: 600px; // for ff + ie6.0 width/**/: 500px; // for ie6.0 -}
4. Double distance of floating ie
# Box {float: left; width: 100px; margin: 0 0 0 100px; // in this case, IE will generate a PX distance display: inline; // ignore floating}
Here, let's take a closer look at the block and inline elements. The characteristics of the Block elements are that they can always start on a new line, and the height, width, row height, and margins can be controlled (block elements ); the features of the Inline element are as follows: On the same line as other elements ,... uncontrollable (embedded element );
# Box {display: block; // The embedded element can be simulated as the block element display: inline; // the result of the same row arrangement is dilay: table;
5 questions about IE and width and height
IE does not recognize the min-definition, but in fact it treats normal width and height as min conditions. In this case, the problem is big. If only the width and height are used,
In a normal browser, these two values will not change. If only min-width and min-height are used, the width and height under IE are not set at all.
For example, to set a background image, the width is important. To solve this problem, you can:
# Box {width: 80px; height: 35px;} html> body # box {width: auto; height: auto; min-width: 80px; min-height: 35px ;}
6. Minimum page width
Min-width is a very convenient CSS command, which can specify that the element is at least or less than a certain width, so as to ensure correct layout. But IE does not recognize this,
In fact, it uses width as the minimum width. To enable this command to be used on IE, you can place <div> under the <body> label and specify a class for div:
Then CSS is designed like this:
# Container {min-width: 600px; width: expression (document. body. clientWidth <600? "600px": "auto ");}
The first min-width is normal, but the width of line 2nd uses Javascript, which is recognized only by IE, which will make your HTML document not formal. It actually achieves the minimum width through Javascript judgment.
7. Clear floating
. Hackbox {display: table; // display the object as a block element-Level table} Or. hackbox {clear: both ;}
Or add: after (pseudo object) to set the content after the object, which is usually used with content. IE does not support this pseudo object, not supported by Ie browsers,
So it does not affect IE/WIN browsers. This is the most troublesome ...... # box: after {content: "."; display: block; height: 0; clear: both; visibility: hidden ;}
8 DIV floating IE text produces 3 pixel bug
The left object floats, and the left margin of the outer patch is used to locate the patch on the right. The text in the right object is 3 px away from the left.
# Box {float: left; width: 800px; }# left {float: left; width: 50% ;}# right {width: 50% ;} * html # left {margin-right:-3px; // This sentence is critical}
HTML code <div id = "box"> <div id = "left"> </div> <div id = "right"> </div>
9 attribute selector (this is incompatible and is a bug in hiding css)
P [id] {} div [id] {}
This is hidden for versions earlier than IE6.0 and IE6.0. It is used by FF and OPera.
There is a difference between the property selector and the Child selector. The range of the Child selector is reduced in the form, and the range of the property selector is relatively large, such as in p [id, all p tags have IDs in the same style.
10 Internet Explorer
When the div application is complicated, there are some links in each column. When the DIV application is complicated, it is prone to the "hide and seek" issue.
Some content cannot be displayed. When you select this area, the content is displayed on the page.
Solution: Use the line-height attribute for # layout or use fixed height and width for # layout. The page structure should be as simple as possible.
11 highly unsuitable
The height mismatch means that the height of the outer layer cannot be automatically adjusted when the height of the inner layer object changes, especially when the inner layer object uses
Margin or paddign.
Example:
<Div id = "box">
<P> content in the p object </p>
</Div>
CSS: # box {background-color: # eee ;}
# Box p {margin-top: 20px; margin-bottom: 20px; text-align: center ;}
Solution: Add two empty div objects to the upper and lower sides of the P object. CSS code:. 1 {height: 0px; overflow: hidden;} or add the border attribute to the DIV.