larry*wei 2009-01-29 18:25 采纳率: 0%
浏览 323
已采纳

什么时候使用 IMG vs. CSS 背景图片?

In what situations is it more appropriate to use an HTML IMG tag to display an image, as opposed to a CSS background-image, and vice-versa?

Factors may include accessibility, browser support, dynamic content, or any kind of technical limits or usability principles.

转载于:https://stackoverflow.com/questions/492809/when-to-use-img-vs-css-background-image

  • 写回答

30条回答 默认 最新

  • 胖鸭 2009-09-23 23:58
    关注

    Proper uses of IMG

    1. Use IMG if you intend to have people print your page and you want the image to be included by default. —JayTee
    2. Use IMG (with alt text) when the image has an important semantic meaning, such as a warning icon. This ensures that the meaning of the image can be communicated in all user-agents, including screen readers.

    Pragmatic uses of IMG

    1. Use IMG plus alt attribute if the image is part of the content such as a logo or diagram or person (real person, not stock photo people). —sanchothefat
    2. Use IMG if you rely on browser scaling to render an image in proportion to text size.
    3. Use IMG for multiple overlay images in IE6.
    4. Use IMG with a z-index in order to stretch a background image to fill its entire window.
      Note, this is no longer true with CSS3 background-size; see #6 below.
    5. Using img instead of background-image can dramatically improve performance of animations over a background.

    When to use CSS background-image

    1. Use CSS background images if the image is not part of the content. —sanchothefat
    2. Use CSS background images when doing image-replacement of text eg. paragraphs/headers. —sanchothefat
    3. Use background-image if you intend to have people print your page and you do not want the image to be included by default. —JayTee
    4. Use background-image if you need to improve download times, as with CSS sprites.
    5. Use background-image if you need for only a portion of the image to be visible, as with CSS sprites.
    6. Use background-image with background-size:cover in order to stretch a background image to fill its entire window.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(29条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗