The compatibility of CSS with browsers sometimes gives people a headache. Perhaps when you understand the techniques and principles, it will not be difficult. I have collected the compatibility tips for IE7, 6 and Fireofx from the Internet and sorted them out. For the transition to web2.0, please try to write code in xhtml format, and DOCTYPE affects CSS processing. As a W3C standard, a DOCTYPE statement must be added.
CSS tips
1.Vertical centering 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 and it will be vertically centered. The disadvantage is that you need to control the content and not wrap it in another line.
2. The problem of doubling margin
The margin set for a div set to float will be doubled under IE. This is a bug that exists in ie6. The solution is to add display:inline; inside this div.
For example:
<#div id=”imfloat”>
The corresponding css is
#imfloat{
float:left;
margin:5px;/*Under IE, it is understood as 10px*/
display:inline;/*Under IE, it will be understood as 5px*/}
3. Double distance generated by floating ie
#box{ float:left; width:100px; margin:0 0 0 100px; //In this case, IE will generate a distance of 200px display:inline; //Ignore the float}
Let’s talk about the two elements block and inline in detail: The characteristic of the block element is that it always starts on a new line, and the height, width, line height, and margins can all be controlled (block element); the characteristic of the inline element is that, and other The elements are on the same line and cannot be controlled (inline elements);
#box{ display:block; //You can simulate inline elements as block elements display:inline; //Achieve the effect of arranging in the same row diplay:table;
4 IE problems with width and height
IE does not recognize the definition of min-, but in fact it treats normal width and height as if there is a min. This is a big problem. If you only use width and height, these two values will not change in a normal browser. If you only use min-width and min-height, the width and height are not set at all under IE.
For example, if you want to set a background image, this width is more important. To solve this problem, you can do this:
#box{ width: 80px; height: 35px;}html>body #box{ width: auto; height: auto; min-width: 80px; min-height: 35px;}
5. Minimum width of page
min-width is a very convenient CSS command. It can specify that the minimum width of an element cannot be smaller than a certain width, so that the layout can always be correct. But IE doesn't recognize this, and it actually treats width as the minimum width. In order to make this command also available on IE, you can put a <div> under the <body> tag, then specify a class for the div, and then design the CSS like this:
#container{ min-width: 600px; width:expression(document.body.clientWidth < 600? "600px": "auto" );}
The first min-width is normal; but the width in the second line uses Javascript, which is only recognized by IE, which will also make your HTML document less formal. It actually implements the minimum width through Javascript judgment.