Common browser compatibility issues and solutions (bottom)

Source: Internet
Author: User

Body Loading problem
Problem Description: The body object of Firefox exists before the body tag is fully read by the browser, while the body object of IE must exist after the body tag is fully read into the browser.
[note] This issue has not been verified and will be modified after verification.
[note] proven, IE6, Opera9, and FireFox2 do not have the above problem, the simple JS script can access all the objects and elements that have been loaded before the script, even if this element has not been loaded complete.
14. Event Delegation Method
Problem description: Under IE, use document.body.onload = inject; where function inject () has been implemented before, in Firefox, using document.body.onload = inject ();
Workaround: Use document.body.onload=new Function uniformly (' inject () '); or document.body.onload = function () {/* Here is the code */}
Note The difference between function and function.
Table Operation Issues
Problem description: IE, Firefox and other browsers for the table label operation is different, in IE does not allow the table and TR innerHTML assignment, using JS to add a TR, using the AppendChild method is not used.
WORKAROUND://Append a blank line to the table:
var row = Otable.insertrow ( -1); var cell = document.createelement ("TD"); cell.innerhtml = ""; cell.classname = "XXXX"; Row.appendchild (cell); [note] Since I rarely use JS direct operation of the table, this problem has not been met. It is recommended to use the JS frameset to manipulate table, such as jquery.
16. Object width and Height assignment problem
Problem Description: A statement similar to obj.style.height = Imgobj.height in Firefox is invalid.
? Css
1. Cursor:hand VS Cursor:pointer
Firefox does not support hand, but IE supports pointer
Workaround: Use pointer uniformly
2. innertext works in IE, but not in Firefox.
Need textcontent.
Workaround:
if (Navigator.appName.indexOf ("explorer") >-1) {
document.getElementById (' element '). InnerText = "my text";
} else{
document.getElementById (' element '). Textcontent = "my text";
}
3. CSS Transparency
IE:filter:progid:DXImageTransform.Microsoft.Alpha (style=0,opacity=60).
ff:opacity:0.6.
4. Width and padding in CSS
Width widths in IE7 and FF do not include padding, and padding are included in Ie6.
5. FF and IE box model interpretation inconsistent resulting in a difference of 2px
Box.style{width:100;border 1px;}
ie understood as Box.width = 100
FF understood as Box.width = 100 + 1*2 = 102//plus Border 2px
Workaround: div{margin:30px!important;margin:28px;}
Note that the order of the two margin must not be written counter, IE does not recognize!important this attribute, but other browsers can be recognized. So under IE actually explains this: div{maring:30px;margin:28px}
Repeat definition is executed according to the last one, so it is not possible to write only margin:xxpx!important;
6. 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 width is 280px, and the width on IE6 and other browsers is calculated as 300px+10px (right padding) +10px (left padding) =320px. At this point we can make the following changes Div{width:300px!important;width/**/:340px;margin:0 10px 0 10px}
7. UL and OL list indent issues
Eliminate the UL, OL and other list of indentation, the style should be written as: list-style:none;margin:0px;padding:0px;
It is verified that in IE, setting margin:0px can remove the upper and lower left and right indent, blank and list number or dot of list, setting padding has no effect on style; in Firefox, setting margin:0px can only remove upper and lower whitespace, set padding:0 Only the left and right indents can be removed after PX, and List-style:none must be set to remove the list number or dot. In other words, in IE, only set margin:0px can achieve the final effect, and in Firefox must be set margin:0px, padding:0px and list-style:none three items to achieve the final effect.
8. Element horizontal Centering Problem
ff:margin:0 Auto;
IE: Parent {text-align:center;}
9. Vertical center of DIV problem
Vertical-align:middle; Increase the line spacing as high as the whole div: line-height:200px; Then insert the text and center it vertically. The disadvantage is to control the content not to wrap.
The question of doubling the margin
A div set to float doubles the margin set under IE. This is a bug that exists in a IE6. The solution is to add display:inline to this div;
For example:
<div id= "Imfloat" >
The corresponding CSS is
#imfloat {
Float:left;
Margin:5px;/*ie understood as 10px*/
Display:inline;/*ie under the 5px*/}
A. ie with width and height issues
IE does not recognize the definition of min-, but in fact it treats the normal width and height as a condition of min. This problem is big, if only with the width and height, the normal browser of these two values will not change, if only with Min-width and min-height, ie, the following is not set width and height.
For example, to set the background image, this width is more important. To solve this problem, you can:
#box {width:80px; height:35px;} Html>body #box {width:auto; height:auto; min-width:80px; min-height:35px;}
12. Minimum width of the page
As the previous problem, IE does not recognize min, to achieve the minimum width, the following methods can be used:
#container {min-width:600px; Width:expression (document.body.clientWidth 600?) "600px": "Auto");}
The first min-width is normal, but the width of line 2nd uses JavaScript, which only IE recognizes, which also makes your HTML document less formal. It actually achieves the minimum width by JavaScript's judgment.
Div floating IE text generates 3 pixel bug
The left object floats, the right side is positioned with the left margin of the outer patch, and the text within the right object is spaced 3px away 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}
<div id= "box" >
<div id= "left" ></div>
<div id= "right" ></div>
</div>
The problem of IE hide and seek
When the div application is complex, there are some links in each column, and the div is prone to hide-and-seek problems.
Some content does not show up when the mouse selects this area is found content is indeed on the page.
WORKAROUND: Use Line-height attribute for #layout or use fixed height and width for #layout. The page structure is as simple as possible.
The div closure of the. float; clear float; Adaptive height
① Example: <div id= "Floata" ><div id= "FLOATB" ><div id= "NOTFLOATC" >
The NOTFLOATC here do not want to continue panning, but want to go down the line. (where the properties of Floata and FLOATB have been set to float:left;)
This code is no problem in IE, the problem is in FF. The reason is that NOTFLOATC is not a float label and the float label must be closed. In <div class= "FLOATB" > <div class= "NOTFLOATC" > Plus <div class= "clear" > this div must be aware of the location, and it has to be in the same class as two div with the float attribute, There cannot be a nested relationship between the two, otherwise an exception is generated. And the clear style is defined as follows:. clear{Clear:both;}
② as an external wrapper div do not set dead height, in order to allow the height of self-adaptation, to wrapper inside add Overflow:hidden; When the box containing float, the height of adaptive under IE invalid, this time should trigger the layout of IE private property (evil ie Ah!). ) with zoom:1, can be done, so that the compatibility is achieved.
For example a certain wrapper is defined as follows:
. colwrapper{Overflow:hidden; zoom:1; margin:5px Auto;}
③ for typography, the CSS description we use most probably is float:left. Sometimes we need to do a uniform background behind the float div in the n column, for example:
<div id= "Page" >
<div id= "left" ></div>
<div id= "center" ></div>
<div id= "right" ></div>
</div>
For example, we want to set the background of the page to blue, so that the background color of all three columns is blue, but we will find that as the left center of right is stretched downward, and the page actually saves the height unchanged, the problem is because the page is not a float property, And our page is to be centered, cannot be set to float, so we should solve this:
<div id= "Page" >
<div id= "bg" style= "float:left;width:100%" >
<div id= "left" ></div>
<div id= "center" ></div>
<div id= "right" ></div>
</div>
</div>
Then embed a float left and the width is 100% div resolved.
④ Universal float closed (very important!)
The principle of clear float can be found in [how to clear floats without Structural Markup], add the following code to the global CSS, the need to close the div plus class= "clearfix", repeated Try to be uncomfortable.
/* 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 */
Alternatively, set:. hackbox{display:table;//Display the object as a block-element-level table}
16. Highly non-adaptable
Height intolerance is when the height of the inner object changes, the outer height cannot be automatically adjusted, especially when the inner object uses margin or padding.
Cases:
#box {}
#box p {margin-top:20px;margin-bottom:20px; text-align:center;}
<div id= "box" >
The contents of the <p>p object </p>
</div>
Workaround: Add 2 empty div object CSS code {Height:0px;overflow:hidden;} to the P object. Or add the border attribute to the Div.
There are voids in the IE6 film.
There are many tricks to fix this bug, either to change the layout of the HTML, or to set the IMG to Display:block or set the Vertical-align property to vertical-align:top/bottom/middle/ Text-bottom can all be solved.
18. Text Input Box
Plus vertical-align:middle;
<style type= "Text/css" >
<!--
Input {
width:200px;
height:30px;
border:1px solid red;
Vertical-align:middle;
}
-
</style>
Verified that the next version of IE is not applicable, and FF, Opera, Safari, Chrome are all ok!
When content in Li exceeds length, it is displayed as an ellipsis
This technique works with IE, Opera, Safari, Chrom Browser, FF temporarily not supported.
<style type= "Text/css" >
<!--
Li {
width:200px;
White-space:nowrap;
Text-overflow:ellipsis;
-o-text-overflow:ellipsis;
Overflow:hidden;
}
-
</style>
20. Why IE Cannot set scroll bar color in Web Standard
The solution is to replace body with HTML
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 strict//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<style type= "Text/css" >
<!--
HTML {
Scrollbar-face-color: #f6f6f6;
Scrollbar-highlight-color: #fff;
Scrollbar-shadow-color: #eeeeee;
Scrollbar-3dlight-color: #eeeeee;
Scrollbar-arrow-color: #000;
Scrollbar-track-color: #fff;
Scrollbar-darkshadow-color: #fff;
}
-
</style>
21. Why can't I define a container with around 1px height?
IE6 This problem is due to the default row height, there are a number of techniques to solve:
Example: Overflow:hidden zoom:0.08 line-height:1px
16. How can I make the layer appear above flash?
The workaround is to set the flash to transparent
<param name= "wmode" value= "Transparent"/>
22. Link (A-label) border and background
A link with border and background color, need to set Display:block, and set Float:left guarantee not wrap. Refer to MenuBar, 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.
23. Hover style does not appear after hyperlink access
The clicked Hyperlink style is not hover and active, many people should have encountered this problem, the solution is to change the order of CSS properties: l-v-h-a
Code:
<style type= "Text/css" >
<!--
A:link {}
a:visited {}
a:hover {}
a:active {}
-[Color=green][/color]
</style>
Form label
This tag in IE, will automatically margin some margins, and in the FF margin is 0, so if you want to show consistency, so it is best to specify the margin and padding in the CSS, for the above two issues, my CSS is generally used first in the style Ul,form {margin:0;padding:0;}.
25. Attribute selector (this is not compatible, is a bug to hide CSS)
p[id]{}div[id]{}
This is hidden for IE6.0 and IE6.0 versions, FF and opera. There is a difference between the property selector and the child selector, the range of the sub-selector is reduced in form, the range of the property selector is larger, such as P[id], and all P tags have the same type of ID.
26. Why the text in FF cannot open the height of the container
The container of fixed height value in standard browser is not open like IE6, then I want to fixed height, and want to be able to be open how to set it? The way is to remove height setting min-height:200px; Here in order to take care of the IE6 do not know min-height can be defined as:
{
Height:auto!important;
height:200px;
min-height:200px;
}

Common browser compatibility issues and solutions (bottom)

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.