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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测