Home Web Front-end CSS Tutorial CSS analysis of browser compatibility issues

CSS analysis of browser compatibility issues

Jul 24, 2018 am 11:24 AM
css html

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

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

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

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

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

二、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文件,个人觉得官网只有说明没有示例不太好。
}
Copy after login

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);
}
Copy after login

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水平渐变
Copy after login

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

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//第三个子节点
//以此类推
Copy after login

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)
}
Copy after login

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);
}
Copy after login

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

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

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显示蓝色
Copy after login

相关推荐:

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1658
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
How to use bootstrap in vue How to use bootstrap in vue Apr 07, 2025 pm 11:33 PM

Using Bootstrap in Vue.js is divided into five steps: Install Bootstrap. Import Bootstrap in main.js. Use the Bootstrap component directly in the template. Optional: Custom style. Optional: Use plug-ins.

Understanding HTML, CSS, and JavaScript: A Beginner's Guide Understanding HTML, CSS, and JavaScript: A Beginner's Guide Apr 12, 2025 am 12:02 AM

WebdevelopmentreliesonHTML,CSS,andJavaScript:1)HTMLstructurescontent,2)CSSstylesit,and3)JavaScriptaddsinteractivity,formingthebasisofmodernwebexperiences.

The Roles of HTML, CSS, and JavaScript: Core Responsibilities The Roles of HTML, CSS, and JavaScript: Core Responsibilities Apr 08, 2025 pm 07:05 PM

HTML defines the web structure, CSS is responsible for style and layout, and JavaScript gives dynamic interaction. The three perform their duties in web development and jointly build a colorful website.

React's Role in HTML: Enhancing User Experience React's Role in HTML: Enhancing User Experience Apr 09, 2025 am 12:11 AM

React combines JSX and HTML to improve user experience. 1) JSX embeds HTML to make development more intuitive. 2) The virtual DOM mechanism optimizes performance and reduces DOM operations. 3) Component-based management UI to improve maintainability. 4) State management and event processing enhance interactivity.

How to insert pictures on bootstrap How to insert pictures on bootstrap Apr 07, 2025 pm 03:30 PM

There are several ways to insert images in Bootstrap: insert images directly, using the HTML img tag. With the Bootstrap image component, you can provide responsive images and more styles. Set the image size, use the img-fluid class to make the image adaptable. Set the border, using the img-bordered class. Set the rounded corners and use the img-rounded class. Set the shadow, use the shadow class. Resize and position the image, using CSS style. Using the background image, use the background-image CSS property.

How to write split lines on bootstrap How to write split lines on bootstrap Apr 07, 2025 pm 03:12 PM

There are two ways to create a Bootstrap split line: using the tag, which creates a horizontal split line. Use the CSS border property to create custom style split lines.

How to set up the framework for bootstrap How to set up the framework for bootstrap Apr 07, 2025 pm 03:27 PM

To set up the Bootstrap framework, you need to follow these steps: 1. Reference the Bootstrap file via CDN; 2. Download and host the file on your own server; 3. Include the Bootstrap file in HTML; 4. Compile Sass/Less as needed; 5. Import a custom file (optional). Once setup is complete, you can use Bootstrap's grid systems, components, and styles to create responsive websites and applications.

How to resize bootstrap How to resize bootstrap Apr 07, 2025 pm 03:18 PM

To adjust the size of elements in Bootstrap, you can use the dimension class, which includes: adjusting width: .col-, .w-, .mw-adjust height: .h-, .min-h-, .max-h-

See all articles