HTML Academy
Effects with a Repeating Background
Introduction to Backgrounds16/18
Back to the list of tasks
  • 1. The background-color Property
  • 2. The background-image Property
  • 3. The background-repeat Property
  • 4. The background-position Property
  • 5. A Little More on background-position
  • 6. The background-attachment Property
  • 7. The background Property
  • 8. Summary of “Backgrounds: An Introduction. Part 1”
  • 9. Challenge: Cat Comics
  • 10. JPEG format
  • 11. The PNG-8 Format
  • 12. PNG-24 format
  • 13. The GIF Format
  • 14. Multiple backgrounds
  • 15. Effects with a Repeating Background
  • 16. Sprites
  • 17. Summary of “Backgrounds: An Introduction. Part 2”
  • 18. Challenge: CAT Academy
Summary of “Backgrounds: An Introduction. Part 2”
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Sprites

A sprite is one big image that contains many small ones. It’s like an image map. Here is a live example (the same image is displayed against a dark background at the bottom of the mini-browser) that we will use in the assignment.

Sprites are used to reduce the number of requests to the server. Each small image is a separate request, and the fewer the requests, the better. Therefore, small images are “glued” together to make one big image.

Parts of the sprite are displayed in elements that are assigned small dimensions. This element is assigned a sprite image as the background and displaced so that the desired part of it is visible.

Sprites are usually made up of icons and various small decorative images. By the way, there are services for quickly creating sprites and generating the CSS code for them, such as, for example, SpritePad.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Sprites</title> <link rel="stylesheet" href="style.css"> </head> <body> <button class="btn btn-add" type="button"> <span class="icon icon-add"></span> Add </button> <button class="btn btn-edit" type="button"> <span class="icon icon-edit"></span> Edit </button> <button class="btn btn-remove" type="button"> <span class="icon icon-remove"></span> Delete </button> <!-- Sprite on dark background --> <div class="full-sprite"></div> </body> </html>
CSS
body { padding: 20px; font-family: "Tahoma", sans-serif; } .btn { display: block; width: 180px; margin: 20px auto; padding: 12px; color: white; font: inherit; text-align: left; border: 0; background-color: #34495e; border-radius: 5px; } .btn-add { background-color: #27ae60; } .btn-remove { background-color: #c0392b; } .icon { display: inline-block; width: 15px; height: 15px; margin: 0 5px; vertical-align: bottom; background-image: url("bootstrap-sprites.png"); background-repeat: no-repeat; box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2); } .icon-add { } .icon-edit { } .icon-remove { } .full-sprite { height: 200px; margin: 50px auto; background: #34495e url("bootstrap-sprites.png") no-repeat 50% 50%; border-radius: 5px; }

What didn’t you like in this task?

Thanks! We’ll fix everything at once!

The code has changed, click “Refresh” or turn autorun on.

You’ve gone to a different page

Click inside the mini-browser to shift the focus onto this window.

100%
Goalscompleted
0

    Set the background location:

    1. -407px -96px — To the element with the class icon-add,
    2. -96px -72px — To the element with the class icon-edit,
    3. -456px 0 — To the element with the class icon-remove.

    Cookies ∙ Privacy ∙ License Agreement ∙ About ∙ Contacts ∙ © HTML Academy OÜ, 2019−2025

    VISAMastercard

    Log in

    or

    Forgot your password?

    Sign up

    Sign up

    or
    Log in

    Restore access

    Have you forgotten your password or lost access to your profile? Enter your email connected to your profile and we will send you a link to restore access.

    Forgot to connect your email to the profile? Email us and we’ll help.