Tips for compatibility with various browsers_CSS/HTML

WBOY
Release: 2016-05-16 12:10:58
Original
1389 people have browsed it

1,盒解释器的不同解释.

#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-}
2,在ie中隐藏css,使用子选择器

html>body #box{     }
3,只有ie识别

*html #box{     }
4,在ie/win有效而ie/max隐藏,使用反斜杠

/* \ */
#box{ }
5,给ie单独定义样式 这里更加详细的说明

6,浮动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;   //for ff,模拟table的效果}
7,for oprea only

@media all and (min-width:0px){/* opera */#box{  }}
8,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;}
9,页面的最小宽度

min-width是个非常方便的CSS命令,它可以指定元素最小也不能小于某个宽度,这样就能保证排版一直正确。但IE不认得这个,而它实际上把width当做最小宽度来使。为了让这一命令在IE上也能用,可以把一个

放到 标签下,然后为div指定一个类:


然后CSS这样设计:
#container{  min-width: 600px;  width:expression(document.body.clientWidth < 600? "600px": "auto" );}
第一个min-width是正常的;但第2行的width使用了Javascript,这只有IE才认得,这也会让你的HTML文档不太正规。它实际上通过Javascript的判断来实现最小宽度。

同样的办法也可以为IE实现最大宽度:

#container{min-width: 600px;max-width: 1200px;width:expression(document.body.clientWidth < 600? "600px" : document.body.clientWidth > 1200? ”1200px“ : ”auto";}
10,清除浮动

.hackbox{       display:table; //将对象作为块元素级的表格显示}或者.hackbox{        clear:both;}
或者加入:after(伪对象),设置在对象后发生的内容,通常和content配合使用,IE不支持此伪对象,非Ie 浏览器支持,所以并不影响到IE/WIN浏览器。-------这种的最麻烦的......

#box:after{    content: ".";     display: block;    height: 0;     clear: both;     visibility: hidden;}
11,DIV浮动IE文本产生3象素的bug

左边对象浮动,右边采用外补丁的左边距来定位,右边对象内的文本会离左边有3px的间距.

#box{    float:left;    width:800px;}#left{    float:left;    width:50%;}#right{    width:50%;}*html #left{    margin-right:-3px;   //这句是关键}
   HTML代码

   
  

12,屬性選擇器(這個不能算是相容,是隱藏css的一個bug)

p[id]{}div[id]{}
這個對於IE6.0和IE6.0以下的版本都隱藏,FF和OPera作用

屬性選擇器和子選擇器還是有區別的,子選擇器的範圍從形式來說縮小了,屬性選擇器的範圍比較大,如p[id]中,所有p標籤中有id的都是同樣式的.

 待續...

 

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=592516

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!