About CSS Browser compatibility issues

Source: Internet
Author: User

Browser compatibility issues with CSS

Today there is time, simply summed up the next CSS browser compatibility related issues, share with you ...

1. CSS in the width and the padding

In IE7 and Mozilla firefox, width widths do not include padding, and padding are included in Ie6.

2. InnerText in the IE normal operation, but in FireFox but not in the Middle. .

Need Textcontent.
Workaround :
If (navigator.appName.indexOf ("explorer") >-1) {
document.getElementById (' element '). innerText = "my text";
} else{
document.getElementById (' element '). textcontent = "my text";
}

3. CSS Transparent

IE:filter:progid:DXImageTransform.Microsoft.Alpha (style=0,opacity=60).
ff:opacity:0.6.

4. FF and the Iebox inconsistent model interpretation results in differences 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;

5. IE5 and the IE6 of the BOX Inconsistent Interpretation

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}

6. ul and the ol List Indentation 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.

7. element Horizontal Centering Problem

ff:margin:0 auto;

IE: Parent {text-align:center;}

8. Div the vertical centering 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.

9. margin double 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;

For example:

<div id= "imfloat" >
The corresponding CSS is
#imfloat {
float:left;
Margin:5px;/*ie understood as 10px*/
Display:inline;/*ie under the 5px*/}

10. IE issues with width and height

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

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

12. DIV Floating IE text Generation 3 of Pixels 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 id= "right" ></div>

13. IE the question of 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.

14. float of the Div closed ; Clear Floating ; self-adapting Height

① example:

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= "clear" > This div must pay attention to the location, and There must be no nesting relationship with two div siblings with the float attribute , or 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 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 id= "center" ><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 this:

<div id= "page" >

<div id= "bg" style= "float:left;width:100%" >

<div id= "left" ><div id= "center" ><div id= "right" >

</div>

</div>

Then embed a float left and the width is 100% div resolved.

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

15. Height not adapted

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

16. IE6 There are voids in the 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.

17. 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!

18. LI after the content is longer than the length, the ellipsis is displayed

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>

19. Why Web Standard in IE i can't set the scroll bar color Anymore.

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

20. Why can't I define 1px container with left and right 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"/>

21st. links (a label ) the 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.

22. after hyperlink access Hover problems with styles that don't appear

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 {}
-
</style>

23. 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;}.

24. Property Selector ( This is not compatible . , is hidden CSS of a Bug)

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.

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

{
height:auto!important;
height:200px;
min-height:200px;
}

. Cursor:hand and the Cursor:pointer

Firefox does not support hand, but IE supports pointer
Workaround : Unified use of pointer

About CSS Browser compatibility issues

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.