• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1011
  • Last Modified:

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>
0
witgrefe
Asked:
witgrefe
  • 3
  • 2
1 Solution
 
bolt81Commented:
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.
0
 
witgrefeAuthor Commented:
would this be correct?:
.currentImage {
background-image: url (location of the image);
background-repeat: no-repeat;
height: 20px;
width: 20px;
}
0
 
bolt81Commented:
if the image size is 20px then yes
0
 
witgrefeAuthor Commented:
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?
0
 
bolt81Commented:
sorry this isn't the case when using a backgroup image. you need to set a size and it will only show what part of the image fits into that size
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now