Is it possible to set the equivalent of a src attribute of an img tag in CSS?

Is it possible to set the src attribute value in CSS? At present, what I am doing is: <img src=”https://stackoverflow.com/questions/2182716/pathTo/myImage.jpg”/> and I want it to be something like this <img class=”myClass”/> .myClass { some-src-property: url(“https://stackoverflow.com/questions/2182716/pathTo/myImage.jpg”); I want to do this without using the background or background-image: properties in CSS. 25 s 25 Use content:url(“image.jpg”). Full … Read more

CSS force image resize and keep aspect ratio

I am working with images, and I ran into a problem with aspect ratios. <img src=”big_image.jpg” width=”900″ height=”600″ alt=”” /> As you can see, height and width are already specified. I added a CSS rule for images: img { max-width: 500px; } But for big_image.jpg, I receive width=500 and height=600. How do I set images … Read more

When to use IMG vs. CSS background-image?

This question’s answers are a community effort. Edit existing answers to improve this post. It is not currently accepting new answers or interactions. In what situations is it more appropriate to use an HTML IMG tag to display an image, as opposed to a CSS background-image, and vice-versa? Factors may include accessibility, browser support, dynamic … Read more

Changing the image source using jQuery

My DOM looks like this: <div id=”d1″> <div class=”c1″> <a href=”#”><img src=”img1_on.gif”></a> <a href=”#”><img src=”img2_on.gif”></a> </div> </div> When someone clicks on an image, I want the image src to change to <img src=”https://stackoverflow.com/questions/554273/imgx_off.gif”> where x represents the image number 1 or 2. Is this possible or do I have to use CSS to change the … Read more

How to display Base64 images in HTML

I’m having trouble displaying a Base64 image inline. How can I do it? <!DOCTYPE html> <html> <head> <title>Display Image</title> </head> <body> <img style=”display:block; width:100px;height:100px;” id=’base64image’ src=”data:image/jpeg;base64, LzlqLzRBQ… <!– Base64 data –>” /> </body> </html> 12 s 12 My suspect is of course the actual Base64 data. Otherwise it looks good to me. See this fiddle … Read more