Safari vs Chrome/Firefox: border-image vs border-color

删除回忆录丶 提交于 2019-12-06 01:27:50

Here's how you get around that bug:

Instead of

border-color:transparent;

use

border-color:transparent; border-color:initial;

As you discovered, Safari does have a bug related to border-color:transparent, but adding border-color:initial afterwards gets around that bug in Safari, and doesn't cause any additional problems in other browsers that support border-image.

For browsers that don't support border-image (which happens to be just IE <= 10), they happen to also not support the initial value there, so they fall back to border-color:transparent and you don't get a visible border.

Here's the fiddle: https://jsfiddle.net/L78gL7xc/2/

Answers:

Answer 1

Behavior with Chrome and FF is correct behavior.

Answer 2

Remove border-color: transparent.

Or

(Updated answer for IE) use border-color (For support check here - can i use border-color?)

#wrapper { background-color: red; }
#test {
  border-width: 10px;
  border-style: solid;
  border-image-source: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAQMAAADaX5RTAAAABlBMVEUA//////+xuF6gAAAACklEQVQIHWPADQAAGwABJwptqgAAAABJRU5ErkJggg==");
  border-image-slice: 1 1 1 1;
  background: white;
  background-clip: content-box;
}

#test1 {
  border-width: 10px;
  border-style: solid;
  border-color: cyan;
  background: white;
}
<div id="wrapper">
  <div id="test">The border of this box is blue in Chrome and Firefox,
  red in Safari.</div>
</div>

<br>

<div id="wrapper1">
  <div id="test1">Simply use border-color, this property is supported effectively in all browsers.</div>
</div>

Hope this will help you in some way.

I am not sure what you are accepting as correct other than you need the equivalent for the code shown and has good compatibility..

Personally, I do not code my borders as shown. So I simply used the borders how I normally would and that seemed to have the light blue border on MacOS Safari, Chrome, FF, iOS 9, Android and IE 8.

#wrapper { background-color: red; }
#test {
  border: 10px solid transparent;
  border-image-source: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAJAQMAAADaX5RTAAAABlBMVEUA//////+xuF6gAAAACklEQVQIHWPADQAAGwABJwptqgAAAABJRU5ErkJggg==");
  border-image-slice: 1 1 1 1;
  background: white;
  background-clip: content-box;
}
<div id="wrapper">
  <div id="test">The border of this box is blue in Chrome and Firefox,
  red in Safari.</div>
</div>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!