当前位置: 首页 > news >正文

几个常用的CSS3样式代码以及不兼容的解决办法

  • border-radius实现圆角效果

    view source print ?
    1. 1 CSS3代码:
    2. 2
    3. 3 -webkit-border-radius:10px;
    4. 4 -moz-border-radius:10px;
    5. 5 border-radius:10px;
    6. 6  margin: 0px; padding: 0px; border: 0px; outline: 0px; float: none; vertical-align: baseline; position: static; left: auto; top: auto; right: auto; bottom: auto; height: auto; width: auto; font-family: 'Courier New', 宋体; background: none;">666;
    7. 7 width:200px;height:100px;

    Firefox,Chrome Google,Safari等浏览器的显示效果如图0-0:

    \

                         图0-0

    但是IE这个异类不支持CSS3的这个属性,在IE9下的显示效果如图0-1:

    \

                         图0-1

    但是不能放任它不管,还是找办法解决这个兼容性问题。

    解决方案:在CSS文件中通过behavior属性——这个属性只能被IE识别,引入一个htc文件, ie-css3.htc

    这个是由Remiz Rahnas使用 VML 编写了一个 HTC 文件,为 IE 浏览器提供圆角效果的支持。

    view source print ?
    01. 1 div{
    02. 2     -webkit-border-radius:10p;
    03. 3     -moz-border-radius:10px;
    04. 4     border-radius:10px;
    05. 5      margin: 0px; padding: 0px; border: 0px; outline: 0px; float: none; vertical-align: baseline; position: static; left: auto; top: auto; right: auto; bottom: auto; height: auto; width: auto; font-family: 'Courier New', 宋体; background: none;">666;
    06. 6     width:200px;
    07. 7     height:100px;
    08. 8     color:#fff;
    09. 9     behavior: url(ie-css3.htc);
    10. 10 }

    截两幅图看看效果,一幅来自IE6,一幅来自IE9:

    \                                             \

                                                                                                                                                                         

    注意:首先,在 Server 端需要引入一个 HTC 文件,经过 gzip 压缩后对 server 端和 client 端性能应该不会有太大的影响;其次,它会使你的 CSS 验证不合法;另外,这个脚本在 IE8 上有一些问题,它会使 z-index 值变成负数。因此使用时还需要小心.

    box-shadow实现阴影效果

    view source print ?
    01. 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    02. 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    03. 3 <head>
    04. 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    05. 5     <title></title>
    06. 6     <style type="text/css">
    07. 7         div img{
    08. 8             
    09. 9             -webkit-box-shadow:5px 5px 5px #000;
    10. 10             -moz-box-shadow:5px 5px 5px #000;
    11. 11             box-shadow:5px 5px 5px #000;
    12. 12             width:295px;
    13. 13             height:300px;
    14. 14             /* For IE 8 */
    15. 15             -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=8, Direction=135, Color='#000000')";
    16. 16             /* For IE 5.5 - 7 */
    17. 17             filter: progid:DXImageTransform.Microsoft.Shadow(Strength=8, Direction=135, Color='#000000');
    18. 18         }
    19. 19     </style>
    20. 20 </head>
    21. 21 <body>
    22. 22     <div>
    23. 23         <img src="beautiful.jpg">
    24. 24     </div>
    25. 25 </body>
    26. 26 </html>

    Chrome,Firefox,IE9下的效果显示:

    \

    接下来要做的事情,想必读者朋友都知道了,兼容IE6-8。首先想到的IE的滤镜。来看看效果吧。

    view source print ?
    01. 1 加上滤镜之后的代码片段:
    02. 2
    03. 3 div img{
    04. 4             
    05. 5             -webkit-box-shadow:5px 5px 5px #000;
    06. 6             -moz-box-shadow:5px 5px 5px #000;
    07. 7             box-shadow:5px 5px 5px #000;
    08. 8             width:295px;
    09. 9             height:300px;
    10. 10             /* For IE 8 */
    11. 11             -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=8, Direction=135, Color='#000000')";
    12. 12             /* For IE 5.5 - 7 */
    13. 13             filter: progid:DXImageTransform.Microsoft.Shadow(Strength=8, Direction=135, Color='#000000');
    14. 14         }

    测试之后的效果,分别是IE5.5-IE8:

    \

    虽然差强人意,但凑合着用。如果有朋友知道除此之外的方法,能否告知一声,共同进步嘛!^_^

    opacity实现透明度效果

    view source print ?
    01. 1 div img{
    02. 2     width:295px;
    03. 3     height:300px;
    04. 4     -webkit-opacity:0.3;
    05. 5     -moz-opacity:0.3;
    06. 6     opacity: 0.3;
    07. 7     /*for IE 6,7,8*/
    08. 8     filter:alpha(opacity=30);
    09. 9     border:1px solid #ccc;
    10. 10 }

    兼容IE 6,7,8。效果(来自IE6):

    \

    transform:rotate(度数) 将元素旋转X度

    view source print ?
    01. 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    02. 2 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    03. 3 <head>
    04. 4     <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    05. 5     <title></title>
    06. 6     <style type="text/css">
    07. 7         div {
    08. 8            
    09. 9             width:150px;
    10. 10             height:50px;
    11. 11             margin: 50px;
    12. 12             -webkit-transform:rotate(7deg);
    13. 13             -moz-transform:rotate(7deg);
    14. 14             -ms-transform:rotate(7deg);
    15. 15             -o-transform:rotate(7deg);
    16. 16             transform:rotate(7deg);
    17. 17               border:1px solid #ccc;
    18. 18         }
    19. 19     </style>
    20. 20 </head>
    21. 21 <body>
    22. 22     <div>
    23. 23        
    24. 24     </div>
    25. 25 </body>
    26. 26 </html>

    让我们来去W3C看看transform的兼容性:

    浏览器及其版本的支持,但是IE6,7,8呢?俗话说,兵来将挡,水来土掩,山人自有妙计,只不过这妙计是借来的。

转载于:https://www.cnblogs.com/hubl/p/5750552.html

相关文章:

  • 报个到
  • iOS: NSArray的方法arrayByAddingObjectsFromArray:
  • excel转化为Json
  • dispatch_after 导致controller没有及时释放
  • poj 2763: [JLOI2011]飞行路线(spfa分层图最短路)
  • uboot 第三天学习
  • 数学概念的理解
  • 深入浅出UML类图(一)
  • ECharts图表的小工具
  • URL不受支持的解决
  • 第三方接入小记
  • 浅述WinForm多线程编程与Control.Invoke的应用
  • 容器和泛型
  • 在Java中、、三者的区别
  • maven 安装本地jar包到本地maven仓库
  • “寒冬”下的金三银四跳槽季来了,帮你客观分析一下局面
  • 《Java编程思想》读书笔记-对象导论
  • 77. Combinations
  • Cumulo 的 ClojureScript 模块已经成型
  • Fabric架构演变之路
  • JavaScript DOM 10 - 滚动
  • Java比较器对数组,集合排序
  • leetcode98. Validate Binary Search Tree
  • Linux链接文件
  • Sass 快速入门教程
  • 电商搜索引擎的架构设计和性能优化
  • 简单数学运算程序(不定期更新)
  • 坑!为什么View.startAnimation不起作用?
  • 快速体验 Sentinel 集群限流功能,只需简单几步
  • 码农张的Bug人生 - 见面之礼
  • 深入浅出Node.js
  • 推荐一款sublime text 3 支持JSX和es201x 代码格式化的插件
  • 用简单代码看卷积组块发展
  • 中国人寿如何基于容器搭建金融PaaS云平台
  • ​VRRP 虚拟路由冗余协议(华为)
  • #【QT 5 调试软件后,发布相关:软件生成exe文件 + 文件打包】
  • #鸿蒙生态创新中心#揭幕仪式在深圳湾科技生态园举行
  • (1/2)敏捷实践指南 Agile Practice Guide ([美] Project Management institute 著)
  • (2)(2.4) TerraRanger Tower/Tower EVO(360度)
  • (pojstep1.1.1)poj 1298(直叙式模拟)
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (编译到47%失败)to be deleted
  • (附源码)springboot掌上博客系统 毕业设计063131
  • (附源码)计算机毕业设计SSM基于java的云顶博客系统
  • (企业 / 公司项目)前端使用pingyin-pro将汉字转成拼音
  • (一)Mocha源码阅读: 项目结构及命令行启动
  • (转)Google的Objective-C编码规范
  • .bat批处理(一):@echo off
  • .desktop 桌面快捷_Linux桌面环境那么多,这几款优秀的任你选
  • .NET 8 中引入新的 IHostedLifecycleService 接口 实现定时任务
  • .net core 实现redis分片_基于 Redis 的分布式任务调度框架 earth-frost
  • .NET Project Open Day(2011.11.13)
  • .NET Standard / dotnet-core / net472 —— .NET 究竟应该如何大小写?
  • /dev/VolGroup00/LogVol00:unexpected inconsistency;run fsck manually
  • [ CTF ]【天格】战队WriteUp- 2022年第三届“网鼎杯”网络安全大赛(青龙组)