Sorting out the most comprehensive CSS browser compatibility issues

Source: Internet
Author: User
I have collected and sorted out the compatibility solutions for IE7, 6 and fireofx from the Internet. For over-compatibility with Web2.0, try to write in XHTML format. Code And doctype affects CSS processing. as W3C standard, doctype must be well known.

CSS skills

1. Vertical-align: middle of the DIV vertical center problem; Increase the line spacing to the line-Height: 200px as high as the entire div; then insert the text, and the vertical center is formed. The disadvantage is that you need to control the content rather than line feed.

2. The problem of margin doubling is that the margin set for div of Float under IE will be doubled. This is a bug in IE6. The solution is to add display: inline to the Div. For example, <# Div id = "imfloat"> the corresponding CSS is # iamfloat {float: Left; margin: 5px; /* ie: 10px */display: inline;/* ie: 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 I will elaborate on the two elements block and inline: The block element is always starting on a new line, with the height, width, and Row Height, margins can be controlled (block elements). The Inline element is not controllable on the same line as other elements (embedded 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 IE and width and height problems IE does not recognize Min-, but in fact it treats normal width and height as Min. 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. The Min-width of the page is a very convenient CSS command, which can specify the minimum or no less than a certain width of the element, so as to ensure that the layout is always correct. But IE does not recognize this, but it actually uses width as the minimum width. To make this command usable on IE, you can place <div> under the <body> label and specify a class for div. Then, CSS is designed as follows: # container {Min-width: 600px; width: E-xpression (document. body. clientwidth <600? "600px": "Auto");} The first Min-width is normal, but the width of row 2nd uses JavaScript, which is recognized only by IE, this will also make your HTML documents less formal. It actually achieves the minimum width through javascript judgment.

6. div floating ie text generates a 3-pixel bug. The left object float is located on the right side using the left margin of the outer patch. 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} <Div id = "box"> <Div id = "Left"> </div> <Div id = "right"> </div> </div>

7. Internet Explorer: When the DIV application is complicated, there are some links in each column. When Div and so on, 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. (The attributes of floata and floatb 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: <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, the background color of all three columns is blue, but we will find that with the left center right extending down, and the page actually keeps the height unchanged, the problem is that, the reason is that the page is not a float attribute, and because the page is centered, it cannot be set to float, therefore, 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> 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 class = "Clearfix" to 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 */or set as follows :. hackbox {display: Table; // display an object as a table at the block element level.}

11. The height is not adaptive. When the height of the inner object changes, the outer height cannot be adjusted automatically, especially when the inner object uses margin or paddign. Example: # box {background-color: # Eee;} # Box P {margin-top: 20px; margin-bottom: 20px; text-align: center ;} <Div id = "box"> <p> content in the p object </P> </div> solution: add two empty Div object CSS codes to the upper and lower sides of the P object :. 1 {Height: 0px; overflow: hidden;} or add the border attribute to the div.

12. in IE6, there are many ways to solve this bug due to gaps in the image. You can change the HTML layout or set IMG to display: block or set the vertical-align attribute to vertical-align: Top | bottom | Middle | text-bottom.

13. How to align text and text input boxes with 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? 1. 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 question ID has a higher priority than class. See example 3 above. 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 is exceeded. This method is applicable to IE and opbrowser <style type = "text/CSS"> <! -- Li {width: 200px; white-space: nowrap; text-overflow: ellipsis;-o-text-overflow: ellipsis; overflow: hidden;} --> </style>

16. Why can't I set the color of the scroll bar for IE in web standards? 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 can't I define the container IE6 with a height of 1 px? This problem is caused by the high row size by default. There are also many solutions, such as overflow: hidden | ZOOM: 0.08 | Line-Height: 1px

18. How can I display layers on Flash? The solution is to set transparency for flash. <Param name = "wmode" value = "Transparent"/>

19. how to center a layer vertically in the browser. Here we use the absolute percentage position, which is negative from the external patch, the size of 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 problem Div set margin-left, margin-right is already centered when it is set to auto, ie is not, ie needs 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. Add a border and a background color to the border of the Link (tag a). 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.

 

13. Why is the container width different from FF in IE6?

the difference between Firefox and IE compatibility
is whether the overall width of the container includes the width of the border (Border). Here IE6 is interpreted as 200px, FF is interpreted as 220px. 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, and FF ie7.0 are coming out, and there are 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! The following shows the compatibility of the three browsers.

First, it is the CSS hack method Height: 20px;/* For Firefox */* Height: 25px;/* For IE7 & IE6 */_ Height: 20px; /* 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 */

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 div and use the CSS style defined earlier: <Div id = "item"> some text here </div> adds the lang attribute in the body representation. The Chinese character is Zh: <body lang = "en"> now define another style for the DIV element: *: Lang (en) # item {Background: Green! Important! 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. For compatibility with IE6 and FF, consider the previous! Important prefers the first method, which is concise and compatible.

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.