Home  >  Article  >  Web Front-end  >  CSS analysis of browser compatibility issues

CSS analysis of browser compatibility issues

不言
不言Original
2018-07-24 11:24:331212browse

这篇文章分享给大家的内容是关于css关于浏览器兼容问题的解析,内容很有参考价值,希望可以帮到有需要的小伙伴。

一、火狐
1. 失效
hack:采用jquery UI:datepicker插件。
(1)下载插件,放置在项目文件夹中;
(2)在所需页面引入,如:

 <script src="jslib/plugins/datepicker/bootstrap-datepicker.js"></script>

此script与页面所需的对应的js位置不分先后;
(3)点击触发pick事件,func(pic);
调用$("#datepicker").datepicker() ;
带参数的写法:

$("#datepicker").datepicker({
    numberOfMonth: 3,     // 一排3个
    numberOfMonth: [3,2], // 三排每排2个    
}) ;

二、ie8
1.圆角:border-radius失效
hack:使用一些能使ie兼容css3新属性的插件,这里介绍一下pie.htc 。
(1)下载pie.htc ;http://css3pie.com/
(2)部署在你的项目文件中,我习惯是放在js下面,不过,就像官网说的
 “It doesn't matter where exactly, as long as you know where it is.”;
(3)写样式并追加兼容,如:

a.level0 span.button {
    width:10px;
    height:10px;
    background:#999;
    border-radius:50%;
    -webkit-border-radius:50%;
    -moz-border-radius:50%;
    behavior:url(view/js/pie.htc)

    //值得注意的是,追加兼容的路径并不是相对于当前的css文件,
    //而是相对应的html/jsp文件,个人觉得官网只有说明没有示例不太好。
}

2.渐变:background-image:linear-gredient()失效
hack1:使用兼容插件。
方法同上的前两步(1)、(2)
(3)写样式并追加兼容,如:

nav{
    background:linear-gradient(#8fb8ff 0%, #fff 100%);
    background:-webkit-linear-gradient(#8fb8ff 0%, #fff 100%);
    background:-moz-linear-gradient(#8fb8ff 0%, #fff 100%);
    -pie-background: linear-gradient(#8fb8ff 0%, #fff 100%); //ie 6-9 
    behavior: url(view/js/pie.htc);
}

hack2:使用兼容语法。

background:linear-gradient(#8fb8ff 0%, #fff 100%);
background:-webkit-linear-gradient(#8fb8ff 0%, #fff 100%);
background:-moz-linear-gradient(#8fb8ff 0%, #fff 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr=
'#00000000',endColorstr='#E5000000',GradientType=0 ); 
//GradientType: 0垂直渐变 , 1水平渐变

以上两种方法杂不同的场景中都各有各的优点和缺点,在项目开发中,
可以都试一下采用兼容更好的一种即可。

3.结构伪类选择器:nth-of-type( )失效
hack:ie8支持first-child,变更一下代码。

a.level0 span:nth-of-type(1) ——>a.level0 span:first-child
a.level0 span:nth-of-type(2)——>a.level0 span:first-child+span //第二个子节点
a.level0 span:nth-of-type(3)——>a.level0 span:first-child+span+span//第三个子节点
//以此类推

4.盒子阴影:box-shadow失效
hack:pie.htc

p{
    wdith:100px;
    height:100px;
    background:#fff;
     //尽管背景是白色,最好还是设置一下,不然兼容后的效果可能会不太理想
    box-shadow:10px 10px 10p #aaa;
    behavior:url(view/js/pie.htc)
}

5.透明色rgba()失效
hack:pie.htc

.contaniner{
    width:100px;
    height:100px;
    background:rgba(0,0,0,0.5);
    -pie-background:rgba(0,0,0,0.5);
    behavior:url(view/js/pie.htc);
}

6. 有默认border
hack:在css文件中控制一下就好了,如

input[type="checkbox"] {
    border:none;
}

7.顺便介绍一下过滤器filter,filter是一种用来过滤不同浏览器的hack类型。
(1)9    :所有IE浏览器都支持
(2)0    :IE8、IE9支持,opera部分支持
(3)90  :IE8部分支持、IE9支持
(4)09  :IE8、IE9支持
如:

background:#0f0;//chrome 、firefox 显示绿色
background\0:#00f ;//ie显示蓝色

相关推荐:

JS识别浏览器类型(电脑浏览器和手机浏览器)

php判断浏览器类型,浏览器语言等信息的代码

The above is the detailed content of CSS analysis of browser compatibility issues. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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