妄徒之命 2009-01-29 18:25 采纳率: 100%
浏览 499
已采纳

什么时候使用 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条回答 默认 最新

  • 关注

    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条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题