Best way to display default image if specified image file is not found?

后端 未结 6 2039
清歌不尽
清歌不尽 2021-02-04 06:12

I\'ve got your average e-Commerce app, I store ITEM_IMAGE_NAME in the database, and sometimes managers MISSPELL the image name.

To avoid \"missing images\" (red X in IE

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-04 07:06

    
    
    
    

    If missing.png loads, it will cover the space allocated for it, as if the fallback were not specified. (Assuming it's not transparent.)

    If missing.png fails to load, the space will instead be filled with fallback.png. You'll still get a little "broken image" icon, but I prefer it that way... a little hint that says "fix me".

    If your images aren't all the same size, you'll notice that the background tiles by default. You can use background-repeat: no-repeat; if you don't like that.

提交回复
热议问题