Reprinted from: http://hi.baidu.com/zhenghanzheng/blog/item/840e5501d2c71b0a7aec2c81.html
When designing a website, you should pay attention to the issue of CSS styles being compatible with different browsers. Especially for websites designed entirely using DIV CSS, you should pay more attention to the compatibility of IE6 IE7 FF with CSS styles. Otherwise, your network may become cluttered and have unwanted effects!
Common to all browsers
height: 100px;
Exclusively for IE6
_height: 100px;
Exclusively for IE6
*height: 100px;
Exclusively for IE7
* height: 100px;
Shared by IE7 and FF
height: 100px !important;
1. CSS compatibility
The following two methods can solve almost all compatibility issues today.
1, !important (not very recommended) , it feels safest to use the following one)
With IE7’s support for !important, the !important method is now only compatible with IE6. (Pay attention to the writing. Remember that the declaration position needs to be in advance.)
Code:
2, IE6/IE77 for FireFox
* html and *html are IE-specific tags, which are not supported by firefox. And *html is a IE7-specific tag .
Code:
Note:
* html Compatibility with IE7 must ensure the following statement at the top of the HTML:
Code:
2. Universal float closure (very important!) You can use this to solve the problem of incorrect spacing when aligning multiple divs.
For the principle of clear float, please refer to [How To Clear Floats Without Structural Markup]
Replace the following Add the code to Global CSS and add class="clearfix" to the div that needs to be closed. It works every time.
Code:
3. Other compatibility tips (quite useful)
1. Setting padding on a div in FF will cause the width and height to increase, but IE will not. (can be solved with !important)
2, centering problem.
1). Vertically centered. Set line-height to the same height as the current div, and then pass vetical-align: middle. (Be careful not to wrap the content.)
2). Horizontally centered. margin: 0 auto; (of course not universal)
3. If you need to add styles to the content in the a tag, you need to set display: block; (common in navigation tags)
4. The difference in the understanding of BOX between FF and IE leads to a 2px difference. There are also problems such as the margin of a div set to float doubling under IE.
5. The ul tag has list-style and padding by default under FF. It is best to prepare it in advance declaration to avoid unnecessary trouble. (Common in navigation tags and content lists)
6. Do not set the height of the div as an external wrapper. It is best to add overflow: hidden. to achieve height adaptability.
7, Regarding the hand cursor. cursor: pointer. And hand is only applicable to IE. Paste the code:
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 differences will appear. Regarding compatibility issues, some are displayed normally and some are displayed abnormally. We will be very annoyed when writing CSS. We just fixed the problem of this browser, but another browser has a new problem. Compatibility is a method that allows you to independently write styles that support different browsers in a CSS. Now there is harmony. hehe!
The compatibility of the IE7 browser recently released by Microsoft has indeed placed a heavy burden on some web page producers. Although IE7 has become standardized, it still has many differences from FF, so the compatibility of IE7 needs to be used. Many friends have asked what the compatibility of IE7 is, but I actually don’t know. I haven't found any compatibility specifically for IE7 yet. In addition to the previous article, the compatibility method in "CSS Style for Firefox IE6 IE7" is also very useful.
Anyone with a little bit of logical thinking will know that you can use the compatibility of IE and FF together. Here are three compatibility options, for example: (Suitable for novices, haha, experts will stop by here.)
Program code
The first one is compatible, common to all IE FF browsers (in fact, it is not compatible)
height:100px;
The second one is compatible with IE6 only
_height:100px;
The third one is compatible IE6 IE7 common
*height:100px;
Now that we have introduced these three compatibility, let’s take a look at how to define IE6 IE7 FF-specific compatibility for an attribute in a style respectively. Look at the code below and the order. You can’t go wrong:
Program code
height:100px;
*height:120px;
_height:150px;
Let me briefly explain how each browser understands these three attributes:
Under FF, FF does not recognize the second and third attributes, so it reads height:100px;
Under IE7, the third attribute IE7 doesn't recognize the attributes, so it reads the first and second attributes, and because the second attribute overwrites the first attribute, IE7 finally reads the second attribute *height:120px;
in IE6 Below, all three attributes are recognized by IE6, so all three attributes can be read. And because the third attribute overwrites the first two attributes, IE6 finally reads the third attribute.
1 CSS styles for firefox ie6 ie7
Most of them are now compatible with !important. For ie6 and firefox tests, they can be displayed normally, but ie7 can correctly interpret !important, which will cause the page not to be displayed as required. ! I found a good compatibility method for IE7 by using "* html". Now browse it with IE7. There should be no problem. Now write a CSS like this:
#1 { color: #333; } /* Moz */
* html #1 { color: #666; } /* IE6 */
* html #1 { color: #999; } /* IE*/
那么在firefox下字体颜色显示为#333,IE6下字体颜色显示为#666,IE7下字体颜色显示为#999。
2 css布局中的居中问题
主要的样式定义如下:
body {TEXT-ALIGN: center;}
#center { MARGIN-RIGHT: auto; MARGIN-LEFT: auto; }
说明:
首先在父级元素定义TEXT-ALIGN: center;这个的意思就是在父级元素内的内容居中;对于IE这样设定就已经可以了。
但在mozilla中不能居中。解决办法就是在子元素定义时候设定时再加上“MARGIN-RIGHT: auto;MARGIN-LEFT: auto; ”
需要说明的是,如果你想用这个方法使整个页面要居中,建议不要套在一个DIV里,你可以依次拆出多个div,只要在每个拆出的div里定义MARGIN-RIGHT: auto;MARGIN-LEFT: auto; 就可以了。
3 盒模型不同解释.
#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 浮动ie产生的双倍距离
#box{ float:left; width:100px; margin:0 0 0 100px; //这种情况之下IE会产生200px的距离 display:inline; //使浮动忽略}
这里细说一下block,inline两个元素,Block元素的特点是:总是在新行上开始,高度,宽度,行高,边距都可以控制(块元素);Inline元素的特点是:和其他元素在同一行上,…不可控制(内嵌元素);
#box{ display:block; //可以为内嵌元素模拟为块元素 display:inline; //实现同一行排列的的效果 diplay:table;
5 IE与宽度和高度的问题
IE不认得min-这个定义,但实际上它把正常的width和height当作有min的情况来使。这样问题就大了,如果只用宽度和高度,正常的浏览器里这两个值就不会变,如果只用min-width和min-height的话,IE下面根本等于没有设置宽度和高度。比如要设置背景图片,这个宽度是比较重要的。要解决这个问题,可以这样:
#box{ width: 80px; height: 35px;}html>body #box{ width: auto; height: auto; min-width: 80px; min-height: 35px;}
6 页面的最小宽度
min-width是个非常方便的CSS命令,它可以指定元素最小也不能小于某个宽度,这样就能保证排版一直正确。但IE不认得这个,而它实际上把 width当做最小宽度来使。为了让这一命令在IE上也能用,可以把一个
p对象中的内容
Category: Css | Add to favorites | Views (90) | Comments (0)
Previous article: IE and Firefox compatibility issues in DIV CSS web pages...