FAQs about compatibility with IE6 IE7 FF in Div + CSS layout
Source: Internet
Author: User
FAQs about compatibility with IE6 IE7 FF in Div + CSS layout
General use of all browsers (IE6 IE7 FF mainly used in the market)
Height: 100px; dedicated for IE6
_ Height: 100px; dedicated for IE6
* Height: 100px; dedicated for IE7
* + Height: 100px; shared by IE7 and FF
Height: 100px! Important;
I. CSS compatibility
The following two methods can solve almost all of today's compatibility. 1 ,! Important (not recommended, use the following one to feel the safest) with IE7! Important Support ,! The important method is only compatible with ie6. (note the writing method. Remember that the declaration position must be in advance .) Code :
<Style>
# Wrapper {
Width: 100px! Important;/* IE7 + FF */
Width: 80px;/* IE6 */
}
</Style> 2, IE6/ie77 for firefox <from CSS style for Firefox IE6 IE7> * + HTML and * HTML are unique tags of IE, which are not supported by Firefox currently. * + HTML is a unique tag of IE7. code:
<Style>
# Wrapper {width: 120px;}/* Firefox */
* Html # wrapper {width: 80px;}/* IE6 fixed */
* + Html # wrapper {width: 60px;}/* IE7 fixed, pay attention to the Order */
</Style> note:
* + For HTML compatibility with IE7, the following declaration must be made on the top of HTML: code:
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> 2. Universal float closure (very important !) You can use this to solve the mismatch of spacing when multiple Div alignment occurs. For 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. The Code has been tried and tested:
<Style>
/* 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 */
</Style> 3. Other compatibility skills (quite useful) 1. Setting padding for div in FF will increase the width and height, but IE will not. (available! Important solution)
2. center problem.
1). Vertical center. Set line-height to the same height of the current Div, and then use vetical-align: middle. (Note that do not wrap the content .)
2). horizontal center. Margin: 0 auto; (of course not omnipotent)
3. To add a style to the content of tag a, set display: block)
4. The difference between FF and IE in understanding box leads to the 2px difference. There are also issues such as Div set to float and margin doubling under IE.
5. UL labels are listed-style and padding by default under ff. It is recommended to declare them in advance to avoid unnecessary troubles. (commonly seen in navigation labels and content lists)
6. Do not set the height of the external wrapper Div. It is best to add overflow: hidden to achieve highly adaptive.
7. for hand-shaped cursor. cursor: pointer. And hand only applies to IE. Pasting code:
8. Double margin bug in IE6
<Style type = "text/CSS">
Body {margin: 0}
Div {float: Left; margin-left: 10px; Height: 200px; Border: 1px solid red}
</Style>
The external margin is 10px after floating, but IE is interpreted as 20px. The solution is to add the display: inline
9. 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 setting of height to Min-Height: 200px, which can be defined as follows to take care of IE6 that does not know Min-height:
Div {Height: Auto! Important; Height: 200px; Min-Height: 200px;} compatible code: compatible with the most recommended mode.
/* FF */
. Submitbutton {
Float: left;
Width: 40px;
Height: 57px;
Margin-top: 24px;
Margin-Right: 12px;
}
/* IE6 */
* Html. submitbutton {
Margin-top: 21px;
}
/* IE7 */
* + Html. submitbutton {
Margin-top: 21px;
}
What is browser compatibility? When we use different browsers (Firefox IE7 IE6) to access the same website or page, some incompatibility problems may occur, and some may be displayed as normal, some of them are not normal, and we will be very annoyed when writing CSS. After fixing this browser problem, another browser has a new problem. Compatibility is a way to enable independent writing in a CSS to support different browser styles. This is harmonious. Haha! Program The first code is compatible, and all ie ff browsers are public (in fact not compatible)
Height: 100px;
Second compatible with dedicated Internet Explorer 6
_ Height: 100px;
Third compatible with IE6 IE7 public
* Height: 100px;
Height: 100px;
* Height: 120px;
_ Height: 150px; In ff, 2nd and 3 attributes are not recognized, so they read Height: 100px. In IE7, the third attribute is not recognized by IE7, therefore, it reads 1st and 2 attributes, and because the second attribute overwrites the first attribute, IE7 finally reads 2nd attributes * Height: 120px; in IE6, all three attributes are recognized by IE6. Therefore, all three attributes can be read. Because the third attribute overwrites the first two attributes, IE6 eventually reads the third attribute. 1 most CSS styles for Firefox IE6 IE7 are currently used! Important is compatible. It can be displayed normally for IE6 and Firefox tests, but IE7 is compatible! Important can be correctly explained, and the page will not be displayed as required! If you find a good compatibility Method for IE7, you can use "* + html". Now you can use IE7 to browse it. It should be okay. Now you can write a CSS file like this: #1 {color: #333;}/* Moz */
* Html #1 {color: #666;}/* IE6 */
* + Html #1 {color: #999;}/* ie */The font color in Firefox is #333, And the font color in IE6 is #666, in IE7, the font color is displayed as #999. 2. The main style definition of the center problem in the CSS layout is as follows: body {text-align: center ;}
# Center {margin-Right: auto; margin-left: auto;} Description: first, define text-align: center in the parent element; this means that the content in the parent element is centered; for IE, this setting is enough. However, it cannot be centered in Mozilla. The solution is to add "margin-Right: auto; margin-left: auto;" when the sub-element is defined, if you want to use this method to center the entire page, it is recommended that you do not set it in one Div. You can split multiple DIV in sequence, as long as you define margin-right in each split Div: auto; margin-left: auto. 3 different explanations for the box model. # 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-
} 4 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 block and inline elements. The characteristics of the block elements are: Always starting on a new line, height, width, and Row Height, margin can be controlled (Block Element); The Inline element is characterized by the same line as other elements ,... Uncontrollable (embedded element); # 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; 5 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 & gt; body # box {width: auto; Height: auto; Min-width: 80px; Min-Height: 35px;} The Min-width of the 6-page is a very convenient CSS command, which can specify the minimum or less width of the element, this ensures that the layout is correct all the time. 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 place <div> under the <body> label and specify a class for div:
Then CSS is designed like this: # container {
Min-width: 600px;
Width: expression (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, which will make your HTML document not regular. It actually achieves the minimum width through javascript judgment. 7 clear floating. compatible with box {
Display: Table;
// Display the object as a table at the Block Element Level
} Or. compatible with box {
Clear: both;
} Or add: After (pseudo object) to set the content after the object, which is usually used with content. ie does not support this pseudo object, not supported by IE browsers, so it does not affect IE/win browsers. This is the most troublesome ...... # Box: After {
Content: ".";
Display: block;
Height: 0;
Clear: both;
Visibility: hidden;
} 8 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 the key
}
HTML code
& Lt; Div id = Box>
<Div id = left> </div>
<Div id = right> </div>
</Div> 9 attribute selector (this is not compatible and is a bug in hiding CSS) P [ID] {} Div [ID] {}
P [ID] {} Div [ID] {} is hidden for versions earlier than ie6.0 and ie6.0. The attribute selector and subselector of FF and opera are different, the range of the sub-selector is reduced in the form, and the range of the property selector is relatively large. For example, in P [ID], all P tags have IDs in the same style. 10 ie: Hide and seek. When the DIV application is complicated, there are some links in each column, and DIV is prone to hide and seek problems.
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. 11. The height of the inner layer cannot be automatically adjusted when the height of the inner layer object changes, especially when the inner layer object is used.
Margin or paddign. Example: <Div id = "box">
<P> content in the p object </P>
</Div> CSS: # box {background-color: # Eee ;}
# Box P {margin-top: 20px; margin-bottom: 20px; text-align: center;} 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. Shield ie browsers (that is, they are not displayed under IE)
*: Lang (zh) Select {Font: 12px! Important;}/* ff, OP visible */
Select: Empty {Font: 12px! Important;}/* safari visible */
Here, select is the selector, which can be changed as needed. The second sentence is unique to the Safari browser on Mac. Only IE7 Recognition
* + HTML {...}
This compatibility can be used only for IE7 styles. Identification of IE6 and IE6 or lower
* HTML {...}
In this case, we should pay special attention to the fact that many landlords write IE6 compatibility. In fact, ie5.x can also identify this compatibility. Not recognized by other browsers.
Html/**/& gt; body select {......}
This sentence serves the same purpose as the previous one. Only IE6 is not recognized
Select {display/* IE6 not recognized */: none ;}
Here we mainly use CSS annotations to separate an attribute and a value, and the stream is prior to the colon. Only IE6 and ie5 are not recognized
Select/**/{display/* IE6, ie5 does not recognize */: none ;}
The difference here is that a CSS comment is added between the separator and curly braces. Only ie5 is not recognized
Select/* ie5 not recognized */{display: none ;}
This sentence removes the comment of the attribute area from the previous sentence. Only ie5 does not recognize the Box Model Solution
Selct {width: ie5.x width; voice-family: ""} "; voice-family: Inherit; width: correct width ;}
The box model clearing method is not passed! Important. This should be clear. Clear floating
Select: After {content: "."; display: block; Height: 0; clear: Both; visibility: hidden ;}
In Firefox, when the child level is floating, the height of the parent level cannot fully cover the entire child level, in this case, we can define the parent level with the compatibility of floating clearance, so that this problem can be solved. Ellipsis (...)
Select {-o-text-overflow: ellipsis; white-space: nowrapoverflow: hidden ;}
This is a good technique to cut out more text and end it with a ellipsis. But Firefox does not currently support it. Only opera Recognition
@ Media all and (min-width: 0px) {select {......} }
Set the Opera Browser separately. All of the above are compatible with CSS. We recommend that you follow the correct tag nesting (div ul Li nested structure), which can reduce the frequency of compatibility and avoid misunderstanding, not a page requires a lot of compatibility to maintain compatibility with multiple browsers). In many cases, a compatible page may not be used to make the browser work very well, these are all used to solve the local compatibility problem. If you want to separate the compatibility content, try several filters below. Some of these filters are written in CSS to import special styles through filters, and some are written in HTML to link or import the required patch styles through conditions. Ie5.x filter, only visible to ie5.x
@ Media tty {
I {content: "";/* "*/} @ import 'ie5win.css ';/*";}
}/**/Ie5/MAC filter, generally not required
/**//*/
@ Import "ie5mac.css ";
/**/If conditions of IE are compatible and can be used flexibly. For more information, see the IE condition note.
Only IE
All ie identifiers are only recognized by ie5.0.
Only IE 5.0 +
Ie5.0 for ie5.5 can be identified only by IE6
Only IE 7 /-
Ie5.x under IE6 and IE6 can be recognized
Only IE 7 /-
IE7 alone can identify many things in CSS that don't follow certain rules, it will upset you very much, although you can use a lot of compatibility, a lot! Important to control it, but you will find that in the long run you will be reluctant to look at many excellent websites, their CSS let IE6, IE7, Firefox, and even safari, is opera perfect? However, they seem to be less compatible with complex templates. In fact, you need to know that IE and Firefox are not so incompatible. We can find a way to make them coexist harmoniously. Don't think that you have discovered a compatible method, and you have mastered everything. We are not compatible slaves. The nesting order of Div ul Li follows the above Nesting Method, <div> <ul> <li> </LI> </ul> </div> In the CSS file, the UL {margin: 0px; padding: 0px; List-style: none;}, where list-style: none is not to show the DOT or number at the front of the <li> mark, because IE and Firefox display a different default effect. Therefore, you do not need to do anything in this way. There is almost no difference between your IE6, IE7, and Firefox (the outer distance, distance, height, and width, maybe you will find the difference between one and two pixels at a certain time, but it is perfect. You don't need to adjust the CSS Of a large part to control their display, you are willing to, you can only be compatible with one or two places, and usually this compatibility can adapt to various places, you do not need to repeatedly debug different compatible methods in different places-ease your troubles. You can use ul. class1, ul. class2, ul. class3 {XXX: XXXX} to easily sort out the areas you want to be compatible. Try it out and never nest it out again. Although you can almost think about how to nest it in Div + CSS mode, you will be much easier according to the above rules, to get twice the result!
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.