HTML Academy
Background Size, Step 2
Frames and Backgrounds4/33
Back to the list of tasks
  • 1. Preparation
  • 2. Background Size, Step 1
  • 3. Background Size, Step 2
  • 4. Background Borders
  • 5. Background Cropping
  • 6. Multiple Background Images
  • 7. Positioning the background relative to different borders
  • 8. background-repeat: round
  • 9. background-repeat: space
  • 10. Outer Frame
  • 11. Rounding Corners, Part 1
  • 12. Rounding Corners, Part 2
  • 13. Frame Image: border-image-source
  • 14. Frame Image: border-image-slice
  • 15. Slicing Asymmetrical Images
  • 16. Frame Image: border-image-repeat, Part 1
  • 17. Frame Image: border-image-repeat, Part 2
  • 18. Frame Image: border-image-width
  • 19. Frame Image: border-image-outset
  • 20. Muffin’s Royal Frame
  • 21. Muffin’s Eco-Frame
  • 22. Muffin’s Round Frame, Part 1
  • 23. Muffin’s Round Frame, Part 2
  • 24. Challenge: The Sea Wolf
  • 25. Frames and Triangles, Part 1
  • 26. Frames and Triangles, Part 2
  • 27. Frames and Triangles, Part 3
  • 28. Creating an Arrow with a Frame
  • 29. Creating a Round Arrow with a Frame, Part 1
  • 30. Creating a Round Arrow with a Frame, Part 2
  • 31. Real-Life Triangles, Part 1
  • 32. Real-Life Triangles, Part 2
  • 33. Challenge: Jewelry Work
Background Cropping
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Background Borders

Another background property is background-origin. It specifies the position and dimensions of the background image display area and takes three values: padding-box, border-box, and content-box.

A diagram of the background-origin property values

The default value is padding-box. When this value is set, the display area of the background image corresponds to the inner area of the block, not including the frames.

With content-box, the display area corresponds just to the content area, not including frames and padding.

With border-box, the display area matches the full size of the block, including frames. The background image starts at the outer edge of the block and is enclosed by frames, if any are specified.

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <title>Background Borders</title> <meta charset="utf-8"> <link rel="stylesheet" href="setting.css"> <link rel="stylesheet" href="style.css"> </head> <body class="set"> <div class="portrait"></div> <div class="portrait portrait-content-box"></div> <div class="portrait portrait-border-box"></div> </body> </html>
CSS
.portrait { box-sizing: border-box; padding: 20px; width: 200px; height: 200px; border: 20px solid rgba(255, 255, 0, 0.4); background: url("img/muffin.jpg") no-repeat #ffffff; background-origin: padding-box; background-size: 100% 100%; }

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
    1. For the .portrait-content-box portrait, set borders for the content-box background,
    2. and then assign border-box to the .portrait-border-box portrait.

    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.