該如何選擇 background-image 和 img 標籤

用img標籤

  1. 若是你但願別人打印頁面時候包含這張圖片請使用 img 標籤
  2. 當這張圖片有很是有意義的語義,好比警告圖標,請使用img標籤及它的alt屬性。這樣意味着你能夠向全部的用戶終端現實他的意義。
  3. IE6下 背景圖片不能益出父級元素 要使用img multiple overlay images in IE6.
  4. 若是你使用動畫img動畫要比background-image 表現更好improve performance of animations over a background

何時用 CSS background-image

  1. 若是圖片不是內容的一部分使用 background-image
  2. 若是使用圖片替換文字請使用 background-image
  3. 若是你不但願別人打印頁面時候包含這張圖片請使用 background-image
  4. 若是你想改善加載時間 使用 CSS sprites
  5. 若是你只想用一張圖片的一部分 請使用 CSS sprites
  6. 用background-image 以及 background-size:cover 拉伸填充整個窗口
相關文章
相關標籤/搜索