Div + CSS compatible with IE6, IE7, and Firefox

Source: Internet
Author: User

The most common difference between Firefox and IE is that! The important method provides the following methods for compatibility of different versions of other browsers and browsers, such as @ import, annotation, and attribute selector, sub-object selector, voice-family, and other methods are described in CSS website layout recording.

◆ The following are CSS compatibility issues between IE and Firefox:

1. doctype affects CSS Processing

2. Firefox: When Div sets margin-left and margin-Right to auto, it is already centered, and IE is not working.

3. When setting text-align for Firefox: body, you must set margin: auto (mainly margin-left and margin-Right) for the DIV to be centered.

4. Firefox: After padding is set, the DIV will increase the height and width, but IE will not, so you need to use it! Set one more height and width for important.

5. Firefox: supported! Important, ie is ignored, available! Important sets a special style for Firefox. It is worth noting that you must set XXXX! The important sentence is placed on the other sentence.

6. Vertical center problem of Div: vertical-align: middle; Increase the line spacing to the same height as the entire Div line-Height: 200px; then insert the text to the vertical center. The disadvantage is that you need to control the content rather than line feed.

7. cursor: pointer can display the cursor finger in iefirefox at the same time. Hand can only be IE

8. Firefox: adds a border and a background color to the link. You must 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.

9. The box model interpretation in mozillafirefox and IE is inconsistent, resulting in a 2px difference. Solution: div {margin: 30px! Important; margin: 28px ;}
Note that the order of the two margin entries must not be reversed. According to Alibaba Cloud! The important attribute ie cannot be identified, but other browsers can. So in IE, it is actually explained as follows: div {maring: 30px; margin: 28px}
If the definition is repeated, execute the last statement. Therefore, you cannot write only margin: xxpx! Important;

10. The box interpretations of ie5 and IE6 are inconsistent.

Div {width: 300px; margin: 010px010px;} under ie5 ;}
The DIV width is interpreted as 300px-10px (right fill)-10px (left fill). The final Div width is 280px, in IE6 and other browsers, the width is calculated based on 300px + 10px (right fill) + 10px (left fill) = 320px. In this case, we can modify Div {width: 300px as follows! Important; width/**/: 340px; margin: 010px010px}
I don't quite understand what/**/is. I only know that both ie5 and Firefox support it, but IE6 does not. If anyone understands it, please let me know. Thank you! :)

11. UL labels have padding values by default in Mozilla, and only margin has a value in IE. Therefore, defining ul {margin: 0; padding: 0 ;} first can solve most of the problems.

◆ Note:

 

1. The DIV of float must be closed.

For example: (floata and floatb attributes have been set

  
  
  1. Float: Left ;)<#Divid= \ "Floata \"> 
  2. <#Divid= \ "Floatb \"> 
  3. <#Divid= \ "Notfloatc \"> 

The notfloatc here does not want to continue translation, but wants to move down.
This sectionCodeThere is no problem in IE. The problem lies in Firefox. The reason is that notfloatc is not a float label and must be closed.
In

  
  
  1. <#Divclass= \ "Floatb \"> 
  2. <#Divclass= \ "Notfloatc \"> 
  3. Add<#Divclass= \ "Clear \"> 

This Div must pay attention to the declaration position. It must be placed in the most appropriate place and must be at the same level as two DIV with the float attribute. No nested relationship exists between them; otherwise, an exception may occur.
And define the clear style as follows:

 
  
  
  1. :. Clear {
  2. Clear: Both ;}

In addition, in order to automatically adapt to the height, overflow: hidden should be added to the wrapper;
When a box containing float is automatically adapted to the IE environment, 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:

 
  
  
  1. :. Colwrapper {
  2. Overflow: hidden;
  3. Zoom: 1;
  4. Margin: 5 pxauto ;}

2. The problem of 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:

  
  
  1. <#Divid= \ "Imfloat \"> 
  2.  
  3. The corresponding CSS is
  4. # Iamfloat {
  5. Float: left;
  6. Margin: 5px;/* 10 Px in IE */
  7. Display: inline;/* in IE, It is understood as 5px */}
  8.  

3. Container inclusion relationships

In many cases, especially when the container has a parallel layout, such as two or three float Divs, the width is prone to problems. In ie, the width of the outer layer is broken by the DIV with a wider inner layer. You must use Photoshop or firework to obtain pixel-level precision.

4. Questions about height

If the content is added dynamically, it is best not to define the height. The browser can automatically scale. However, it is best to set the height of static content. (It seems that sometimes it will not be automatically pushed down and I don't know what's going on)

5. the most cruel means -! Important;

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

 
  
  
  1. . Tabd1 {
  2. Background: URL (/RES/images/up/tab1.gif) no-repeat0px0px! Important;/* styleforFirefox*/
  3. Background: URL (/RES/images/up/tab1.gif) no-repeat1px0px;/* styleforie */}

It is worth noting that XXXX must be added! Important is placed on the other sentence, which has been mentioned above

When ie7.0 came out, there were new problems with CSS support. When there are more browsers and the webpage compatibility is worse, we are still exhausted. To solve the problem of ie7.0 compatibility, I found the following article.Article:

I use most of them now! Important comes to hack. It can be displayed normally for IE6 and Firefox tests, but IE7 is correct! Important can be correctly explained, and the page will not be displayed as required! After searching, I found a good hack Method for IE7 and used "* + html". Now I can use IE7 to browse it. It should be okay.

You can write a CSS file as follows:

  
  
  1. # Example {color: #333;}/* Moz */
  2. * Html # example {color: #666;}/* IE6 */
  3. * + Html # example {color: #999;}/* IE7 */

The font color in Firefox is #333, the font color in IE6 is #666, And the font color in IE7 is #999. I really want IE6 to retire soon.

◆ Div + CSS three-row and three-column layout (compatible with various browsers)

  1. <! Doctypehtmlpublic "-// W3C // dtdhtml4.01 // en"
  2.  
  3. Http://www.w3.org/TR/html4/strict.dtd"> 
  4. <Html> 
  5. <Head> 
  6. <Title>Div layout Test</Title> 
  7. <StyletypeStyletype="Text/CSS"> 
  8.  
  9. Div
  10. {
  11. Height: 150px;
  12. }
  13. Div. Left
  14. {
  15. Width: 20%;
  16. Float: left;
  17. Clear: right;
  18. Background-color: # eeeeee;
  19. }
  20.  
  21. Div. Center
  22. {
  23. Width: 50%;
  24. Float: left;
  25. Clear: right;
  26. Background-color: # cccccc;
  27. }
  28.  
  29. Div. Right
  30. {
  31. Width: 30%;
  32. Float: left;
  33. Clear: right;
  34. Background-color: #808080;
  35. }
  36. Div. Both
  37. {
  38. Width: 100%;
  39. Clear: both;
  40. Background-color: #696969;
  41. }
  42.  
  43. </Style> 
  44. </Head> 
  45.  
  46. <Body> 
  47. <DivclassDivclass="Left">Left side</Div> 
  48. <DivclassDivclass="Center">Middle Side</Div> 
  49. <DivclassDivclass="Right">Right side</Div> 
  50.  
  51. <DivclassDivclass="Both">Full row</Div> 
  52.  
  53. <DivclassDivclass="Left">Left side</Div> 
  54. <DivclassDivclass="Center">Middle Side</Div> 
  55. <DivclassDivclass="Right">Right side</Div> 
  56. </Body> 
  57. </Html> 

From: http://developer.51cto.com/art/201008/220140.htm

Purpose: Collect Summary

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.