Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background-Image in <img> element

Tags:

html

css

Can someone help me to find my Problem ? I have a <img /> and will give him a background-image within a <a> tag.

Here is my example:

<img border="0" style="display:block; width:20px; height:20px; background-color:red; padding:9px; background:url(\'./images/system/button/close/close.png)\' no-repeat" />

Background-Color didn't work to.. :-( My Example is a JavaScript String, thats the reason why I'm escaping the URL

Thank's for help :-)

like image 445
Patrik Avatar asked Oct 19 '10 10:10

Patrik


People also ask

Can an IMG tag have a background image?

HTML <img> Tag When you want to be indexed by the search engine. Google doesn't index background images automatically. Browsers don't provide any information on background images to assistive technology. But using the <img> tag with the alt and title attributes will help to be recognised by screen readers.

How do I add a background image to an element?

The background-image property sets one or more background images for an element. By default, a background-image is placed at the top-left corner of an element, and repeated both vertically and horizontally.

What is the difference between using a background image and using the IMG element?

Use IMG if you rely on browser scaling to render an image in proportion to text size. Use IMG for multiple overlay images in IE6. Use IMG with a z-index in order to stretch a background image to fill its entire window.

Can you put a background image in a div?

Say you want to put an image or two on a webpage. One way is to use the background-image CSS property. This property applies one or more background images to an element, like a <div> , as the documentation explains.


1 Answers

you dont even need the quote marks.

background:url(./images/system/button/close/close.png)

use a div if you can

<div style="height:20px; width:20px; padding:9px; background:url(./images/system/button/close/close.png) no-repeat red"></div>
like image 65
Rocket Ronnie Avatar answered Oct 15 '22 01:10

Rocket Ronnie