Our volunteers haven't translated this article into Bahasa Indonesia yet. Join us and help get the job done!
You can also read the article in English (US).

The border-image-slice CSS property divides the image specified by border-image-source into regions. These regions are used to form the components of an element's border image.

The slicing process creates nine regions in total: four corners, four edges, and a middle region. Four slice lines, set a given distance from their respective sides, control the size of the regions.

The nine regions defined by the border-image or border-image-slice properties

The above diagram illustrates the location of each region.

The border-image-repeat, border-image-width, and border-image-outset properties determine how these regions are used to form the final border image.

Syntax

/* All sides */
border-image-slice: 30%;

/* vertical | horizontal */
border-image-slice: 10% 30%;

/* top | horizontal | bottom */
border-image-slice: 30 30% 45;

/* top | right | bottom | left */
border-image-slice: 7 12 14 5; 

/* Using the `fill` keyword */
border-image-slice: 10% fill 7 12;

/* Global values */
border-image-slice: inherit;
border-image-slice: initial;
border-image-slice: unset;

The border-image-slice property may be specified using one to four <number-percentage> values to represent the position of each image slice. Negative values are invalid; values greater than their corresponding dimension are clamped to 100%.

  • When one position is specified, it creates all four slices at the same distance from their respective sides.
  • When two positions are specified, the first value creates slices measured from the top and bottom, the second creates slices measured from the left and right.
  • When three positions are specified, the first value creates a slice measured from the top, the second creates slices measured from the left and right, the third creates a slice measured from the bottom.
  • When four positions are specified, they create slices measured from the top, right, bottom, and left in that order (clockwise).

The optional fill value, if used, can be placed anywhere in the declaration.

Values

<number>
Represents an edge offset in pixels for raster images and coordinates for vector images. For vector images, the number is relative to the element's size, not the size of the source image, so percentages are generally preferable.
<percentage>
Represents an edge offset as a percentage of the source image's size: the width of the image for horizontal offsets, the height for vertical offsets.
fill
Preserves the middle image region and displays it like a background image, but stacked above the actual background. Its width and height are sized to match the top and left image regions, respectively.

Formal syntax

<number-percentage>{1,4} && fill?

where
<number-percentage> = <number> | <percentage>

Specifications

Specification Status Comment
CSS Backgrounds and Borders Module Level 3
The definition of 'border-image-slice' in that specification.
Candidate Recommendation Initial defintion

Initial value100%
Applies toall elements, except internal table elements when border-collapse is collapse. It also applies to ::first-letter.
Inheritedno
Percentagesrefer to the size of the border image
Mediavisual
Computed valueone to four percentage(s) (as specified) or absolute length(s), plus the keyword fill if specified
Animation typediscrete
Canonical orderthe percentages or lengths, eventually followed by the keyword fill

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support15 Yes151 2 3 411156
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support4.1 -webkit- ? Yes151 2 3 4 ? ? ?

1. Small SVGs are incorrectly stretched, because percentages in border-image-slice are computed to integers instead of floats (bug 1284797).

2. Until Firefox 47, SVGs without viewport were not sliced correctly (bug 619500).

3. From Firefox 48 until Firefox 49, SVGs without viewport are displayed the same as SVGs with viewport, but if the slices are not exactly 50%, they are incorrectly stretched (bug 1264809).

4. Until Firefox 57, an issue persisted for SVGs without viewport when e10s was disabled (bug 1290782).

See also

Tag Dokumen dan Kontributor

 Terakhir diperbarui oleh: wbamberg,