CSS Hack compatibility, normal display of all browsers

Source: Internet
Author: User

CSS has a high value for the compatibility of browsers. In general, there is a great difference between IE and Firefox. Here we will introduce the compatibility points.

FAQs:

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

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 text, vertical center. The disadvantage is that you need to control the content instead of 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 mozilla 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.
Under IE5
Div {width: 300px; margin: 0 10px 0 10px ;}
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 make the following changes:
Div {width: 300px! 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, while in IE, only margin has a value, so we first define
Ul {margin: 0; padding: 0 ;}
Most problems can be solved.

Note:

1. The div of float must be closed.

Example: (floatA and floatB attributes have been set to float: left ;)

<# Div id = "floatA"> </# div>
<# Div id = "floatB"> </# div>
<# Div id = "NOTfloatC"> </# div>
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>
<# Div class = "NOTfloatC"> </# div>
Add

<# Div class = "clear"> </# div>
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"> </# div>
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

CSS Hack compatibility, so that your webpage can be normally displayed in IE5, IE5.5, IE6, IE7, Firefox, Opera, Safari

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.