Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

  <img style="background-image:url(Resources/bar.png); width: 300px; height: 50px;"/> 

In Safari (at least), a gray border surrounds the 300x50px area. Adding style="border: none;" doesn't remove it. Any ideas?

Thanks. Mike

like image 332
Michael Swarts Avatar asked Jul 02 '09 07:07

Michael Swarts


People also ask

How do you remove borders from photos?

Remove a border from a picture Select the picture whose border you want to remove. On the Page Layout tab, in the Page Background group, select Page Borders. Click the Borders tab. Under Setting, select None.

How do I remove the border from an image in CSS?

Adding border="0" to your img tag prevents that picture from having a border around the image. However, adding border="0" to every image would not only be time consuming but also increase the file size and download time. To prevent all images from having a border, create a CSS rule or file with the following code.


2 Answers

So, you have an img element that doesn't have a src attribute, but it does have a background-image style applied.

I'd say that the gray border is the 'placeholder' for where the image would be, if you'd specified a src attribute.

If you don't want a 'foreground' image, then don't use an img tag - you've already stated that changing to a div solves the problem, why not go with that solution?

like image 60
belugabob Avatar answered Oct 11 '22 14:10

belugabob


You can also add a blank image as a place holder:

img.src='data:image/png;base64,R0lGODlhFAAUAIAAAP///wAAACH5BAEAAAAALAAAAAAUABQAAAIRhI+py+0Po5y02ouz3rz7rxUAOw==' 

This should do the trick!

like image 40
user424540 Avatar answered Oct 11 '22 12:10

user424540