Solutions to CSS compatibility between IE8, 7, 6 and Fireofx

Source: Internet
Author: User
Solutions to CSS compatibility between IE8, 7, and 6 and Fireofx)

In DIV + CSS | Tags:

Solutions to CSS compatibility between IE8, 7, 6 and Fireofx

Many webmasters complain that CSS compatibility with browsers is sometimes a headache, especially for browsers with many Internet Explorer 6 problems. Maybe when you understand the skills and principles, you will feel that it is not difficult. I have collected and sorted out the solutions for the compatibility between IE7, 6 and Fireofx from the Internet. for Web, try to write code in xhtml format, and DOCTYPE affects CSS processing. As the W3C standard, DOCTYPE Declaration must be added.

CSS skills

1. Vertical center of div

Vertical-align: middle; Increase the line spacing to the line-height: 200px as high as the entire DIV; then insert the text to center vertically. The disadvantage is that you need to control the content rather than line feed.

2. Question about doubling margin

The div set to float doubles the margin set in ie. This is a bug in ie6. The solution is to add the display: inline In the div;

For example:

<# Div id = "imfloat">

The corresponding css is

# IamFloat {

Float: left;

Margin: 5px;/* 10 Px in IE */

Display: inline;/* in IE, It is understood as 5px */}

3. Double distance produced by floating ie

# Box {float: left; width: 100px; margin: 0 0 0 100px; // in this case, IE will generate a PX distance display: inline; // ignore floating}

Here, let's take a closer look at the block and inline elements: the block elements always start on a new line, and can be controlled by the height, width, row height, and margin (block element ); the Inline element is not controllable (embedded element) on the same line as other elements );

# Box {display: block; // The embedded element can be simulated as the block element display: inline; // the result of the same row arrangement is dilay: table;

4 issues with IE and width and height

IE does not recognize the min-definition, but in fact it treats normal width and height as min conditions. In this case, the problem is big. If only the width and height are used, the values in the normal browser will not change. If only min-width and min-height are used, the width and height under IE are not set at all.

For example, to set a background image, the width is 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 ;}

5. Minimum page width

Min-width is a very convenient CSS command, which can specify that the element is at least or less than a certain width, so as to ensure correct layout. But IE does not recognize this, but it actually uses width as the minimum width. To enable this command to be used on IE, you can

Put it under the tag, specify a class for the div, and then design the CSS as follows:

# 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 is recognized only by IE, which will make your HTML document not formal. It actually achieves the minimum width through Javascript judgment.

6. The bug that DIV floating IE text produces 3 pixels

The left object floats, and the left margin of the outer patch is used to locate the patch on the right. The text in the right object is 3 px 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 critical}

7. Questions about Internet Explorer

When the div application is complicated, there are some links in each column. When the DIV application is complicated, it is prone to the "hide and seek" issue.

Some content cannot be displayed. When you select this area, the content is displayed on the page. Solution: Use the line-height attribute for # layout or use fixed height and width for # layout. The page structure should be as simple as possible.

8. float div closure; clear floating; adaptive height;

① For example, <# div id = "floatA"> <# div id = "floatB"> <# div id = "NOTfloatC"> the NOTfloatC here does not want to continue translation, instead, we want to move it down. (FloatA and floatB attributes have been set to float: left ;)

This code has no problem in IE, and the problem lies in FF. The reason is that NOTfloatC is not a float label and must be closed. Add <# div class = "floatB"> <# div class = "NOTfloatC"> <# div class = "clear"> the position of the div, it must be at the same level as the two div with the float attribute. No nested relationship exists between them; otherwise, an exception occurs. And define the clear style as follows:. clear {clear: both ;}

② Do not set the height of the external wrapper div. In order to make the height automatically adapt, overflow: hidden should be added to the wrapper; when the box containing float is included, the height auto-fit is invalid in IE. In this case, the private attribute layout of IE should be triggered (the Internet Explorer !) Zoom: 1; can be used to achieve compatibility.

For example, a wrapper is defined as follows:

. Colwrapper {overflow: hidden; zoom: 1; margin: 5px auto ;}

③ For typographical layout, the most commonly used css description may be float: left. Sometimes we need to make a unified background behind the float div in the n column, for example:

For example, we want to set the background of the page to Blue to make the background color of all three columns blue, but we will find that as the left center right is stretched down, the storage height of the page remains unchanged. The problem is that the page is not a float attribute. Because the page is centered, it cannot be set to float, so we should solve this problem.

Embed a float left and the DIV with a width of 100%.

④ Universal float closure (very important !)

For details about the principle of clear float, see [How To Clear Floats Without Structural Markup]. Add the following code To Global CSS and add the div To be closed.

/* 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 table at the block element level}

11. highly unsuitable

Height mismatch means that the height of the outer layer cannot be automatically adjusted when the height of the inner layer object changes, especially when the inner layer object uses margin or paddign.

Example:

# Box {background-color: # eee ;}

# Box p {margin-top: 20px; margin-bottom: 20px; text-align: center ;}

Content in object p

Solution: Add two empty div objects to the upper and lower sides of the P object. CSS code:. 1 {height: 0px; overflow: hidden;} or add the border attribute to the DIV.

12. Why is there a gap in the image under IE6?

There are also many ways to solve this BUG. You can change the html layout, set img to display: block, or set vertical-align to vertical-align: top | bottom | middle | both text and bottom can be solved.

13. Align text and text input boxes

Add vertical-align: middle;

<Style type = "text/css">
<! -
Input {
Width: 200px;
Height: 30px;
Border: 1px solid red;
Vertical-align: middle;
}
->
</Style>

14. What is the difference between id and class defined in web standards?

I. duplicate IDs are not allowed in web standards. For example, div ID = "aa" cannot be repeated twice, while class defines classes, which can be infinitely repeated in theory, in this way, you can use the definition that requires multiple references.

Ii. attribute priority

The priority of ID is higher than that of class.

III. convenience for JS and other client scripts. If you want to perform script operations on an object on the page, you can define an ID for it. Otherwise, you can only find it by traversing the page element and adding specific attributes, this is a relatively time-consuming resource, which is far less simple than an ID.

15. How to display the content in LI with ellipsis after the content length exceeds

<Style type = "text/css">
<! -
Li {
Width: 200px;
White-space: nowrap;
Text-overflow: ellipsis;
-O-text-overflow: ellipsis;
Overflow: hidden;
}

->
</Style>

This method is applicable to IE and opbrowser.

16. Why can't I set the color of the scroll bar in web Standard IE?

The solution is to change the body to 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>

17. Why cannot I define a container with a height of around 1 px?

In IE6, this problem is caused by the default Row height, and there are many solutions, such as overflow: hidden | zoom: 0.08 | line-height: 1px.

18. How can I display layers on FLASH?

The solution is to make FLASH transparent.

<Param value = "transparent"/>

19. How to center a layer vertically in the browser

Here we use the absolute percentage position, and the method of negative value of the external patch, the negative value is its own width and height divided by two

<Style type = "text/css">
<! -
Div {
Position: absolute;
Top: 50%;
Lef: 50%;
Margin:-100px 0 0-100px;
Width: 200px;
Height: 200px;
Border: 1px solid red;
}
->
</Style>

FF and IE

1. Div Center

If the div sets margin-left and margin-right to auto, it is already centered. If IE is not, you need to set the body to center. First, define text-algin: center in the parent element; this means that the content in the parent element is centered.

2. Border and background of the Link (a tag)

Add the border and background color to the link. Set display: block and float: left to avoid line breaks. Refer to menubar to set the height of a and menubar to avoid misplacement of the bottom side. If no height is set, you can insert a space in menubar.

3. Problems with the hover style after hyperlink access

Click to access the hyperlink style is not with hover and active, many people should have encountered this problem, the solution is to change the CSS attribute order: L-V-H-A

Code:

<Style type = "text/css">
<! -
A: link {}
A: visited {}
A: hover {}
A: active {}
->
</Style>

4. cursor

Cursor: pointer can display the cursor finger shape in ie ff at the same time, hand only IE Can

5. UL's padding and margin

Ul labels have padding values by default in FF, while only margin has default values in IE. Therefore, ul {margin: 0; padding: 0;} is defined first ;} most problems can be solved.

6. FORM tag

In IE, this label will automatically margin some margins, while in FF, margin is 0. Therefore, if you want to display consistency, it is best to specify margin and padding in css, for the above two problems, I usually use this style ul in css first, form {margin: 0; padding: 0 ;}to define it as dead, so it won't be a headache in the future.

7. Inconsistency of BOX Model Interpretation

The BOX model interpretation in FF and IE is inconsistent, resulting in a 2px difference. Solution: div {margin: 30px! Important; margin: 28px;} note that the order of the two margin must not be reversed. The attribute IE of important cannot be identified, but can be recognized by other browsers. Therefore, in IE, it is actually interpreted as follows: If div {maring: 30px; margin: 28px} is repeatedly defined, it is executed according to the last one. Therefore, you cannot 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 incompatible and is a bug in hiding css)

P [id] {} div [id] {}

This is hidden for versions earlier than IE6.0 and IE6.0, and works with FF and OPera. there is a difference between the property selector and the Child selector. The range of the Child selector is reduced in the form, and the range of the property selector is relatively large, such as in p [id, all p tags have IDs in the same style.

9. The most cruel means -! Important;

If there is no way to solve some detailed problems, you can use this method. FF "! Important will automatically give priority to resolution, but IE will ignore it.

. 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 xxxx must be added! Important is placed on the other sentence, which has been mentioned above.

10. Questions about default values of IE and FF

Maybe you have been complaining about why you want to write different CSS for IE and FF. Why is it so troublesome for IE? Then write css while cursing the hateful M $ IE. in fact, for the standard support of css, IE is not as bad as we think. The key is that the default values of IE and FF are different. I have mastered this technique, you will find that writing css compatible with FF and IE is not that difficult. You may not need to write simple css "! Important.

We all know that when a browser displays a webpage, it will decide how to display it based on the css style sheet of the webpage. However, we may not describe all the elements in the style sheet, of course, there is no need to do this, so for those attributes that are not described, the browser will use the built-in default mode for display, such as text, if you do not specify the color in css, the browser uses black or system color to display the background of the div or other elements. If it is not specified in css, the browser sets it to white or transparent, and so on. So the root cause of the difference between FF and IE display is that their default display is different, and how to display this default style? I know there are no corresponding standards in w3 to define, therefore, do not blame IE for this.

11. why can't the FF text support the height of the container?

Containers with fixed height values in the standard browser won't be opened as in IE6, so I want to fix the height and how can I set it to be supported? The method is to remove the min-height: 200px setting for height. Here, we can define this to take care of IE6 that does not know min-height:

{

Height: auto! Important;

Height: 200px;

Min-height: 200px;

}

12. How to enable automatic line feed for continuous long fields in FireFox

As we all know, you can use word-wrap: break-word directly in IE. In FF, we use JS insertion to solve this problem.

<Style type = "text/css">
<! -
Div {
Width: 300px;
Word-wrap: break-word;
Border: 1px solid red;
}
->
</Style>

<Div id = "ff"> 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 </div>

<Script type = "text/plain Cr partition pt">
/* <! [CDATA [*/
Function toBreakWord (el, intLen ){
Var export 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", 37 );
/*]> */
</Script>

13. Why is the container width and FF interpretation different under IE6?

<? Xml version = "1.0" encoding = "gb2312"?>
<! 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">
<! -
Div {
Cursor: pointer;
Width: 200px;
Height: 200px;
Border: 10px solid red
}
->
</Style>
<Div export nclick = "alert (this. offsetWidth)"> make FireFox compatible with IE </div>

Make FireFox compatible with IE

The difference is whether the overall width of the container includes the border width. Here, IE6 is interpreted as 200PX, while FF is interpreted as 220PX, so how did it cause the problem? If you remove the xml at the top of the container, you will find that the original problem exists. The declaration at the top triggers the qurks mode of IE. For more information about qurks mode and standards mode, see: http://www.microsoft.com/china/msdn/library/webservices/asp.net/

ASPNETusStan. mspx? Mfr = true

IE6, IE7, FF

When IE7.0 came out, there were new problems with CSS support. More browsers,

Width: 50px;/* For IE7 & IE6 */

Width: 40px;/* For IE6 */

Pay attention to the sequence.

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;}/* IE7 */

The second method is to use conditional annotations dedicated to IE.

Third, the css filter method, which is translated from a foreign website as a classic ..

Create a css style as follows:

# Item {

Width: 200px;

Height: 200px;

Background: red;

}

Create a new div and use the css style defined above:

Some text here

Add the lang attribute in the body representation. The Chinese character is zh:

Now define another style for the div element:

*: Lang (en) # item {

Background: green! Important;

}

This is intended for use! Important overwrites the original css style. Because the lang selector ie7.0 does not support this sentence, it does not have any effect on this sentence, so it achieves the same effect in ie6.0, unfortunately, safari does not support this attribute, so you need to add the following css style:

# Item: empty {

Background: green! Important

}

: The empty selector is a css3 specification. Although safari does not support this specification, this element is still selected, whether or not this element exists, now green will be available in browsers other than ie versions.

 

Go to: http://www.kitesky.com/20100815/736.html

Related Article

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.