Issue
Is it possible to set the src
attribute value in CSS?
In most cases, we use it like this:
<img src="pathTo/myImage.jpg" />
and I want it to be something like this
<img class="myClass" />
.myClass {
some-src-property: url("pathTo/myImage.jpg");
}
I want to know if there is a way doing it without using the background
or background-image
properties in CSS.
Solution
Full working solution (Live Demo):
<!doctype html>
<style>
.MyClass123{
content:url("http://imgur.com/SZ8Cm.jpg");
}
</style>
<img class="MyClass123"/>
Tested and working:
- Chrome 14.0.835.163
- Safari 4.0.5
- Opera 10.6
- Firefox 100 & newer
Tested and Not working:
- FireFox 40.0.2 (observing Developer Network Tools, you can see that the URL loads, but the image is not displayed)
- Internet Explorer 11.0.9600.17905 (URL never loads)
Answered By - Pacerier
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.