How do I remove the gray border that surrounds background images?

前端 未结 13 1936
挽巷
挽巷 2020-12-09 01:09

I\'ve come across an interesting problem in the following line of code:

  

        
13条回答
  •  离开以前
    2020-12-09 01:36

    I know this is an old question but I found this useful..

    In the case that your Resources/bar.png is a foreground image in the form of a sprite, it makes sense to use an img tag rather than a div. When you do this it can help to have a 1px transparent image file which you use for the src attribute, then set the background image as you do here e.g.

        
    

    Here you set x and y to be the pixel position on the sprite that you want the image to start at. This technique is also explained at: http://www.w3schools.com/css/css_image_sprites.asp

    Of course the downside of this is that there is an extra request, but it you're always using the same transparent image for you sprites it's not a massive deal.

提交回复
热议问题