CSS hack

针对不同的浏览器写不同的CSS code的过程,就叫CSS hack!

1、!important 

随着IE7对!important的支持, !important 方法现在只针对IE6的HACK.(注意写法.记得该声明位置需要提前.) (另外必须在html开头加上doctype)

2、*+html和*html 

  *html只有IE6能认出来

  *+html只有IE7能认出来

  例如:

#inn{
background-color:silver;
}
*+html #inn{
background-color:green;
}
*html #inn{
background-color:red;
}

 其他技巧:

1, FF下给 div 设置 padding 后会导致 width 和 height 增加, 但IE不会.(可用!important解决) 
2, 居中问题. 
1).垂直居中.将 line-height 设置为 当前 div 相同的高度, 再通过 vertical-align: middle.( 注意内容不要换行.) 

2).水平居中. margin: 0 auto;(当然不是万能) 

3, 若需给 a 标签内内容加上 样式, 需要设置 display: block;(常见于导航标签) (没理解)

4, FF 和 IE 对 BOX 理解的差异导致相差 2px 的还有设为 float的div在ie下 margin加倍等问题. 
5, ul 标签在 FF 下面默认有 list-style 和 padding . 最好事先声明, 以避免不必要的麻烦. (常见于导航标签和内容列表) 
6, 作为外部 wrapper 的 div 不要定死高度, 最好还加上 overflow: hidden.以达到高度自适应. 
7, 关于手形光标. cursor: pointer. 而hand 只适用于 IE. (pointer所有浏览器都可以,如果设置时hand,必须是IE9之下的才行)

附加:*加上某个属性表示只有IE能认出来

例如:*padding-left:10px;只有IE能识别,其他的不行.

IE6识别*和_, 不识别 !important 
IE7识别*, 不识别_,识别 !important 
而firefox两个都不识别, 识别 !important

 

posted @ 2012-09-20 16:42  wcp_spring  阅读(193)  评论(0)    收藏  举报