Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange behaviour with border-image CSS

I have an image that I would like to use as div's border and background. The below code (and fiddle) produces undesirable white background inside the div despite using background: transparent !important; or background: none !important; (I tried both).

Here's the image I'm using:

enter image description here


Here's the effect I'm getting:

enter image description here


Here's the effect I want:

enter image description here


Strangely, I can achieve the desired effect by opening Web Inspector in Chrome and toggling the border-image property after page render. Simply turning the border-image off and back on, I get the result I want:

enter image description here


HTML

<div>test</div>


CSS

div {
    -webkit-border-image: url(http://img.ctrlv.in/img/14/10/28/544fc2d75c818.png) 30 30 round; /* Safari 3.1-5 */
    -o-border-image: url(http://img.ctrlv.in/img/14/10/28/544fc2d75c818.png) 30 30 round; /* Opera 11-12.1 */
    border-image: url(http://img.ctrlv.in/img/14/10/28/544fc2d75c818.png) 30 30 round;
}


So if the browser can render it, why can't I write it? :) Any help/suggestions would be great.

Please note I have already tried setting the image to be the div's background-image instead of border-image and that did not produce desired results either (scaling the image to prevent the border from getting cut off was simply too much guess work since the textual contents of the div are dynamic).

like image 416
cassidymack Avatar asked Oct 28 '14 17:10

cassidymack


People also ask

Can we apply image to border in CSS True or false?

With the CSS border-image property, you can set an image to be used as the border around an element.

How do I style an image border in CSS?

The border-image property allows you to specify an image to be used as the border around an element. The border-image property is a shorthand property for: border-image-source. border-image-slice.

How do I hide an image border in CSS?

Adding border="0" to your img tag prevents that picture from having a border around the image. However, adding border="0" to every image would not only be time consuming but also increase the file size and download time. To prevent all images from having a border, create a CSS rule or file with the following code.


1 Answers

You're lacking the fill keyword: the standard says:

The ‘fill’ keyword, if present, causes the middle part of the border-image to be preserved. (By default it is discarded, i.e., treated as empty.)

See updated fiddle: writing 30 30 fill seems to solve your issue.

like image 73
Ulrich Schwarz Avatar answered Oct 06 '22 00:10

Ulrich Schwarz