HTML Academy
The GIF Format
Introduction to Backgrounds14/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
Effects with a Repeating Background
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Multiple backgrounds

You can use multiple backgrounds to set multiple backgrounds for one element.

We will cover this and other options in the continuation of this section, “Frames and Backgrounds: An Immersion Course”.

Now let’s take a look at one old and reliable technique for creating multiple backgrounds.

The essence of the technique is to nest elements one inside the other and make them the same size, and then set a background for each element. That is, each element functions as one layer of the background.

The backgrounds of the nested elements overlap each other: the deeper the element, the higher its background.

By the way, for the sake of convenience, it is better to assign a width to the outer element (since all nested elements will have the same width) and a height to the deepest element, since it will stretch to the height of all its parents.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Multiple backgrounds</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="block1"> <div class="block2"> <div class="block3"></div> </div> </div> </body> </html>
CSS
body { padding-top: 80px; } .block1 { width: 256px; margin: 0 auto; box-shadow: 1px 1px 3px #999999; } .block2 { } .block3 { height: 256px; }

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

    Let’s create a “Cat on the Farm” miniature. Set the following non-repeating background images:

    1. cows.jpg — To the first block,
    2. cat_walk.png — To the second block, with a background position of 190px 195px,
    3. fence.png — To the third block.

    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.