The border-image-source property

The border-image-source property specifies a border image. For more details, see border-image property.

Syntax

cssselector {
  border-image-source: url(path to an image);
}

Example

The border-image-source property should be set together with border-image-slice:

html<div id="elem"></div>
css#elem {
  border-image-source: url("image.png");
  border-image-slice: 26;
  border-style: solid;
  border-width: 26px;
  width: 200px;
  height: 200px;
  background: green;
  margin: 0 auto;
}

Результат:

Example

If the border-image-slice property is not set, the entire image will end up in the corners (since border-image-slice defaults to 100%):

html<div id="elem"></div>
css#elem {
  border-image-source: url("image.png");
  border-style: solid;
  border-width: 26px;
  width: 200px;
  height: 200px;
  background: green;
  margin: 0 auto;
}

Результат:

Example

Instead of an image, you can set linear gradient:

html<div id="elem"></div>
css#elem {
  border-image-source: linear-gradient(to bottom, red, blue);
  border-image-slice: 30;
  border-width: 30px;
  border-style: solid;
  background: green;
  height: 200px;
  width: 200px;
  margin: 0 auto;
}

Результат:

Example

If the border-image-slice property is not set, the gradient will fall on the corners (since border-image-slice defaults to 100%):

html<div id="elem"></div>
css#elem {
  border-image-source: linear-gradient(to bottom, red, blue);
  border-width: 30px;
  border-style: solid;
  background: green;
  height: 200px;
  width: 200px;
  margin: 0 auto;
}

Результат:

Example

If you set the border-radius property, then, unfortunately, the border will not be rounded (and in the case of a gradient too), although the effect will also be quite interesting:

html<div id="elem"></div>
css#elem {
  border-radius: 100px;
  border-image-source: url("image.png");
  border-image-slice: 26;
  border-style: solid;
  border-width: 26px;
  width: 200px;
  height: 200px;
  background: green;
  margin: 0 auto;
}

Результат:

See also