Link to home
Start Free TrialLog in
Avatar of witgrefe
witgrefe

asked on

Using CSS to set image source

Instead of hardcoding the image into an img tag, I would like to have the image defined in a stylesheet and pull it from there.  How do I go about it?

<td id= 'a' ><img id='b' src ="images/image.jpg;"></td>
Avatar of bolt81
bolt81
Flag of United Kingdom of Great Britain and Northern Ireland image

create css class with the following properity
background-image: url (location of the image);

use background-repeat: no-repeat; to just show it once.
you will need to set a width and hieght for the class to show the image.
Avatar of witgrefe
witgrefe

ASKER

would this be correct?:
.currentImage {
background-image: url (location of the image);
background-repeat: no-repeat;
height: 20px;
width: 20px;
}
if the image size is 20px then yes
If I don't know the image size can I just leave out the width and height attributes to have the image rendered at its actual dimensions?
ASKER CERTIFIED SOLUTION
Avatar of bolt81
bolt81
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial