Resolution of css browser compatibility issues
I ,! Important (limited function)
With IE7! Important Support ,! The important method is only compatible with ie6. (note the writing method. Remember that the declaration position must be in advance .)
For example:
# Example {
Width: 100px! Important;/* IE7 + FF */
Width: 200px;/* IE6 */
}
Ii. css hack method (for beginners, let's take a look at it and pass it)
The first thing you need to know is:
General height of all browsers: 100px;
IE6 dedicated _ height: 100px;
IE7 dedicated * + height: 100px;
IE6 and IE7 share * height: 100px;
IE7 and FF share height: 100px! Important;
For example:
# Example {height: 100px;}/* FF */
* Html # example {height: 200px;}/* IE6 */
* + Html # example {height: 300px;}/* IE7 */
The following method is relatively simple:
For example:
1. IE6-IE7 + FF
# Example {
Height: 100px;/* FF + IE7 */
_ Height: 200px;/* IE6 */
}
In fact, the first method mentioned above can also be used.
# Example {
Height: 100px! Important;/* FF + IE7 */
Height: 200px;/* IE6 */
}
2. IE6 + IE7-FF
# Example {
Height: 100px;/* FF */
* Height: 200px;/* IE6 + IE7 */
}
3. IE6 + FF-IE7
# Example {
Height: 100px;/* IE6 + FF */
* + Height: 200px;/* IE7 */
}
4. IE6 IE7 FF varies
# Example {
Height: 100px;/* FF */
_ Height: 200px;/* IE6 */
* + Height: 300px;/* IE7 */
}
Or:
# Example {
Height: 100px;/* FF */
* Height: 300px;/* IE7 */
_ Height: 200px;/* IE6 */
}
It should be noted that the order of the Code must not be reversed, or you will not be able to discard it. Because when the browser interprets the program, if the name is duplicated, it will overwrite the previous one, just like assigning a value to the variable, so we put the general purpose above, the more dedicated, the more you put the back
Explain the code 4:
When you read the code, the first line of height: 100px is common. IE6 IE7 FF shows 100px.
The second line * height: 300px; FF does not recognize this attribute, IE6 IE7 recognizes it, So FF also displays 100px, while IE6 IE7 overwrites the height attribute obtained from the first line, both display 300px
To the third row _ height: 200px; only IE6 knows, so IE6 overwrites the height obtained in the second row, and finally displays 200px
In this way, all three browsers have their own height attributes.
If you still don't understand this, either you hit the wall or I went! But it is better for you to go.
Oh, I almost forgot to say:
* + For html compatibility with IE7, the following declaration must be made on the top of HTML:
<〈! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN" "http://www.w3.org/TR/html4/loose.dtd"> "〉
3. Use IE-specific condition annotations
<〈! -- Other browsers --> --〉
<Link rel = "stylesheet" type = "text/css" href = "css.css"/> "/〉
<〈! -- [If IE 7]>
<〈! -- Suitable for IE7 --> --〉
<Link rel = "stylesheet" type = "text/css" href = "ie7.css"/> "/〉
<〈! [Endif] -->
<〈! -- [If lte IE 6]>
<〈! -- Suitable for IE6 and below --> --〉
<Link rel = "stylesheet" type = "text/css" href = "ie.css"/> "/〉
<〈! [Endif] -->
It seems that three sets of css are to be compiled. I haven't used them yet. Stick them first.
If condition Hack of IE
1. <.〈! -- [If! IE]> <! --> All except Internet Explorer can be recognized 〈! -- <--〈! [Endif] -->
2. <.〈! -- [If IE]> all IE can recognize <〈! [Endif] -->
3. <.〈! -- [If IE 5.0]> only IE5.0 can recognize <〈! [Endif] -->
4. <.〈! -- [If IE 5]> only IE5.0 and IE5.5 can recognize <〈! [Endif] -->
5. <.〈! -- [If gt IE 5.0]> both IE5.0 and IE5.0 can recognize <〈! [Endif] -->
6. <.〈! -- [If IE 6]> only IE6 can recognize <〈! [Endif] -->
7. <.〈! -- [If lt IE 6]> versions earlier than IE6 and IE6 can recognize <〈! [Endif] -->
8. <.〈! -- [If gte IE 6]> IE6 and IE6 and later versions can recognize <〈! [Endif] -->
9. <.〈! -- [If IE 7]> only IE7 can recognize <〈! [Endif] -->
10. <.〈! -- [If lt IE 7]> versions earlier than IE7 and IE7 can recognize <〈! [Endif] -->
11. <.〈! -- [If gte IE 7]> IE7 and IE7 and later versions can recognize <〈! [Endif] --> Note: gt = Great Then is greater
>=> Greater
Lt = Less Then Less
<=< Minor sign
Gte = Great Then or Equal greater than or Equal
Lte = Less Then or Equal Less than or Equal
Iv. css filter Method (translated by the author from a foreign classic website)
Create a css style as follows:
# Item {
Width: 200px;
Height: 200px;
Background: red;
}
Create a new div and use the css style defined above:
<Div> some text here </div> 〉
Add the lang attribute in the body representation. The Chinese character is zh:
<Body lang = "en"> "〉
Now define another style for the div element:
*: Lang (en) # item {
Background: green! Important;
}
This is intended for use! Important overwrites the original css style. Because the lang selector ie7.0 does not support this sentence, it does not have any effect on this sentence, so it achieves the same effect in ie6.0, unfortunately, safari does not support this attribute, so you need to add the following css style:
# Item: empty {
Background: green! Important
}
: The empty selector is a css3 specification. Although safari does not support this specification, this element is still selected, whether or not this element exists, now green will be available in browsers other than ie versions.
5. FLOAT closure (clearing float)
In some browsers, the webpage is often displayed incorrectly because float is not actually closed, which is also one reason why div cannot adapt to the height. If the parent div does not have a float and its Child div has a float, the parent div cannot enclose the entire child DIV. This usually occurs when a parent DIV contains multiple child DIV. Solution:
1. Set float to the parent DIV (Don't scold me, I know it's nonsense)
2. Add an empty DIV after all sub-DIV (not recommended, Some browsers can see the gaps generated by the empty DIV)
For example:
. Parent {width: 100px ;}
. Son1 {float: left; width: 20px ;}
. Son2 {float: left; width: 80px ;}
. Clear {clear: both; margin: 0; parding0; height: 0px; font-size: 0px ;}
<Div class = "parent"> "〉
<Div class = "son1"> </div> 〉
<Div class = "son2"> </div> 〉
<Div class = "clear"> </div> 〉
</Div> 〉
3. Universal float Closure
Add the following code to Global CSS and add class = "clearfix" to the div to be closed.
Code:
<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> 〉
: After (pseudo object), set the content after the object, 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.
4. overflow: auto (I just saw it and strongly recommended it)
You only need to add overflow: auto to the CSS of the parent DIV.
Example:
. Parent {width: 100px; overflow: auto}
. Son1 {float: left; width: 20px ;}
. Son2 {float: left; width: 80px ;}
<Div class = "parent"> "〉
<Div class = "son1"> </div> 〉
<Div class = "son2"> </div> 〉
</Div> 〉
The principle is that the peripheral elements cannot be well extended. The problem lies in overflow because overflow is invisible (see W3C explanation ). Now, you only need to add an "overflow: auto" to the peripheral element to solve the problem. The result is that Internet Explorer can be used in addition to Internet Explorer. The problem of IE will be solved. The problem is completely solved by adding "_ height: 1%.
I tried it. In fact, it does not apply "_ height: 1%" to IE. Keep it.
6. Compatibility details
1. Setting padding for div under FF will increase the width and height (the actual width of DIV = DIV width + Padding), but IE will not.
Solution: Set the IE and FF widths for the DIV, and add the IE special mark "*" before the IE width.
2. The page is centered.
Body {TEXT-ALIGN: center;} is sufficient in IE, but it fails in FF.
Solution: Add "MARGIN-RIGHT: auto; MARGIN-LEFT: auto ;"
3. Sometimes we see some strange gaps on IE6, but we have set the height clearly.
Solution: Add "font-size: 0px;" to the DIV with gaps ;"
4. about hand-shaped cursor. cursor: pointer. And hand only applies to IE.
5. Double distance produced by floating IE6
# Box {float: left;
Width: 100px;
Margin: 0 0 0 100px;
}
In this case, IE6 will generate a PX distance.
Solution: Add display: inline to 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 characteristics of the Inline element are: 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; // you can arrange the same row.
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. However, IE does not recognize the min-definition, but in fact it treats the normal width and height as min conditions. In this case, the problem is big. If only the width and height are used, the values in the normal browser 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 heavy.
Solution: to make this command usable on IE, you can put a <div> under the <body> label and specify a class for the div:
Then CSS is designed like this:
# Container {
Min-width: 600px;
Width: e-xpression (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. padding and margin of UL and FORM labels
Ul labels have padding values by default in FF, while only margin has default values in IE. In IE, the FORM label will automatically margin some margins, while in FF, the margin is 0;
Solution: first, the style ul is used in css, and form {margin: 0; padding: 0;} is defined to be dead. This will not be a headache in the future.
8. DIV floating IE text produces a 3-pixel bug
The following section is what I pasted on the Internet.
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 the key
}
HTML code
<DIV id = box> 〉
<DIV id = left> </DIV> 〉
<DIV id = right> </DIV> 〉
</DIV> 〉
For the above Code, let's talk about my understanding:
First, as long as right defines the width attribute, two lines are displayed under FF.
2. If both width values are defined as percentages, even if both width values are 100%, a row is displayed under IE. Therefore, the above saying "this sentence is the key" is useless, and it is in a row without adding it, unless you define a value in width.
So the above Code is actually not very useful, at least it won't work in FF. In fact, you only need to define the left width. If right does not define the width, It will be successful in IE or FF, in this case, the parent div box does not actually contain the LEFT and RIGHT child Divs. You can use the 5th method mentioned above to solve this problem. The simplest way is to add float: left to the RIGHT, and then OK!
9. hyphens (-)
. Hh {-o-text-overflow: ellipsis;
Text-overflow: ellipsis;
White-space:
Nowrapoverflow: hidden;
}
This part of the text will be cut off and ended with a ellipsis. Technology is a good technology, and many people like to use it indiscriminately, but note that Firefox does not support it.