HTML Academy
Frame Image: border-image-source
Frames and Backgrounds14/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
Slicing Asymmetrical Images
  • Sign up
  • Log in

Loading…
Everything will be ready in few seconds

  • Theory
  • Theory
  • Comments

Frame Image: border-image-slice

Let’s see how the mechanism for slicing the background image for the frame works.

A diagram demonstrating how the background image is sliced up for the frame

Each frame has 9 areas: 4 corners, 4 borders, and a center area. To fill these areas, the browser must slice the image for the frame into 9 pieces. When the browser doesn’t know how to do this, it simply places the image in the corners. We saw this in the previous assignment.

The border-image-slice property sets the margins as measured from the edges of the image to the four lines that are used to slice it into parts, as in the diagram on the right. If these margins are small, then we are able to slice the image into 9 pieces, which are then placed in the corresponding areas of the frame.

But if the margins are too large (more than half of the image), then the browser is not able to obtain the 9 pieces and places what was sliced in the corners.

The property value can be set as a number without a unit (it is usually denoted in pixels) or as a percentage (relative to the size of the image itself). Example:

border-image-slice: 60;
border-image-slice: 10%;

Comments

  • index.html
  • style.css
HTML
<!DOCTYPE html> <html lang="en"> <head> <title>Frame Image: border-image-slice</title> <meta charset="utf-8"> <link rel="stylesheet" href="setting.css"> <link rel="stylesheet" href="style.css"> </head> <body> <div class="portrait"></div> </body> </html>
CSS
.portrait { box-sizing: border-box; margin: 50px auto; padding: 10px; width: 270px; height: 270px; outline: 10px solid white; border: 50px solid rgba(0, 0, 0, 0.4); border-image-source: url("img/border-img.png"); background: url("img/border-img.png") no-repeat #ffffff; background-clip: padding-box; background-origin: content-box; }

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. Set the border-image-slice property with a value of 120 for the .portrait block,
    2. and then change the value to 80,
    3. and then finally change it to 50. Notice how the background is filled to all of the borders of the frame.

    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.