博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CSS Hack大全-可区分出IE6-IE10、FireFox、Chrome、Opera
阅读量:7072 次
发布时间:2019-06-28

本文共 1849 字,大约阅读时间需要 6 分钟。

今天把一些常用的CSS Hack整理了一下,包括常用的IE hack以及火狐、Chrome、Opera浏览器的Hack,并把这些CSS Hack综合的一起,写了一个小的浏览器测试器。如图所示:

下面就来看一下代码吧:

html部分:

1
2
3
4
5
6
7
8
9
10
11
12
13
<
div
class
=
"content"
>
    
<
div
class
=
"test"
></
div
>
    
<
div
class
=
"txt"
>
        
<
p
>IE6下背景颜色:<
span
class
=
"ie6"
style
=
"background-color: #ccc;"
>#ccc</
span
></
p
>
        
<
p
>IE7下背景颜色:<
span
class
=
"ie7"
style
=
"background-color: #666;"
>#666</
span
></
p
>
        
<
p
>IE8下背景颜色:<
span
class
=
"ie8"
style
=
"background-color: #06f;"
>#06f</
span
></
p
>
        
<
p
>IE9下背景颜色:<
span
class
=
"ie9"
style
=
"background-color: #f00;"
>#f00</
span
></
p
>
        
<
p
>IE10下背景颜色:<
span
class
=
"ie10"
style
=
"background-color: #0ff;"
>#0ff</
span
></
p
>
        
<
p
>webkit,Safari,Chrome下背景颜色:<
span
class
=
"webkit-safari-gg"
style
=
"background-color: #ff0;"
>#ff0</
span
></
p
>
        
<
p
>FireFox下背景颜色:<
span
class
=
"firefox"
style
=
"background-color: #f0f;"
>#f0f</
span
></
p
>
        
<
p
>Opera下背景颜色:<
span
class
=
"opera"
style
=
"background-color: #0f0;"
>#0f0</
span
></
p
>
    
</
div
>
</
div
>

CSS部分,此部分就只贴Hack部分的代码吧,布局的就不贴了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
.content .test {
    
width
:
200px
;
    
height
:
200px
;
    
background
:
#f60
;
/*all*/
    
background
:
#06f9
;
/*IE*/
    
*
background
:
#666
;
/*IE6,7*/
    
_background
:
#ccc
;
/*IE6*/
}
    
/* webkit and opera */
@media
all
and (
min-width
:
0
){
    
.content .test {
        
background
:
#0f0
;
    
}
}
    
/* webkit */
@media
screen
and (-webkit-min-device-pixel-ratio:
0
) {
    
.content .test {
        
background
:
#ff0
;
    
}
}
    
/*FireFox*/
@-moz-document url-prefix() {
    
.content .test {
        
background
:
#f0f
;
    
}
}
    
/*IE9+*/
@media
all
and (
min-width
:
0
) {
    
.content .test{
        
background
:
#f009
;
        
}
}
    
/*IE10+*/
@media
screen
and (-ms-high-contrast: active), (-ms-high-contrast:
none
) {
    
.content .test {
        
background
:
#0ff
;
    
}
}

下面是在线演示以及源码下载:

    

转载地址:http://clzml.baihongyu.com/

你可能感兴趣的文章
MySQL Workbench关键字转成小写设置
查看>>
[转]如何写出线程安全的类和函数
查看>>
将手机替换为*号
查看>>
加密算法(对称加密)AES、DES (非对称加密)RSA、DSA
查看>>
【Dalston】【第六章】API服务网关(Zuul) 下
查看>>
Windows上SSH服务器的配置以及客户端的连接
查看>>
『PyTorch x TensorFlow』第八弹_基本nn.Module层函数
查看>>
PHP数字字符串左侧补0、字符串填充和自动补齐的几种方法
查看>>
教你一步步composer安装Magento2.3
查看>>
JSON方式封装通信接口
查看>>
Spark进阶之路-Spark提交Jar包执行
查看>>
串口发送数据速度
查看>>
登录功能测试点
查看>>
vue项目ide(vue项目环境搭建)
查看>>
传统企业触网的战略--借助电商外包
查看>>
本周ASP.NET英文技术文章推荐[06/10 - 06/16]
查看>>
匈奴的历史简述
查看>>
【自然框架之SSO】实现SSO的一个初步想法
查看>>
Can't create/write to file '/tmp/MLjnvU95' (Errcode: 13 - Permission denied)
查看>>
[iphone-cocos2d]关于Loading的若干处理和讨论
查看>>