I need to define an <img>'s src attribute in CSS. Is there a way to specify this attribute?
+6
A:
No there isn't. You can specify a background image but that's not the same thing.
cletus
2010-04-20 15:34:44
Indeed. `<img>` represents a content image. If the image isn't content then it shouldn't be an `<img>` element. If it is content, then it should be. If the content is duplicated on multiple pages (such as being part of a menu) then the HTML for it should be too (e.g. using a template system) just like any other duplicated content.
David Dorward
2010-04-20 15:36:49
+4
A:
#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;
}
Ronnie Chester Lynwood
2010-04-20 15:34:44
A:
CSS is not used to define values to DOM element attributes, javascript would be more suitable for this.
Darin Dimitrov
2010-04-20 15:35:35
+3
A:
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;
}
RoToRa
2010-04-20 15:35:49