在 iOS 设备上,border-image 可能会出现以下异常: - 边框不显示或显示不完整 - 边框图片被拉伸变形 - 边框重复模式(repeat)不生效 - 边框宽度与预期不符
.element {
border-image-source: url('border.png');
border-image-slice: 30 fill; /* 确保slice值合理 */
border-image-width: 30px; /* 与slice值匹配 */
border-image-repeat: stretch; /* 或 repeat, round */
}
iOS 的 Safari 可能需要 webkit 前缀:
.element {
-webkit-border-image: url('border.png') 30 30 30 30 stretch;
border-image: url('border.png') 30 30 30 30 stretch;
}
.element {
border-width: 30px; /* 必须设置 */
border-style: solid; /* 必须设置 */
border-image-source: url('border.png');
}
iOS 可能对相对路径处理有问题:
.element {
border-image-source: url('https://example.com/border.png');
/* 或 */
border-image-source: url('data:image/png;base64,...');
}
确保图片: - 尺寸足够大 - 没有透明区域问题 - 使用 PNG 或 SVG 格式
如果问题持续,考虑使用背景图片模拟边框:
.element {
background:
linear-gradient(#000, #000) top / 100% 2px no-repeat,
linear-gradient(#000, #000) right / 2px 100% no-repeat,
linear-gradient(#000, #000) bottom / 100% 2px no-repeat,
linear-gradient(#000, #000) left / 2px 100% no-repeat;
}
通过以上方法,大多数 iOS 上的 border-image 显示问题应该能够得到解决。