Previous task
Backgrounds13/14
Back to the list of tasks
  1. 1. Background-color property
  2. 2. Background-image property
  3. 3. Background-repeat property
  4. 4. Background-position property
  5. 5. A little more background-position
  6. 6. Background-attachment property
  7. 7. Background property
  8. 8. JPEG format
  9. 9. PNG-8 format
  10. 10. PNG-24 format
  11. 11. GIF format
  12. 12. Nested elements with backgrounds
  13. 13. Effects with repeating backgrounds
  14. 14. Sprites
Nest task
  • Courses
  • Sign up
  • Log in

Loading...
It will be ready in a few seconds.

  • Theory
  • Theory

Effects with repeating backgrounds

A repeating background is often used to create interesting decorative effects. For example, it can be used to make:

  • stitches;
  • jagged edges;
  • gradients and shadows.

Yes, gradients and shadows can be done with CSS. But for complex shadows or gradients it is easier to use a semi-transparent PNG.

The most important thing when creating such effects is to choose a picture with the right period. It can be very small and will give a significant saving of page weight.

Let's practice. Please, change the repetition mode after you set the background images. It'll be clearer that way.

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Effects with repeating backgrounds</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="block block1"></div> <div class="block block2"></div> <div class="block block3"></div> </body> </html>
CSS
body { padding-top: 40px; } .block { height: 70px; margin: 30px 50px; background-color: #3498db; background-repeat: no-repeat; border-radius: 5px; box-shadow: 1px 1px 3px #999999; } .block1 { background-position: -30px 30px; } .block2 { background-position: 0 0; } .block3 { background-position: 0 100%; }

The code has changed, click "Update" or enable autorun.

You have moved to another page

Click inside the mini-browser to highlight this window.

100%
GoalsCompleted
0

    Set horizontally repeating background images:

    1. stitch.png — for the first block,
    2. zigzag.png — for the second block,
    3. shadow.png — for the third block.

    © 2023-2024, codehero.pro