Categories
CSS Web development

CSS border-image Property

CSS border-image Property

By using the CSS border-image property you can define an image to be used as the border around an element.

The CSS border-image property is a shorthand property for:

border-image-source

border-image-slice

border-image-width

border-image-outset

border-image-repeat

Syntax:

border-image: source slice width outset repeat;

border-image-source – defines the path to the image to be used as a border.

border-image-slice – defines how to slice the image defined by the CSS border-image-source.

border-image-width – defines the width of the border-image.

border-image-outset – defines the amount by which the border-image area extends beyond the border-box.

border-image-repeat – defines whether the border-image should be repeated, rounded or stretched.

Example:

<!DOCTYPE html>
<html>
<head>
<style> 
#borderimg-1 { 
  border: 10px solid transparent;
  padding: 15px;
  border-image: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png) 30 round;
}

#borderimg-2 { 
  border: 10px solid transparent;
  padding: 15px;
  border-image: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png) 60 stretch;
}
</style>
</head>
<body>

<p id="borderimg-1">The image tiles to fill the area. The image is re-scaled if necessary, to avoid dividing tiles.</p>
<p id="borderimg-2">The image is stretched to fill the area.</p>

</body>
</html>

Output:

The image tiles to fill the area. The image is re-scaled if necessary, to avoid dividing tiles.

The image is stretched to fill the area.


The original image:

Enjoy coding!

Read also:

CSS Border Property

CSS Glowing Gradient Border

Categories
CSS Web development

CSS border-image-width Property

CSS border-image-width Property

The CSS border-image-width property defines the width of the border-image.

Demo:

Click the “Try it” button to change the value of the border-image-width property 10px to 20px 30px:



Hello World!


Syntax:

border-image-width: length|number|%|auto;

length – a length unit (in px) defining the size of the border-width.

number – represents multiples of the corresponding border-width (the default value is 1).

% – refers to the size of the border image area: the width of the area for horizontal offsets, the height for vertical offsets.

auto – if defined, the width is the intrinsic width or height of the corresponding image slice.

Example:

<!DOCTYPE html>
<html>
<head>
<style> 
#borderimg-1 { 
  border: 10px solid transparent;
  padding: 15px;
  border-image-source: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png);
  border-image-repeat: round;
  border-image-slice: 30;
  border-image-width: 10px;    
}

#borderimg-2 { 
  border: 10px solid transparent;
  padding: 15px;
  border-image-source: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png);
  border-image-repeat: round;
  border-image-slice: 30;
  border-image-width: 15px;    
}

#borderimg-3 { 
  border: 10px solid transparent;
  padding: 15px;
  border-image-source: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png);
  border-image-repeat: round;  
  border-image-slice: 30;
  border-image-width: 20px;    
}
</style>
</head>
<body>

<p id="borderimg-1">border-image-width: 10px;</p>
<p id="borderimg-2">border-image-width: 15px;</p>
<p id="borderimg-3">border-image-width: 20px;</p>

</body>
</html>

Output:

border-image-width: 10px;

border-image-width: 15px;

border-image-width: 20px;


The original image:

CSS border-image Property

Enjoy coding!

Read also:

CSS Border Property

Advanced CSS Border-radius/ Drop Shape, Lemon Shape, Leaf Shape & Egg Shape

Categories
CSS Web development

CSS border-image-slice Property

CSS border-image-slice Property

The CSS border-image-slice property defines how to slice the image defined by the CSS border-image-source (the image is sliced into nine sections: four corners, four edges and the middle).

Demo:

Click the “Try it” button to change the value of the border-image-slice property to 30%:



Hello World!


Syntax:

border-image-slice: number|%|fill;

number – the number(s) represent pixels for raster images or coordinates for vector images.

% – percentages are relative to the height or width of the image.

fill – causes the middle part of the image to be displayed.

Example:

<!DOCTYPE html>
<html>
<head>
<style>
#borderimg-1 {
  border: 10px solid transparent;
  padding: 15px;
  border-image: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png) round;
  border-image-slice: 10%;
}

#borderimg-2 {
  border: 10px solid transparent;
  padding: 15px;
  border-image: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png) round;
  border-image-slice: 20%;
}

#borderimg-3 {
  border: 10px solid transparent;
  padding: 15px;
  border-image: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png) round;
  border-image-slice: 30%;
}
</style>
</head>
<body>

<p id="borderimg-1">border-image-slice: 10%;</p>
<p id="borderimg-2">border-image-slice: 20%;</p>
<p id="borderimg-3">border-image-slice: 30%;</p>

</body>
</html>

Output:

border-image-slice: 10%;

border-image-slice: 20%;

border-image-slice: 30%;


The original image:

CSS border-image Property

Enjoy coding!

Read more:

CSS Gradient Border

CSS Glowing Gradient Border

Categories
CSS Web development

CSS border-image-source Property

CSS border-image-source Property

The CSS border-image-source property defines the path to the image to be used as a border.

Syntax:

border-image-source: none|image;

none – no image will be used.

image – the path to the image to be used as a border.

Example:

<!DOCTYPE html>
<html>
<head>
<style> 
#borderimg-1 { 
  border: 15px solid transparent;
  padding: 15px;
  border-image-source: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png);
  border-image-repeat: repeat;
  border-image-slice: 30;
}

</style>
</head>
<body>

<p id="borderimg-1">Hello World!</p>

</body>
</html>

Output:

Hello World!


The original image:

CSS border-image Property

Enjoy coding!

Read also:

CSS Gradient Border

CSS border-radius property

Categories
CSS Web development

CSS border-image-repeat Property

CSS border-image-repeat Property

The CSS border-image-repeat property defines whether the border-image should be repeated, rounded or stretched.

Demo:

Syntax:

border-image-repeat: stretch|repeat|round|space;

stretch (default) – the image is stretched to fill the area.

repeat – the image is repeated to fill the area.

round – the image is repeated to fill the area (if it does not fill the area with a whole number of tiles, the image is rescaled so it fits).

space – the image is repeated to fill the area (if it does not fill the area with a whole number of tiles, the extra space is distributed around the tiles).

Example:

<!DOCTYPE html>
<html>
<head>
<style> 
#borderimg-1 { 
  border: 15px solid transparent;
  padding: 15px;
  border-image-source: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png);
  border-image-repeat: repeat;
  border-image-slice: 30;
}

#borderimg-2 { 
  border: 15px solid transparent;
  padding: 15px;
  border-image-source: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png);
  border-image-repeat: round;
  border-image-slice: 30;
}

#borderimg-3 { 
  border: 15px solid transparent;
  padding: 15px;
  border-image-source: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png);
  border-image-repeat: stretch;  
  border-image-slice: 30;
}
</style>
</head>
<body>

<h4>border-image-repeat: repeat;</h4>
<p id="borderimg-1">Here, the image tiles to fill the area. Tiles are divided if necessary.</p>

<h4>border-image-repeat: round;</h4>
<p id="borderimg-2">Here, the image tiles to fill the area. The image is rescaled if necessary, to avoid dividing tiles.</p>

<h4>border-image-repeat: stretch;</h4>
<p id="borderimg-3">Here, the image is stretched to fill the area.</p>

</body>
</html>

Output:

border-image-repeat: repeat;

Here, the image tiles to fill the area. Tiles are divided if necessary.

border-image-repeat: round;

Here, the image tiles to fill the area. The image is rescaled if necessary, to avoid dividing tiles.

border-image-repeat: stretch;

Here, the image is stretched to fill the area.


The original image:

CSS border-image Property

Enjoy coding!

Read also:

CSS Border Property

Advanced CSS Border-radius/ Drop Shape, Lemon Shape, Leaf Shape & Egg Shape

Categories
CSS Web development

CSS border-image-outset Property

CSS border-image-outset Property

The CSS border-image-outset property defines the amount by which the border-image area extends beyond the border-box.

Demo:

Click the “Try it” button to change the border-image-outset property of the div element to 15px:




Hello World!


Syntax:

border-image-outset: length|number;

length – a length unit defining how far from the edges the border image will appear (the default value is 0).

number – represent multiples of the corresponding border-width.

Example:

<!DOCTYPE html>
<html>
<head>
<style> 
#borderimg1, #borderimg2 { 
  border: 10px solid transparent;
  padding: 15px;
  border-image-source: url(https://lenadesign.org/wp-content/uploads/2021/09/border-1.png);
  border-image-width: 15px;
  border-image-repeat: round;
  border-image-slice: 30;
}

#borderimg1 {
  border-image-outset: 5px; 
    }

#borderimg2 {
  border-image-outset: 15px; 
    }

</style>
</head>
<body>

<p id="borderimg1">Some text...some text...some-text...</p>
    <br>
<p id="borderimg2">Some text...some text...some-text...</p>

</body>
</html>

Output:

border-image-outset: 5px;


border-image-outset: 15px;


The original image:

CSS border-image

Enjoy coding!

Read also:

CSS Border Property

CSS Multiple Borders

CSS Outline