border-image
The border-image
property is a shorthand that defines several border image properties at once, including the border-image-source
property. This means that you can specify the URL-address or the data URI of the image.
For example, you can use a 5x5 GIF image to draw a red cross border:
.base64-url {
border-image: url("//static.base64.guru/uploads/images/5x5.gif") 5 0 / 5px repeat;
}
The same can be achieved by encoding image to Base64 and embedding it using data URI:
.base64-data {
border-image: url("data:image/gif;base64,R0lGODdhBQAFAPABAP////8AACwAAAAABQAFAAACCARihhe9q0wBADs=") 5 0 / 5px repeat;
}
Both behaviors are identical — when you open the page, your browser displays the same border for both elements. The difference is that in the first case the browser sends one HTTP request to fetch the external image, when in the second case the image is already loaded in the browser’s memory and it does not need to send any HTTP requests.
Please note that Base64 Data URIs have some limitations. In addition, like almost any unconventional solutions, it has both advantages and disadvantages. Therefore, if you plan to use it, first of all, read about Base64 Data URI.
Comments (12)
I hope you enjoy this discussion. In any case, I ask you to join it.