CSS hack

来源:互联网 发布:simulink 知乎 标定 编辑:程序博客网 时间:2024/05/22 14:49

原文链接:http://www.cnblogs.com/2050/archive/2010/08/24/1807231.html

css hacks

* html selector                    /* for IE6 and below */

*+html selector                  /* for IE7 and IE5 */

*:first-child+html selector  /* for IE7 only */

html>body selector            /* for IE7+ and other standard browsers */

html>/**/ body selector   /* for not IE */

_property:value                  /* for IE6 and below */

*property:value                  /* for IE7、6、5 */

porperty:value\0/              /* for IE8 */

porperty:value\9                /* for all IE */

例子:利用CSS使高度未知的图片垂直居中:

box {
2        /*非IE的主流浏览器识别的垂直居中的方法*/
3        display: table-cell;
4        vertical-align:middle;
5
6        /*设置水平居中*/
7        text-align:center;
8
9        /* 针对IE的Hack */
10        *display: block;
11        *font-size: 175px;/*约为高度的0.873,200*0.873 约为175*/
12        *font-family:Arial;/*防止非utf-8引起的hack失效问题,如gbk编码*/
13
14        width:200px;
15        height:200px;
16        border: 1px solid #eee;
17}
18.box img {
19        /*设置图片垂直居中*/
20        vertical-align:middle;
21}
22
23<div class="box">
24        <img src="http://pics.taobao.com/bao/album/promotion/taoscars_180x95_071112_sr.jpg" />
25</div>

代码中那段“针对IE”的CSShack的写法,就是在选择器前面加了个星号!

0 0
原创粉丝点击