0

I would like an image to repeat horizontally, but I don't want to make it a background image. Is there a way to repeat an <img> element horizontally like that, or am I going to have to make it a background image?

Steven Matthews
  • 9,705
  • 45
  • 126
  • 232
  • This is already answered here: http://stackoverflow.com/questions/8679066/make-image-not-background-img-in-div-repeat/8679131#8679131 – Emre Oct 17 '13 at 14:46

1 Answers1

0

Make it a background image with repeat-x. You could repeat an <img> to fill a container if you use JavaScript, but I can't think why anyone would want to do that.

If you are trying to make the image source dynamic or something, and that's why you are trying to avoid hard-coding it as an image in the CSS, then you could also use JavaScript or a server-side language such as PHP to dynamically add a style="background-image:url('http://example.com/images/image.jpg')" attribute to the container element.

BadHorsie
  • 14,135
  • 30
  • 117
  • 191
  • That solution's not bad. I'm mostly worried about moving from dev to live and having the URL change. – Steven Matthews Oct 17 '13 at 17:11
  • @AndrewAlexander Well you could make a global constant for the base path. That way, when you move to live you can just change the constant, and all the paths across your application will work in the new environment. – BadHorsie Oct 22 '13 at 11:56