Solved

Using CSS to set image source

Posted on 2008-06-11
5
992 Views
Last Modified: 2012-06-27
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
Comment
Question by:witgrefe
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:bolt81
ID: 21757997
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
 

Author Comment

by:witgrefe
ID: 21758072
would this be correct?:
.currentImage {
background-image: url (location of the image);
background-repeat: no-repeat;
height: 20px;
width: 20px;
}
0
 
LVL 1

Expert Comment

by:bolt81
ID: 21758089
if the image size is 20px then yes
0
 

Author Comment

by:witgrefe
ID: 21758128
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
 
LVL 1

Accepted Solution

by:
bolt81 earned 50 total points
ID: 22272011
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now