CSS compatibility under IE and Firefox

Source: Internet
Author: User
Tags define wrapper

1.DOCTYPE affects CSS processing

2.ff:div set Margin-left, Margin-right is already centered when auto, IE not

3.ff:body set Text-align, Div needs to set Margin:auto (mainly margin-left,margin-right) to center

4.FF: Set padding, div will increase the height and width, but IE will not, it needs to use!important more set a height and width

5.FF: Support!important, IE is ignored, can be used!important for FF special set style, it is noteworthy that the XXXX!important must be placed on the other sentence

6.div Vertical Center problem: vertical-align:middle; Increase line spacing to be as high as the entire Div line-height:200px; Then insert the text and center it vertically. The disadvantage is to control the content do not change lines

7.cursor:pointer can display cursor finger-like in IE FF at the same time, hand only IE can

8.FF: Links with border and background color, you need to set the Display:block, and set the Float:left guarantee do not change lines. Refer to MenuBar, to set a and menubar height is to avoid the bottom of the display dislocation, if not set height, you can insert a space in the menubar.

9. In Mozilla Firefox and IE, the box model explains inconsistencies resulting in a difference of 2PX resolution: div{margin:30px!important;margin:28px}

Note that the order of these two margin must not be written in reverse, according to the Czech Republic!important This attribute IE is not recognized, but other browsers can identify. So in the case of IE, the explanation is as follows: div{maring:30px;margin:28px}

Repeat the definition according to the last one to execute, so can not only write margin:xxpx!important;

10.ie5 and IE6 's box explanations are inconsistent.

IE5 under div{width:300px;margin:0 10px 0 10px;}

The width of the div is interpreted as 300px-10px (right padding) -10px (left padding) The final div has a width of 280px, while the width on IE6 and other browsers is calculated with 300px+10px (right padding) +10px (left padding) =320px. At this point we can do the following modification Div{width:300px!important;width/**/:340px;margin:0 10px 0 10px}

About this/**/is what I also do not understand, only know IE5 and Firefox support but IE6 not support, if someone understand, please tell me, thanks! :)

11.UL tags in mozilla default is padding value, and in IE only margin have a value, so first define ul{margin:0;padding:0;}

We can solve most of the problems.

Precautions:

1, float the div must be closed.

For example: (where the Floata, FLOATB properties have been set to Float:left;) < #div id= "Floata" >

< #div id= "FLOATB" >

< #div id= "NOTFLOATC" >

The NOTFLOATC here do not want to continue to translate, but want to row down.

This code has no problem with IE, the problem is ff. The reason is that NOTFLOATC is not a float label and the float label must be closed.

In the < #div class= "FLOATB" >

< #div class= "NOTFLOATC" >

Plus < #div class= "clear" >

This div must pay attention to the declaration location, must be placed in the most appropriate place, and must be with two of the float property of the div sibling, there can be no nested relationship, or you will produce an exception.

and define clear this style as follows:. clear{

Clear:both;}

In addition, in order to allow the height to automatically adapt, to wrapper inside add Overflow:hidden;

When the box contains float, the height of automatic adaptation in IE invalid, this time should trigger IE layout private properties (Evil ie Ah!). Can be done with zoom:1, so that compatibility is achieved.

For example, a wrapper is defined as follows:. colwrapper{

Overflow:hidden;

Zoom:1;

margin:5px Auto;}

2, margin double the problem.

Div set to float will double the margin set under IE. This is a bug that IE6 all exist.

The solution is to add display:inline to the div;

For example:

< #div id= "Imfloat" >

The corresponding CSS is

#IamFloat {

Float:left;

Margin:5px;/*ie under the understanding of 10px*/

Display:inline;/*ie to be understood as 5px*/}

3, on the inclusion of the relationship between the container

Many times, especially when there are parallel layouts in the container, such as three float Div, the width is easily problematic. In IE, the width of the outer layer is broken by a wider div inside. Be sure to use Photoshop or firework to measure pixel-level precision.

4, about the height of the problem

If you are adding content dynamically, it is best not to define the height. The browser can scale automatically, however, if it is static content, the height is best set. (Sometimes it doesn't seem to go down automatically, don't know exactly what's going on)

5, the most ruthless means-!important;

If there is no way to solve some of the details, you can use this method. FF will automatically give priority to "!important", while 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 the XXXX!important must be placed above another sentence, which has been mentioned above.

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.