網頁設計中CSS關聯調用的4種方式

來源:互聯網
上載者:User

首先介紹一下HTML文檔與CSS 的關聯常見有4種方式:
  1、使用link標記

  <link rel="stylesheet" type="text/css" href="sheet.css" />

  2、使用style元素

  <style type="text/css">

  body{background:#fff;}

  h1{font-size:12px;}

  </style>

  3、使用@import指令

  <style type="text/css">

  @import url(sheet1.css);

  @import "sheet2.css";

  </style>

  4、使用style屬性的內聯樣式(inline style)

  <p style="color:#f00;">這是紅色的字</p>

  在實際應用中,使用style屬性的內聯樣式是不推薦使用的,XHTML1.1已經將其標準為不建議使用,原因很簡單這種方式不比font標記強多少,削弱了CSS集中控制整個文檔外觀的優點。

  前3種方式利用了link標記和style標記,在IE(包括IE6、IE7和IE8 beta1)中有如下限制:

  ◆ 文檔中只有前31個link或style標記關聯的CSS能夠應用。

  從第32個開始,其標記關聯的CSS都將失效。IE的官方文檔All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer也提及這個限制,包括在使用.xsl的.xml檔案也有這個限制。但是似乎寫錯了數量。請在IE看:

  ◆ 一個style標記只有前31次@import指令有效應用。

  從第32個@import指令開始忽略。

  ◆ 一個css檔案只有前31次@import指令有效應用。

  從第31個@import指令開始忽略。

  ◆ 一個CSS檔案的不能超過288kb?

  IE對CSS的限制在絕大部分情況下是不會遇到的,即使遇到最佳的解決方案也應該是手動或者通過後端程式對CSS檔案和響應的標記進行合并,最小化的http請求數是最佳化頁面呈現的第一原則。


轉載自:http://www.xiaoer68.cn/html/142.html

相關文章

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.