温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

常见的浏览器Hack技巧有哪些

发布时间:2021-08-19 13:40:20 来源:亿速云 阅读:149 作者:小新 栏目:web开发

这篇文章将为大家详细讲解有关常见的浏览器Hack技巧有哪些,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

IE Hack

IE系列浏览器的hack大略如下:

  • _nowamagic:1px;-----------ie6

  • *nowamagic:1px;-----------ie7

  • nowamagic:1px\0;----------ie89

  • nowamagic:1px\9\0;--------ie9

  • :root nowamagic:1px;    ----ie9(实际情况可能ie9还是有问题,再用这种方式)

这样就基本上就可以兼容所有IE。

常见的浏览器Hack技巧有哪些

其中粉红色部分为属性hack,黄色部分为选择器hack,它们可以结合使用。此外Firefox和Chrome也有它们专有的hack,详细hack方式及使用示例如下:

Firefox 与 Chrome 的 Hack

Firefox:

@-moz-document url-prefix()  /*写在选择器外层时(只可写在此处):Firefox 
only*/

Chrome:

@media screen and (-webkit-min-device-pixel-ratio:0)  /*写在选择器外层时(只可写在此处):Chrome only*/

使用示例:

@-moz-document url-prefix()  /*Firefox*/
{
 body
 {
 background-color:pink;
 }
}

浏览器对css的解析是从前到后的,并且采用最后一个样式声明。

CSS 实例

.color{
  background-color: #CC00FF;    /*所有浏览器都会显示为紫色*/
  background-color: #FF0000\9;  /*IE6、IE7、IE8会显示红色*/
  *background-color: #0066FF;    /*IE6、IE7会变为蓝色*/      
  _background-color: #009933;    /*IE6会变为绿色*/
}
background: red;    /* 对FF Opera和Safari有效 */
#background: blue;   /* 对 IE6 和 IE7有效 */
_background: green;   /* 只对IE6有效 */
/*/background: orange;*/   /** 只对IE8有效 **/
!important     /*FF、IE7有效*/
*     /*IE都有效*/

IE8是可以和IE7兼容的,简单一行代码,让IE8自动调用IE7的渲染模式。只需要在页面中加入如下HTTP meta-tag:<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />,只要IE8读到这个标签,它就会自动启动IE7兼容模式,保证页面完整展示。

混用起来大约是这样:

:root .demo { 
 background:#963\9; /* 仅IE9适用 */ 
} 
.demo { 
 width: 300px; 
 height: 200px; 
 background: #036; /* 所有浏览器都适用 */ 
 background: #09F\9; /* IE6~IE9 */ 
 background: #09F\0; /* IE8~IE9 */ 
 background: #09F\0/; /* IE8 */ 
 *background: #F60; /* IE6/IE7 */ 
 +background: #F60; /* IE6/IE7 */ 
 @background: #F60; /* IE6/IE7 */ 
 >background: #F60; /* IE6/IE7 */ 
 _background: #ccc; /* IE6 */ 
} 
@media all and (min-width:0) { 
 .demo { 
 background: #F06; /* webkit and opera */ 
 } 
} 
 
@media screen and (-webkit-min-device-pixel-ratio:0){ 
 .demo {background:#609;}/*webkit (& Opera9.2)*/ 
}

关于“常见的浏览器Hack技巧有哪些”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI