Compatibility issues Summary

Source: Internet
Author: User

CSS compatibility with the browser is sometimes a headache, especially for IE6 this issue a lot of browser version, from the online collection of ie7,6 and FIREOFX compatibility processing method and organized a bit. For web2.0, please try to write the code in XHTML format, and DOCTYPE affect the CSS processing, as the standard, must add DOCTYPE declaration.

First, CSS

1, vertical-align:middle text Vertical Center, for some elements such as div{width:200px;height:200px;} No effect, just give div{line-height:200px;} You can center text vertically.

2, margin doubled the problem:

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.

<div class= "Float-left" ></div>.float-left{            float:left;            Margin:5px;/*ie understood as 10px*/            Display:inline;/*ie under the understanding of 5px*/        }

3. Double the distance generated by the floating IE

#box {float:left; width:100px; margin:0 0 0 100px; In this case, IE will produce 200px distance display:inline; Make floating Ignore}
Here's a look at block and inline two elements: The block element is characterized by always starting on new lines, height, width, row height, margin can be controlled (block elements); The inline element is characterized by an uncontrolled (inline element) on the same line as other elements;
#box {display:block;//can simulate a block element display:inline for inline elements;//Achieve the effect of the same row arrangement diplay:table;

4, ie and width and height of the problem

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:

5, the minimum width of the page

Min-width is a handy CSS command that allows you to specify that the element should be minimal or less than a certain width, so that the layout is always correct. But IE doesn't recognize this, and it actually puts width as the minimum width. In order for this command to work on IE, you can put a <div> into the <body> tab, then specify a class for the Div, and then the CSS is designed like this:

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.

6, div floating IE text generated 3 pixels of the 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 key}    <div id= "box" >   <div id= "left" ></div>   <div Id= "Right" ></div>   

7, IE hide and seek problems

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.

8, Float div closed, clear floating, adaptive height;

① such as:< #div id= "Floata" >< #div id= "FLOATB" >< #div id= "NOTFLOATC" > The NOTFLOATC here do not want to continue panning, but want to go down. (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" > Add < #div class= "clear" > this div must pay attention to the position, And there must be no nested relationship with the two Div siblings with the float attribute, otherwise an exception will occur. And the clear style is defined as follows:. clear{Clear:both;}

② as an external wrapper div do not set dead height, in order to let the height can automatically adapt to the wrapper inside add Overflow:hidden; When the box containing float, the height of automatic adaptation in 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>    

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

<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 >   

④ Universal float closed (very important!)
For the principle of clear float, see [How to clear floats without Structural Markup], add the following code to the global CSS, add class= "Clearfix" to the div that needs to be closed, Tried.

/* 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 */    

Alternatively, set:. hackbox{display:table;//Display the object as a block-element-level table}

9, height is not suitable

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= the contents of the "box" >     <p>p object </p>     </div>  

Workaround: Add 2 empty div object CSS code to the P object: P{height:0px;overflow:hidden;} Or add the border attribute to the Div.

10, IE6 under why there is a gap in the picture produced

There are many ways to fix this bug, either by changing the layout of the HTML, or by setting the IMG to Display:block or setting the Vertical-align property to Vertical-align:top | Bottom |middle |text-bottom can be solved.

11. How to align text and input boxes

input {      width:200px;      height:30px;      line-height:30px;     border:1px solid red;      Vertical-align:middle; }

12. What is the difference between the definition ID and class in the Web Standard?

A. The Web Standard is not allow duplicate ID, such as div id= "AA" is not allowed to repeat 2 times, and class is defined by the classes, theoretically can be infinitely repeated, so that the definition of multiple references can be used.

Two. Priority issues for attributes
The priority of ID is higher than class, see the example above

Three. Convenient JS and other client-side script, if you want to script an object in the page, then you can define an ID, otherwise only by traversing the page element plus specify a specific attribute to find it, this is a relatively waste of time resources, far less than a simple ID.

13, Li in the content beyond the length of the ellipsis display method

Li {      width:200px;      White-space:nowrap;      text-overflow:ellipsis;      -o-text-overflow:ellipsis;      Overflow:hidden;      }

14, the Web Standard in IE can not set the scroll bar color solution:

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;      

15, why can not define the height of the container of about 1px

IE6 This problem is due to the default row height, there are many workarounds, such as: Overflow:hidden | zoom:0.08 | line-height:1px

16, how to make a layer vertically centered in the browser

Here we use the percent absolute positioning, with the method of negative value of the outer patch, the size of the negative value to its own width height divided by two

div {      position:absolute;      top:50%;      lef:50%;      margin:-100px 0 0-100px;      width:200px;      height:200px;      border:1px solid red;      

II:FF and IE

1, Div Center problem

Div set Margin-left, margin-right for Auto is already centered, ie not, ie need to set the body center, first in the parent element definition text-algin:center; This means that the content within the parent element is centered.

2. 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.

3, after the hyperlink access hover style does not appear problems

The clicked Hyperlink style is not hover and active, many people should have encountered this problem, the workaround is to change the order of CSS properties: l-v-h-a

4. Mouse finger cursor

Cursor:pointer can display the cursor finger in IE FF at the same time, hand only IE can

5, padding and margin of UL

UL label in FF default is padding value, and in IE only margin default has value, so first define ul{margin:0;padding:0;} Will solve most of the problems.

6. 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;} The definition died, so the back will not be a headache for this.

7, Box model explanation inconsistency problem

The inconsistency of the box model in FF and IE leads to a 2px resolution: div{margin:30px!important;margin:28px; Note that the order of the two margin must not be written in reverse, important this property IE is not recognized, But other browsers can identify. So in the IE is actually interpreted as such: div{maring:30px;margin:28px} repeated definition, according to the last one to execute, so can not write only margin:xx px!important;
#box {width:600px;//for ie6.0-w\idth:500px;//for ff+ie6.0}
#box {width:600px!important//for ff width:600px;//for ff+ie6.0 width/**/:500px;//for ie6.0-}

8, attribute selector (this is not considered 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.

9, the most ruthless means-!important;

If there is no way to solve some of the details, we can use this method. FF will automatically parse for "!important", but IE will be ignored.
. 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 on the other sentence above, mentioned above.

10, Ie,ff The default value problem

Maybe you've been complaining about why you have to write different CSS specifically for IE and FF, why IE makes people headache, and then while writing CSS, while cursing that hateful m$ ie. in fact, for the standard of CSS support, IE is not as bad as we think, the key is that the default value of IE and FF is not the same, mastered this technique, you will find that compatible with FF and IE CSS is not so difficult, perhaps for the simple CSS, you can absolutely not "! Important "This thing up.
We all know that the browser in the Display page, the Web page will be based on the CSS style sheet to determine how to display, but we do not necessarily have all the elements in the stylesheet is described in detail, of course, there is no need to do so, for those not described in the property, the browser will use the built-in default way to display , such as text, if you do not specify a color in the CSS, then the browser will be in black or system color to display, div or other elements of the background, if not specified in the CSS, the browser will be set to white or transparent, and so on other undefined style. So there's a lot of things. The root cause of the difference between FF and IE is that their default display is different, and how this default style should be displayed I know there are no corresponding standards in W3, so don't blame IE for this.

11. Why the FF text 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:

12. How to make continuous long field wrap automatically under Firefox

It is well known that the use of word-wrap:break-word directly in IE, FF we use JS Insertion & #10, the method to solve

<style type= "Text/css" > <!--div {      width:300px;      Word-wrap:break-word;      border:1px solid red; --</style> <div id= "FF" > 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 </div> <scrīpt type= "text/javascrīpt" >/* <! [cdata[* * Function Tobreakword (el, Intlen) {      Varōbj=document.getelementbyid (EL);      var strcontent=obj.innerhtml;      var strtemp= "";      while (Strcontent.length>intlen) {          strtemp+=strcontent.substr (0,intlen) + "& #10;";          Strcontent=strcontent.substr (intlen,strcontent.length);      }      strtemp+= "& #10;" +strcontent;      Obj.innerhtml=strtemp; } if (document.getElementById   &&   !document.all)   tobreakword ("FF", PNS);/*]]> */</ Scrīpt>

13. Ie6/7 ...

width:50px; /*for IE7 & ie6*/width:40px;   /*for ie6*/Note the order.   This also belongs to CSS HACK, but it is not as concise as above. #example {color: #333;}/* Moz * * HTML #example {color: #666;}/* IE6 */*+html #example {color: #999;}/* I E7 */Second, is the use of IE-specific conditions comments <!--other browsers--<link rel= "stylesheet" type= "Text/css" href= "Http://handyxuefeng.blo G.163.com/blog/css.css "/> <!--[if IE 7]> <!--suitable for IE7, <link rel=" stylesheet "type=" text/css "href=" Http://handyxuefeng.blog.163.com/blog/ie7.css "/> <! [endif]--> <!--[if LTE IE 6]> <!--suitable for IE6 and <link rel= "stylesheet" type= "Text/css" href= "htt P://handyxuefeng.blog.163.com/blog/ie.css "/> <!   [endif]--> Third, CSS filter method, the following is the classic from the foreign website translation come from.        Create a new CSS style as follows: #item {width:200px;        height:200px;     background:red; Create a new div and use the style of the CSS that you defined earlier: <div id= "Item" >some text here</div> Add the Lang property to the body representation, en: <body la ng= "EN" >   Now again define a style for the DIV element: *:lang (en) #item {background:green!important; }

This is done in order to overwrite the original CSS style with!important, because: lang selector ie7.0 does not support, so this sentence will not have any effect, so also achieved the same effect ie6.0, but unfortunately, Safari also does not support this property, So you need to add the following CSS styles:
#item: Empty {
Background:green!important
}
: The empty selector is a CSS3 specification, and although Safari does not support this specification, it will still be selected, whether or not this element exists, and now the Green will now be on a browser other than IE versions

Second, JS part

Compatibility wording
Document.onclick = function (EV) {
var e = ev| | window.event;
var x = E.clientx;
var y = e.clienty;
}
var winw=document.body.clientwidth| | document.docuemntelement.clientwidth;//Web page Visible area width
var winh=document.body.clientheight| | document.docuemntelement.clientheight;//Web page Visible area width
The above is not including the width of the border height, if it is offsetwidth or offsetheight, including the border

var winww=document.body.scrollwidth| | document.docuemntelement.scrollwidth;//the width of the entire Web page
var winhh=document.body.scrollheight| | document.docuemntelement.scrollheight;//the entire page of high

var scrollheight=document.body.scrolltop| | document.docuemntelement.scrolltop;//Web page was rolled off the high
var scrollleft=document.body.scrollleft| | document.docuemntelement.scrollleft;//the distance of the left volume of the Web page

Var screenh=window.screen.height;//high Screen resolution
var screenw=window.screen.width;//width of screen resolution
var screenx=window.screenleft;//the x-coordinate of the browser window relative to the screen (except Firefox)
var Screenxx=window.screenx;//firefox relative to the x-coordinate of the screen
var screeny=window.screentop;//the y-coordinate of the browser window relative to the screen (except Firefox)
var screenyy=window.screeny;//firefox relative to the y-coordinate of the screen
Get elements by class name
Document.getelementsbyclassname (');//ie 6 7 8 not supported;

Here you can define a function to solve the compatibility problem, and of course don't mention jquery to me here ...
The first gets the class name globally, and the second gets the class name as a local
function ByClass1 (oclass) {//global fetch, Oclass is the class name you want to find, no "."
var tags=document.all?document.all:document.getelementsbytagname (' * ');
var arr=[];
for (var i = 0; i < tags.length; i++) {
var reg=new RegExp (' \\b ' +oclass+ ' \\b ', ' G ');
if (Reg.test (Tags[i].classname)) {
Arr.push (Tags[i]);
};
};
Return arr;//Note that the returned array contains all the elements of the class you passed in;
}

function ByClass2 (parentid,oclass) {//Local get class name, ParentID is the parent ID you passed in
var Parent=document.getelementbyid (ParentID);
var tags=parent.all?parent.all:parent.getelementsbytagname (' * ');
var arr=[];
for (var i = 0; i < tags.length; i++) {
var reg=new RegExp (' \\b ' +oclass+ ' \\b ', ' G ');
if (Reg.test (Tags[i].classname)) {
Arr.push (Tags[i]);
};
};
Return arr;//Note that the returned array contains all the elements of the class you passed in;
}

Setting Up Listener Events
function Addevent (OBJ,TYPE,FN) {//Add event listener, three parameters are object, event type, event handler, default = False
if (Obj.addeventlistener) {
Obj.addeventlistener (Type,fn,false);//Non IE
} else{
Obj.attachevent (' on ' +type,fn),//ie, this has been added on, please do not repeat when you pass the argument.
};
}
function Removeevent (OBJ,TYPE,FN) {//delete event listener
if (Obj.removeeventlistener) {
Obj.removeeventlistener (Type,fn,false);//Non IE
} else{
Obj.detachevent (' on ' +type,fn),//ie, this has been added on, please do not repeat when you pass the argument.
};
}

JS Block event propagation, where the click event is used as an example
Document.onclick=function (e) {
var e=e| | window.event;
if (e.stoppropagation) {
E.stoppropagation ();//W3C Standard
}else{
E.cancelbubble=true;//ie ....
}
}

JS block Default Events
Document.onclick=function (e) {
var e=e| | window.event;
if (E.preventdefault) {
E.preventdefault ();//W3C Standard
}else{
E.returnvalue= ' false ';//ie.
}
}

About target in event events
Document.onmouseover=function (e) {
var e=e| | window.event;
var target=e.target| | e.srcelement;//gets the compatible wording for target, followed by IE
var from=e.relatedtarget| | e.formelement;//Mouse to the place, the same back for IE ...
var to=e.relatedtarget| | e.toelement;//mouse to go to the place
}

Compatibility issues Summary (RPM)

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.