关于网站建设方面的css+div hack兼容问题的讨论
屏蔽ie浏览器(ie下不显示)
example source code [www.sl99.net]
*:lang(zh) select {font:12px !important;} /*ff,op可见*/
select:empty {font:12px !important;} /*safari可见*/
这里select是选择符,根据情况更换。第二句是mac上safari浏览器独有的。
仅ie7识别
example source code [www.sl99.net]
* html {…}
当面临需要只针对ie7做样式的时候就可以采用这个hack。
ie6及ie6以下识别
example source code [www.sl99.net]
* html {…}
这个地方要非凡注重很多地主都写了是ie6的hack其实ie5.x同样可以识别这个hack。其它浏览器不识别。
html/**/ >body select {…}
这句与上一句的作用相同。
仅ie6不识别,屏蔽ie6
example source code [www.sl99.net]
select { display /*屏蔽ie6*/:none;}
这里主要是通过css注释分开一个属性与值,注释在冒号前。
仅ie6与ie5不识别,屏蔽ie6与ie5
example source code [www.sl99.net]
select/**/ { display /*ie6,ie5不识别*/:none;}
这里与上面一句不同的是在选择符与花括号之间多了一个css注释。不屏蔽ie5.5
仅ie5不识别,屏蔽ie5
example source code [www.sl99.net]
select/*ie5不识别*/ {…}
这一句是在上一句中去掉了属性区的注释。只有ie5不识别,ie5.5可以识别。
盒模型解决方法
example source code [www.sl99.net]
selct {width:ie5.x宽度; voice-family :\}\; voice-family:inherit; width:正确宽度;}
盒模型的清除方法不是通过!important来处理的。这点要明确。
清除浮动
example source code [www.sl99.net]
select:after {content:.; display:block; height:0; clear:both; visibility:hidden;}
在firefox中,当子级都为浮动时,那么父级的高度就无法完全的包住整个子级,那么这时用这个清除浮动的hack来对父级做一次定义,那么就可以解决这个问题。
截字省略号
example source code [www.sl99.net]
select { -o-text-overflow:ellipsis; text-overflow:ellipsis; white-space:nowrap; overflow:hidden; }
这个是在越出长度后会自行的截掉多出部分的文字,并以省略号结尾,很好的一个技术。只是目前firefox并不支持。
只有opera识别
example source code [www.sl99.net]
@media all and (min-width: 0px){ select {……} }
针对opera浏览器做单独的设定。
以上都是写css中的一些hack,这些都是用来解决局部的兼容性问题,假如希望把兼容性的内容也分离出来,不妨试一下下面的几种过滤器。这些过滤器有的是写在css中通过过滤器导入非凡的样式,也有的是写在html中的通过条件来链接或是导入需要的补丁样式。
ie5.x的过滤器,只有ie5.x可见
example source code [www.sl99.net]
@media tty {
i{content:\;/* */}} @import 'ie5win.css'; /*;}
}/* */
ie5/mac的过滤器,一般用不着
example source code [www.sl99.net]
/*\*//*/
@import ie5mac.css;
/**/
ie的if条件hack
example source code [www.sl99.net]
only ie
所有的ie可识别
只有ie5.0可以识别
only ie 5.0
ie5.0包换ie5.5都可以识别
仅ie6可识别
only ie 6/
ie6以及ie6以下的ie5.x都可识别
only ie 7/-
仅ie7可识别