Home  >  Article  >  Web Front-end  >  CSS browser compatibility issues set

CSS browser compatibility issues set

巴扎黑
巴扎黑Original
2017-04-05 10:39:271024browse

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 methods of 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, DOCTYPE must be added.

CSS Tips

1.p vertical centering problem

vertical-align:middle; Increase the line spacing to the same height as the entire p line-height:200px; Then insert the text and it will be vertically centered. The disadvantage is that the content must be controlled without line breaks

2. The problem of doubling margin

If p is set to float, the margin set under IE will be doubled. This is a bug that exists in ie6. The solution is to add display:inline;
to this p For example:
<#p id=”imfloat”>
The corresponding css is
#IamFloat{
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 (embedded 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 and width and height question

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, it means that 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

under the tag, then specify a class for p, 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.

6.p Floating IE text produces a 3-pixel bug

The object on the left is floated, and the right is positioned using the left margin of the outer patch. The text within the object on the right will be spaced 3px 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}






7. IE hide-and-seek problem

When the p application is complex, there are some links in each column, and the hide-and-seek problem easily occurs at this time.​
Some content cannot be displayed. When the mouse selects this area, it is found that the content is indeed on the page. Solution: Use the line-height attribute for #layout or use fixed height and width for #layout. Keep the page structure as simple as possible.

8.float p closure; clear float; adaptive height;

①For example: <#p id=”floatA” ><#p id=”floatB” ><#p id=”NOTfloatC” >NOTfloatC here does not want to continue to translate, but wants to go down Row. (The attributes of floatA and floatB have been set to float:left;)
This code works fine in IE, the problem is in FF. The reason is that NOTfloatC is not a float label, and the float label must be closed. Add <#p class=”floatB”> <#p class=”NOTfloatC”> between There cannot be a nested relationship between p siblings with float attributes, otherwise an exception will occur. And define the clear style as follows: .clear{ clear:both;}

② As an external wrapper p, do not set a fixed height. In order to allow the height to automatically adapt, add overflow:hidden in the wrapper; when it contains a float box, automatic height adaptation is invalid under IE, and IE should be triggered at this time. The layout private attribute (the evil IE!) can be done using zoom:1;, thus achieving compatibility.
For example, a wrapper is defined as follows:
.colwrapper{ overflow:hidden; zoom:1; margin:5px auto;}

③For typesetting, the CSS description we use most is probably float:left. Sometimes we need to make a unified background behind the float p in column n, for example:






For example, we want to set the background of the page to blue so that the background color of all three columns is blue. However, we will find that as the left center right stretches downward, the page actually saves the same height. The problem arises. The reason is that page is not a float attribute, and our page cannot be set to float because it needs to be centered, so we should solve it like this








Then embed a float left and the width is 100% p to solve the problem

④Universal float closure (very important!)
For the principle of clear float, please refer to [How To Clear Floats Without Structural Markup]. Add the following code to Global CSS and add class="clearfix" to the p that needs to be closed. It has been tried and tested repeatedly.
/* 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 */
Or set it like this: .hackbox{ display:table; //Display the object as a block element-level table}

The above is the detailed content of CSS browser compatibility issues set. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn