一些常用的CSS hack代碼

一.清零代碼:因爲不同的瀏覽器,默認的初始值是不同的,用清零代碼把這些默認值高置爲0是很有必要的。

  1. body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, fieldset, legend, input, button, textarea, p, blockquote, th, td { 
  2. margin: 0; 
  3. padding: 0; 

二.clearfix:如果有一個DIV作爲外部容器,內部的DIV如果設置了float樣式,則外部的容器DIV因爲內部沒有 clear,導致不能被撐開。可用如下代碼解決。

  1. .clearfix:after{ 
  2.     content:"."; 
  3.     display:block; 
  4.     height:0; 
  5.     clear:both; 
  6.     visibility:hidden; 
  7.  
  8. * html .clearfix{ 
  9.     height:1%; 

三.ie6不支持position:fixed;的BUG;

  1. /* 除IE6瀏覽器的通用方法 */ 
  2. .ie6fixedTL{position:fixed;left:0;top:0} 
  3. .ie6fixedBR{position:fixed;right:0;bottom:0} 
  4. /* IE6瀏覽器的特有方法 */ 
  5. /* 修正IE6振動bug */ 
  6. * html,* html body{background-image:url(about:blank);background-attachment:fixed} 
  7. * html .ie6fixedTL{position:absolute;left:expression(eval(document.documentElement.scrollLeft));top:expression(eval(document.documentElement.scrollTop))} 
  8. * html .ie6fixedBR{position:absolute;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)))} 

四.ie6不支持max-width、max-height、min-width、min-height的BUG。

 

  1. _width:expression((documentElement.clientWidth < 500) ? "500px" : "auto" );//實現min-width 
  2. _width:expression((documentElement.clientWidth >500) ? "500px" : "auto" );//實現max-width 
  3. _height:expression((documentElement.clientHeight<500) ? "500px" :"auto");//實現min-height 
  4. _height:expression((documentElement.clientHeight>500) ? "500px" :"auto");//實現max-height 


 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章