Define an <img>'s src attribute in CSS [duplicate]

I need to define an <img>'s src attribute in CSS. Is there a way to specify this attribute?


just this as img tag is a content element

img {
    content:url(http://example.com/image.png);
}

#divID {
    background-image: url("http://imageurlhere.com");
    background-repeat: no-repeat;
    width: auto; /*or your image's width*/
    height: auto; /*or your image's height*/
    margin: 0;
    padding: 0;
}

No there isn't. You can specify a background image but that's not the same thing.


CSS is not used to define values to DOM element attributes, javascript would be more suitable for this.


No. The closest you can get is setting a background image:

<div id="myimage"></div>

#myimage {
  width: 20px;
  height: 20px;
  background: white url(myimage.gif) no-repeat;
}