Collation of CSS compatibility issues between IE and Firefox

Source: Internet
Author: User
Document directory
  • FAQ 1:
  • FAQ 2:
  • Note:
  • Others:
FAQ 1:

1. doctype affects CSS Processing
2. FF: When Div sets margin-left and margin-Right to auto, it is already centered, and IE does not work.
3. FF: when setting text-align for the body, set margin: auto (mainly margin-left, margin-Right) for the DIV to be centered.
4. FF: After padding is set, the DIV will increase the height and width, but IE will not, so you need to use it! Set one more height and width for important.
5. FF: supported! Important, ie is ignored, available! Important sets a special style for ff. It is worth noting that you must set XXXX! The important sentence is placed on the other sentence.
6. Vertical center problem of Div: vertical-align: middle; Increase the line spacing to the same height as the entire Div line-Height: 200px; then insert the text to the vertical center. The disadvantage is that you need to control the content rather than line feed.
7. cursor: pointer can display the cursor finger in IE ff at the same time. Hand can only be IE
8. FF: adds a border and a background color to the link. You must set display: block and float: left to avoid line breaks. Refer to menubar to set the height of a and menubar to avoid misplacement of the bottom side. If no height is set, you can insert a space in menubar.
9. The box model interpretation in Firefox and IE is inconsistent, resulting in a 2px difference. Solution: div {margin: 30px! Important; margin: 28px ;}
Note that the order of the two margin entries must not be reversed. According to Alibaba Cloud! The important attribute ie cannot be identified, but other browsers can. So in IE, it is actually explained as follows: div {maring: 30px; margin: 28px}
If the definition is repeated, execute the last statement. Therefore, you cannot write only margin: xxpx! Important;

10. The box interpretations of ie5 and IE6 are inconsistent.
Div {width: 300px; margin: 0 10px 0 10px;} under ie5 ;}
The DIV width is interpreted as 300px-10px (right fill)-10px (left fill). The final Div width is 280px, in IE6 and other browsers, the width is calculated based on 300px + 10px (right fill) + 10px (left fill) = 320px. In this case, we can modify Div {width: 300px as follows! Important; width/**/: 340px; margin: 0 10px 0 10px}
I don't quite understand what/**/is. I only know that both ie5 and Firefox support it, but IE6 does not. If anyone understands it, please let me know. Thank you! :)

11. UL labels have padding values by default in Mozilla, and only margin has a value in IE. Therefore, defining ul {margin: 0; padding: 0 ;} first can solve most of the problems.

FAQ 2:

The notorious bug of IE box-model exists in every previous version of IE6/win. This bug was not released until tantak released the most widely spread hack.

Http://www.tantek.com/CSS/Examples/boxmodelhack.html

Ie5.x/win parses box-model in the same way. They think width includes border and padding. Fortunately, this has improved in IE6.
However, IE6 is backward compatible with previous errors. In fact, IE6 has two cores, and he still shows tolerance for errors before the old pages, IE6 can accept the correct box-model only when the doctype statement is strictly added to the document.
Therefore, the hack of tantak must be included in the document with the correct doctype to work properly.

Div. Content {
Width: 400px; // This is the incorrect width, which is read by all browsers.
Voice-family: "\"} \ "; // ie5.x/win ignores the content after "\ "} \"
Voice-family: Inherit;
Width: 300px; // Some browsers including IE6/win read this sentence. The new value (300px) overwrites the old one.
}
HTML> body. Content {// html> body is written in css2.
Width: 300px; // the browser that supports css2 is lucky enough to read this sentence.
}

Now back to the topic, we often see it! Important and (Space)/**/: used together. What are the mysteries of this writing?

Let's look at the writing method. Here I can provide another writing method to achieve this effect.

Div. Content {
Width: 300px! Important; // This is the correct width, most of which are supported! The browser marked with important uses the value here
Width (Space)/**/: 400px; // IE6/win does not parse this sentence, so IE6/win still thinks that the width value is 300px; when ie5.x/win reads this sentence, the new value (400px) overwrites the old one because! Important flag does not work for them
}
HTML> body. Content {// html> body is written in css2.
Width: 300px; // the browser that supports css2 is lucky enough to read this sentence.
}

Similarly, this method can work normally only after the correct document type declaration, as mentioned earlier.

The document type declaration is like a switch that enables the future of backward compatibility. If it is used incorrectly, It is a Pandora Box

Note:

1. The DIV of float must be closed.

Example: (floata and floatb attributes have been set to float: Left ;)

<# Div id = "floata">
<# Div id = "floatb">
<# Div id = "notfloatc">

The notfloatc here does not want to continue translation, but wants to move down.
This code has no problem in IE, and the problem lies in ff. The reason is that notfloatc is not a float label and must be closed.
In

<# Div class = "floatb">
<# Div class = "notfloatc">

Add

<# Div class = "clear">

This Div must pay attention to the declaration position. It must be placed in the most appropriate place and must be at the same level as two DIV with the float attribute. No nested relationship exists between them; otherwise, an exception may occur.
And define the clear style as follows:

. Clear {
Clear: Both ;}

In addition, in order to automatically adapt to the height, overflow: hidden should be added to the wrapper;
When a box containing float is automatically adapted to the IE environment, the private attribute layout of IE should be triggered (the Internet Explorer !) Zoom: 1; can be used to achieve compatibility.
For example, a wrapper is defined as follows:

. Colwrapper {
Overflow: hidden;
Zoom: 1;
Margin: 5px auto ;}

2. The problem of doubling margin.

The DIV set to float doubles the margin set in IE. This is a bug in IE6.
The solution is to add the display: inline In the div;
For example:

<# Div id = "imfloat">

The corresponding CSS is

# Iamfloat {
Float: left;
Margin: 5px;/* 10 Px in IE */
Display: inline;/* in IE, It is understood as 5px */}

3. Container inclusion relationships

In many cases, especially when the container has a parallel layout, such as two or three float Divs, the width is prone to problems. In ie, the width of the outer layer is broken by the DIV with a wider inner layer. You must use Photoshop or firework to obtain pixel-level precision.

4. Questions about height

If the content is added dynamically, it is best not to define the height. The browser can automatically scale. However, it is best to set the height of static content. (It seems that sometimes it will not be automatically pushed down and I don't know what's going on)

5. the most cruel means -! Important;

If there is no way to solve some detailed problems, you can use this method. FF "! Important will automatically give priority to resolution, but IE will ignore it.

. Tabd1 {
Background: URL (/RES/images/up/tab1.gif) No-repeat 0px 0px! Important;/* style for FF */
Background: URL (/RES/images/up/tab1.gif) No-repeat 1px 0px;/* style for IE */}

It is worth noting that XXXX must be added! Important is placed on the other sentence, which has been mentioned above.

Others:

Note: IE can recognize *. standard browsers (such as Firefox, opera, and Netscape) cannot recognize *. IE6 can recognize *, but cannot recognize! Important and IE7 can recognize * and also! Important; FF cannot recognize *, but can recognize it! Important;

Write two lines of code to control a property. The difference between Firefox and IE6 is:
Background: orange; * Background: blue;

// When you use Firefox or another non-IE browser when writing this code, you will find that the background of the region where the code is written is orange. If you use IE browser, it is blue, because IE can recognize *; standard browsers (such as Firefox, opera, and Netscape) cannot recognize *;

Write two lines of code to control an attribute, which distinguishes IE7 from IE6:
Background: Green! Important; Background: blue;

// When this code is written, you can use IE7 to browse and find that the background of the region where the code is written is green. If you use IE6 to browse, it is blue, this is because IE7 can recognize it! Important *. Once it is recognized, it will be executed. The following sentence is ignored, but IE6 cannot be recognized! Important, so the previous part is skipped and the second half is executed directly.

Write two lines of code to control a property. The difference between Firefox and IE is:
Background: orange; * Background: green;

// When this code is written, you can use Firefox to browse and find that the background is orange, While IE is green. It is very simple because Firefox cannot recognize *, while IE6, both IE7 can recognize *

Write three lines of code to control a property, which distinguishes Firefox, IE7, and IE6:
Background: orange; * Background: Green! Important; * Background: blue;

// This sentence will make the background in Firefox orange, green in IE7, and blue in IE6. The principle is the same as the previous one. Firefox cannot recognize *, so neither of the following two sentences will be executed, execute the first sentence directly. IE7 can also execute the first line of code, but because the second sentence can also be identified, the second sentence of code is executed to filter out the previous results, in the last sentence, IE7 cannot be recognized. IE6 cannot be recognized! Imprtant, the first sentence of code is run, and the second sentence cannot be identified, so the last sentence is executed.

(Come to the network)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.