Previous task
Backgrounds5/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

A little more background-position

When the background image is larger than the block, it is cropped. You can also control which part of the image will be visible using the background-position property.

Sometimes it is convenient to use relative values (percentages) and sometimes absolute values (pixels) for this purpose.

By the way, you can use not only positive but also negative values. And also combine pixels and percentages.

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>A little more background-position</title> <link rel="stylesheet" href="style.css"> </head> <body> <div class="block block1"></div> <div class="block block2"></div> <br> <div class="block block3"></div> <div class="block block4"></div> </body> </html>
CSS
body { padding: 10px; text-align: center; } .block { display: inline-block; width: 200px; height: 200px; margin: 5px; background-color: #34495e; background-image: url("instructor.jpg"); background-repeat: no-repeat; border-radius: 5px; box-shadow: 1px 1px 3px #999999; } .block1 { } .block2 { } .block3 { } .block4 { }

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 the background position for the blocks:

    1. -60px -100px — for the first block,
    2. 70% 25% — for the second block,
    3. -50px 80% — for the third block,
    4. -250px 80%; - for the fourth block.

    © 2023-2024, codehero.pro