Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example of Hack compatible code in CSS

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

这篇文章给大家分享的是有关CSS中Hack兼容的代码示例的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

1、屏蔽IE浏览器(也就是IE下不显示)

*:lang(zh) select {font:12px !important;} /*FF的专用*/

select:empty {font:12px !important;} /*safari可见*/

这里select是选择符,根据情况更换。第二句是MAC上safari浏览器独有的。

2、仅IE7识别hack

*+html {…}

当面临需要只针对IE7做样式的时候就可以采用这个HACK。

3、IE6及IE6以下识别CSS HACK

* html {…}

这个地方要特别注意很多地主都写了是IE6的HACK其实IE5.x同样可以识别这个HACK。其它浏览器不识别。

html/**/ >body select {……}

这句与上一句的作用相同。

4、仅IE6不识别div hack

select { display /*IE6不识别*/:none;}

这里主要是通过CSS注释分开一个属性与值,流释在冒号前。

5、仅IE6识别支持

.yangshi{_height:20px;}

这里IE6支持识别CSS属性前"_"短下划线。

6、仅IE6与IE5不识别

select/**/ { display /*IE6,IE5不识别*/:none;}

这里与上面一句不同的是在选择符与花括号之间多了一个CSS注释。

7、仅IE5不识别

select/*IE5不识别*/ { display:none;}

这一句是在上一句中去掉了属性区的注释。只有IE5不识别

8、盒模型解决方法

selct {width:IE5.x宽度; voice-family :"\"}\""; voice-family:inherit; width:正确宽度;}

盒模型的清除方法不是通过!important来处理的。这点要明确。

9、清除浮动

select:after {content:"."; display:block; height:0; clear:both; visibility:hidden;}

在Firefox中,当子级都为浮动时,那么父级的高度就无法完全的包住整个子级,那么这时用这个清除浮动的HACK来对父级做一次定义,那么就可以解决这个问题 。

10、截字省略号

select { -o-text-overflow:ellipsis; text-overflow:ellipsis; white-space:nowrap; overflow:hidden; }

这个是在越出长度后会自行的截掉多出部分的文字,并以省略号结尾,很好的一个技术。只是目前Firefox并不支持。

11、只有Opera识别

@media all and (min-width: 0px){ select {……} }

针对Opera浏览器做单独的设定。

以上都是写CSS中的一些HACK,这些都是用来解决局部的兼容性问题,如果希望把兼容性的内容也分离出来,不妨试一下下面的几种过滤器。这些过滤器有的是写在CSS中通过过滤器导入特别的样式,也有的是写在HTML中的通过条件来链接或是导入需要的补丁样式。

12、IE的if条件Hack

所有的IE可识别

只有IE5.0可以识别

IE5.0包换IE5.5都可以识别

仅IE6可识别

IE6以及IE6以下的IE5.x都可识别

仅IE7可识别

13、仅IE8兼容识别

div{height:20px\9;}

这里的"\9"仅IE8支持识别感谢各位的阅读!关于"CSS中Hack兼容的代码示例"这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report