I am trying to understand how does the border-image-slice work.
When you load a border-image using the border-image-source, the image is placed on the 4 corners of the element. Top-right, top-left, bottom-right and bottom-left. Then, you can use border-image-slice property to "slice" the image and determine how much of the original image to be displayed. You can use numbers or percentages. By default, 100% of the image is displayed. As you start cutting down the number, the image gets sliced by that percentage or pixel. So, if you define 50%, that means 50% of the image is displayed.
So far, so good.
What i don't understand, however, is the "edge regions" which get "activated" and filled by the "sliced" parts of the image at a seemingly random percentage.
So, in the below image taken from MDN, we can see the 9 regions of the image.
Before even slicing the image, the entire image is displayed in the 4 corners. But when you start slicing the image, the image remains displayed at the 4 corners, but it just keeps getting cut, and fewer and fewer parts of the image are displayed. The edge regions remain empty UNTIL you hit about 40% or just 40 in border-image-slice. At a seemingly random number, all of a sudden, the edge regions get filled, as if the corner regions had a defined size which got exceeded.
Here is an example.
I am using the below image. Its size is 90x90.
HTML:
div {
padding:25px;
font-size:20px;
border:50px solid;
outline:1px dashed;
border-image-source: url('https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png');
border-image-slice:45;
}
<div>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Optio, eligendi perferendis? Magnam in iste sunt quaerat ullam porro molestiae harum! Corrupti, aperiam? Eligendi facere dignissimos soluta molestiae suscipit voluptate, magni error laborum atque recusandae cum temporibus eos accusamus vitae. Quae laudantium libero cum, aliquam repellat ad, vitae maiores nulla consequatur quibusdam sed vero amet sapiente? Qui aut optio commodi impedit!
</div>
Now, as you can see from the snippet above, the border-image-slice is set to 45, and the edge regions are empty. The 4 images displayed at the 4 corners are being sliced, and only 45px are being shown of the image.
Now, the confusing part is when you decrease the number from 45 to 44, just take 1 number off.
div {
padding:25px;
font-size:20px;
border:50px solid;
outline:1px dashed;
border-image-source: url('https://interactive-examples.mdn.mozilla.net/media/examples/border-diamonds.png');
border-image-slice:44;
}
<div>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Optio, eligendi perferendis? Magnam in iste sunt quaerat ullam porro molestiae harum! Corrupti, aperiam? Eligendi facere dignissimos soluta molestiae suscipit voluptate, magni error laborum atque recusandae cum temporibus eos accusamus vitae. Quae laudantium libero cum, aliquam repellat ad, vitae maiores nulla consequatur quibusdam sed vero amet sapiente? Qui aut optio commodi impedit!
</div>
Now, as you can see, something completely unexpected happens. I would expect the image to just keep decreasing as it gets sliced more and more, and fewer parts being displayed, yet something completely different happens. The edge regions get filled by the sliced parts of the image.
I don't understand why? What is the logic behind this? Why is this happening when the border-image-slice is set to exactly 44 or lower? Do the corner regions have a defined size, which got exceeded? But how does it get exceeded, since i am only cutting the images, and fewer parts of the image become visible?