Solved

Using CSS to set image source

Posted on 2008-06-11
5
991 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
Comment Utility
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
Comment Utility
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
Comment Utility
if the image size is 20px then yes
0
 

Author Comment

by:witgrefe
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

744 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

15 Experts available now in Live!

Get 1:1 Help Now