Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Using CSS to set image source

Posted on 2008-06-11
Medium Priority
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>
Question by:witgrefe
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Expert Comment

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.

Author Comment

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

Expert Comment

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

Author Comment

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?

Accepted Solution

bolt81 earned 200 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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

688 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