多瀏覽器CSS樣式解決方案

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   使用   for   

一、CSS HACK

1、在同一個CSS樣式表中,使用 !important 來定義不同的值以適應Firefox和IE,例如:

 

#box {     color:red !important;     color:blue; }

 

 

(注意這裡IE6是無法識別 !important 這個標記的,但它會識別padding: 20px,所以要在後面加上padding: 10px用來覆蓋padding: 20px)

2、為特定瀏覽器設定特定的樣式

 

height:20px; /*For all 包括Firefox */*height:25px; /*For IE7 & IE6*/_height:20px; /*For IE6*/*+height:20px /* IE7 */

 

#someNode{    position: fixed;    /*給Firefox以及其他瀏覽器看 */   #position: fixed;    /*給IE7看 */   _position: fixed;    /*第三排給IE6以及更老的版本看*/}

*+html 與 *html 是IE特有的標籤, firefox 暫不支援。

*+html 對IE7的HACK 必須保證HTML頂部有如下聲明:

XML/HTML代碼

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

 

二、float 閉合

關於 clear float 的原理可參見 [How To Clear Floats Without Structural Markup]

將以下代碼加入Global CSS 中,給需要閉合的div加上 class="clearfix" 即可。

/* Clear Fix */.clearfix:after {  content:".";  display:block;  height:0;  clear:both;      visibility:hidden;  }  .clearfix { display:inline-block;   }/* Hide from IE Mac /*/  .clearfix { display:block; }   /* End hide from IE Mac */  /* end of clearfix */

 

待補充......

多瀏覽器CSS樣式解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.