Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7549519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:57:51+00:00 2026-05-30T09:57:51+00:00

I have browsed all the how-tos about CSS sprites and although some of them

  • 0

I have browsed all the how-tos about CSS sprites and although some of them are helpful, absolutely none explain how exactly to use the CSS class to display an image in a HTML page.

This is my CSS code, it has two classes.

.sprites{background-image:url('bookie_logos/0csssprites.png');background-color:transparent;background-repeat:no-repeat;}
#3_png{height:16px;width:75px;background-position:0 0;}
#5_png{height:16px;width:75px;background-position:-75px 0;}
...and so on

Which code do I use to display the image I want, not as a link, not as a list, not as a background, just a stand-alone image with width 75 and height 16? I suppose I should be using a DIV and assign two classes for it like this: class=”sprites 3_png” but it doesn’t work.

UPDATE:
There were several problems with the code. The first one was that 3_png should be used as an id, not as a class. Second, the code only worked when naming convention png_N was used instead of N_png, it won’t work when it starts with a number. After finding a working solution, I encountered another problem with the images creating a line break, solved it using display:inline. This is the CSS and PHP code which produces the wanted output:

CSS:

.sprites {background-image:url('bookie_logos/0csssprites.png');background-color:transparent;background-repeat:no-repeat;display:inline;}
#png3  {height:16px;width:75px;background-position:0px 0;}
#png5  {height:16px;width:75px;background-position:-75px 0;}

PHP:

$classy = "png" . $db_field['bookieid'];
echo "<td>" , "<img src='transparent.gif' class='sprites' id='$classy' alt='bookie' align='absmiddle'/>" , "</td>";

$classy is a variable which is choosing between 160+ images in the spritesheet. transparent.gif is a 1px transparent gif, as I opted to use IMG tag instead of DIV, and I need to use that 1px gif in order for the IMG tag to actually display the sprite image.

I’d like to thank all the contributors, most of you saw that first part of the problem, where ID should be used instead of class. You all guided me towards the solution, and unfortunately I can only choose one answer, and I’m choosing the one which mentioned display:block as it made me use display:inline later.

Thanks everyone, and I hope this question and answer will help someone else who’s having the same problem with CSS sprites.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:57:52+00:00Added an answer on May 30, 2026 at 9:57 am

    If you want to use 1 sprite for displaying multiple images, I think you should try this:

    CSS

    .sprite {
      background-image:url('bookie_logos/0csssprites.png');
      background-color:transparent;
      background-repeat:no-repeat;
      display:block;
    }
    
    #img_1 {
      height:16px;width:75px;background-position:0px 0;
    }
    
    #img_2 {
      height:16px;width:75px;background-position:-75px 0;
    }
    

    HTML

    <div class="sprite" id="img_1">
    </div>
    
    <div class="sprite" id="img_2">
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following program to browse all virtual directories and their sub directories
I currently have a issue with firefox, where all other browser behave in the
All the in-browser chat rooms I have seen so far append messages into the
I have 2 div boxes. It's all working fine but when the browser is
I have browsed thru other postings on S/O, but I can't find a solution
I have browsed lift's MegaProtoUser and encountered this construction: ??(Last Name) . Can anyone
I have an ASP.NET web application the entire site is browsed over HTTPS using
I have browsed around and haven't found a solution that specifically tailors to my
I do some PHP with Kohana 3 (IDE:Netbeans), and got excited about idea of
I have a database with files which can be searched, browsed and have multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.