Home > Web Front-end > HTML Tutorial > [Reprint] Compatibility-related features of IE6, IE7, and FF when designing DIV CSS_html/css_WEB-ITnose

[Reprint] Compatibility-related features of IE6, IE7, and FF when designing DIV CSS_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 12:29:50
Original
1176 people have browsed it

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:

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上也能用,可以把一个

放到 标签下,然后为div指定一个类:
然后CSS这样设计:
#container{
min-width: 600px;
width:e­xpression(document.body.clientWidth < 600? “600px”: “auto” );
}
第一个min-width是正常的;但第2行的width使用了Javascript,这只有IE才认得,这也会让你的HTML文档不太正规。它实际上通过Javascript的判断来实现最小宽度。
7 清除浮动
.兼容box{
display:table;
//将对象作为块元素级的表格显示
}
或者
.兼容box{
clear:both;
}
或者加入:after(伪对象),设置在对象后发生的内容,通常和content配合使用,IE不支持此伪对象,非Ie 浏览器支持,所以并不影响到IE/WIN浏览器。这种的最麻烦的
……#box:after{
content: “.”;
display: block;
height: 0;
clear: both;
visibility: hidden;
}
8 DIV浮动IE文本产生3象素的bug
左边对象浮动,右边采用外补丁的左边距来定位,右边对象内的文本会离左边有3px的间距.
#box{
float:left;
width:800px;}
#left{
float:left;
width:50%;}
#right{
width:50%;
}
*html #left{
margin-right:-3px;
//这句是关键
}
HTML代码




9 属性选择器(这个不能算是兼容,是隐藏css的一个bug)
p[id]{}div[id]{}
p[id]{}div[id]{}
这个对于IE6.0和IE6.0以下的版本都隐藏,FF和OPera作用
属性选择器和子选择器还是有区别的,子选择器的范围从形式来说缩小了,属性选择器的范围比较大,如p[id]中,所有p标签中有id的都是同样式的.
10 IE捉迷藏的问题
当div应用复杂的时候每个栏中又有一些链接,DIV等这个时候容易发生捉迷藏的问题。
有些内容显示不出来,当鼠标选择这个区域是发现内容确实在页面。
解决办法:对#layout使用line-height属性 或者给#layout使用固定高和宽。页面结构尽量简单。
11 高度不适应
高度不适应是当内层对象的高度发生变化时外层高度不能自动进行调节,特别是当内层对象使用
margin 或paddign 时。例:

p对象中的内容



CSS:
#box {background-color:#eee; }
#box p {margin-top: 20px; margin-bottom: 20px; text-align:center; }
Solution Method: Add 2 empty div objects above and below the P object. CSS code: .1{height:0px;overflow:hidden;} or add the border attribute to the DIV.
Block IE browser (that is, it will not be displayed in IE)
*:lang(zh) select {font:12px !important;} /*FF, OP visible*/
select:empty {font: 12px !important;} /*visible in safari*/
Here select is the selector, which can be changed according to the situation. The second sentence is unique to the Safari browser on MAC.
Only recognized by IE7
* html {…}
You can use this compatibility when you need to make styles only for IE7.
Identification of IE6 and below
* html {…}
Pay special attention to this place. Many landlords have written that it is compatible with IE6. In fact, IE5.x can also recognize this compatibility. Other browsers do not recognize it.
html/**/ >body select {……}
This sentence has the same effect as the previous sentence.
Only IE6 does not recognize it
select { display /*IE6 does not recognize it*/:none;}
Here mainly separates an attribute and value through CSS comments, which are released before the colon.
Only IE6 and IE5 do not recognize it
select/**/ { display /*IE6, IE5 does not recognize*/:none;}
The difference here from the above sentence is that there is an additional CSS comment between the selector and the curly braces.
Only IE5 does not recognize it
select/*IE5 does not recognize it*/ { display:none;}
This sentence is the comment in the attribute area removed 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;}
box model The clearing method is not handled through !important. This needs to be clear.
Clear float
select:after {content:"."; display:block; height:0; clear:both; visibility:hidden;}
In Firefox, when the children are all floats, Then the height of the parent cannot completely cover the entire child. Then use this clear floating compatibility to define the parent once, then this problem can be solved.
Truncating ellipsis
select { -o-text-overflow:ellipsis; text-overflow:ellipsis; white-space:nowrapoverflow:hidden; }
This will be truncated automatically after exceeding the length It is a good technique to add extra text and end it with an ellipsis. It's just that Firefox doesn't support it currently.
Only recognized by Opera
@media all and (min-width: 0px){ select {……} }
Make separate settings for Opera browser.
The above are some compatibility in writing CSS. It is recommended to follow the correct tag nesting (div ul li nested structure relationship). This can reduce the frequency of using compatibility and avoid misunderstandings. It is not required for just one page. A lot of compatibility to maintain multi-browser compatibility). In many cases, the browser may work very well without using any compatibility. These are used to solve local compatibility problems. If you want to separate the compatibility content, Come out and try some of the 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 required patch styles through conditions.
Filter for IE5.x, only IE5.x is visible
@media tty {
i{content:"";/*" "*/}} @import 'ie5win.css'; /* ";}
}/* */
IE5/MAC filters are generally not needed
/**//*/
@import "ie5mac.css";
/ **/
The following is the conditional comment of IE. I personally think that using conditional comments to call the corresponding compatibility is a perfect solution for multi-browser compatibility. Put the parts that need compatibility into a separate file, and when the browser version is consistent. You can call the compatible style when using it, which is not only very convenient to use, but also allows you to more strictly observe whether it is necessary to use compatibility when making the CSS itself. In many cases, when I write CSS, if I When all the code including compatibility is written into a CSS file, it will be very casual, and it can be compatible as much as you want. But when you write it independently, you will unconsciously consider whether it is necessary to be compatible. Should you be compatible with CSS first? Or should you first adjust things in the main CSS so that they don’t require compatibility as much as possible? When you can make many browsers behave well with only a small amount of compatibility, do you feel a sense of accomplishment? Do you know how to choose? Come on~~ Haha
IE’s if condition is compatible and you can use it flexibly. Please refer to this IE condition comment
Only IE
All IE can recognize it
Only IE5.0 can recognize it
Only IE 5.0
Can be recognized by IE5.0 or IE5.5
Only IE6 can be recognized
Only IE 7/-
IE6 and IE5.x below IE6 can be recognized
Only IE 7 /-
Only recognized by IE7
There are many things in CSS that will make you very upset if they do not follow certain rules. Although you can control it through a lot of compatibility and a lot of !important, you will find that you will be very unwilling to do so in the long run. Take a look Aren't you envious of the many excellent websites whose CSS makes IE6, Ie7, Firefox, and even Safari and Opera run flawlessly? And their seemingly complex templates use very little compatibility. In fact, you have to know that IE and Firefox are not so disharmonious. We can find a certain method to make them coexist harmoniously. Don't think that if you find a compatible method, you have mastered everything. We are not slaves to compatibility.
The nesting order of div ul li
Only one rule will be discussed today. It is the triangular relationship of
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template