Login | Register | FAQ
Anonymous

Can I use background image within <img> tag?

+ Post a reply

1, 2


Can I use background image within <img> tag?

by Voucher Codes » Wed Mar 02, 2011 1:52 pm

Can I use background-image within the <img> tag to get an overlay effect as in the code below?

<img style="background-image:url(freegifts.gif)" src="new.gif" alt="image" width="72" height="73" />

In that case, how do I specify the dimension of the background image.
Can anybody help me with a solution for this?
User avatar

Voucher Codes

  • Posts: 1
  • Joined: Wed Mar 02, 2011 1:43 pm

Re: Can I use background image within <img> tag?

by snowhite » Wed Mar 02, 2011 2:11 pm

Voucher Codes wrote:Can I use background-image within the <img> tag to get an overlay effect as in the code below?

<img style="background-image:url(freegifts.gif)" src="new.gif" alt="image" width="72" height="73" />

In that case, how do I specify the dimension of the background image.
Can anybody help me with a solution for this?



No, you won't be able to use IMG tag in the background image..
User avatar

snowhite

  • Posts: 3
  • Joined: Wed Mar 02, 2011 2:00 pm

Re: Can I use background image within <img> tag?

by HTML.net » Wed Mar 02, 2011 2:29 pm

That's an interesting idea...

If you make the image transparent (in your image editing program) I quess you could set a background image on it.

Try it - and let us know if it works.

- Andreas, HTML.net
User avatar

HTML.net
Site Admin

  • Posts: 1184
  • Joined: Sat Sep 11, 2010 11:24 am
--
Show some love for HTML.net on Twitter, Facebook and Google: Use the buttons on top of all pages.

Re: Can I use background image within <img> tag?

by movieviewonline » Thu Mar 03, 2011 8:03 pm

I'd also like to know how this ended up!
User avatar

movieviewonline

  • Posts: 1
  • Joined: Thu Mar 03, 2011 7:57 pm

Re: Can I use background image within <img> tag?

by al_uk » Sat Mar 05, 2011 10:49 am

Its possible, but it would be pointless. You can do it in CSS in like 5 seconds and its a more efficient way of doing it (:
User avatar

al_uk

  • Posts: 3
  • Joined: Sat Mar 05, 2011 10:38 am

Re: Can I use background image within <img> tag?

by martha301 » Mon Mar 07, 2011 4:55 am

I agree, CSS is a much easier route, unless you are having an HTML contest :)
User avatar

martha301

  • Posts: 1
  • Joined: Mon Mar 07, 2011 4:52 am

Re: Can I use background image within <img> tag?

by dreison27 » Mon Mar 07, 2011 4:20 pm

Wow, I never thought of this before because I used style="background:xxx" on almost any html tag I encountered, except <html>,<head>,<title>,<meta> of course. I never tried it. It is really possible because it will just treat the img tag like any other div or html tag. But like they said its pointless, or maybe not if you find any use for it. But that will just violate why it is called img tag in the first place.
User avatar

dreison27

  • Posts: 1
  • Joined: Mon Mar 07, 2011 3:59 pm

Re: Can I use background image within <img> tag?

by lonnienieves » Mon Mar 07, 2011 5:48 pm

snowhite wrote:
Voucher Codes wrote:Can I use background-image within the <img> tag to get an overlay effect as in the code below?

<img style="background-image:url(freegifts.gif)" src="new.gif" alt="image" width="72" height="73" />

In that case, how do I specify the dimension of the background image.
Can anybody help me with a solution for this?



No, you won't be able to use IMG tag in the background image..



thanks for your answer. this info was helpful to me too.
User avatar

lonnienieves

  • Posts: 1
  • Joined: Mon Mar 07, 2011 5:45 pm

Re: Can I use background image within <img> tag?

by bartekkaczka » Mon Mar 07, 2011 9:19 pm

img tag won't work. Better way to do it is to go to your stylesheet and put image in css. Much easier and fits better.
User avatar

bartekkaczka

  • Posts: 1
  • Joined: Mon Mar 07, 2011 9:17 pm

Re: Can I use background image within <img> tag?

by Huge Heffener » Wed Mar 23, 2011 3:06 pm

Yes you can do this with the use of <img> tag.If you want to do this first give the path of the image in the <img> tag then you can set it as the background.
User avatar

Huge Heffener

  • Posts: 3
  • Joined: Wed Mar 23, 2011 2:55 pm


+ Post a reply

1, 2