html - 线性渐变在 Safari 上不显示正确的颜色
问题描述
我有<div>
一个简单的CSS:
.mapTop {
z-index: 12;
display: flex;
align-items: center;
padding-left: 30px;
position: absolute;
top: 0;
width: 100%;
height: 96px;
background-image: linear-gradient(to top, rgba(45,59,78,0), #fff);
box-sizing: border-box;
border-radius: 4px;
}
body {
background: #F4F5F6;
}
<div class="mapTop">
</div>
在所有其他浏览器中,它看起来像这样: https ://i.stack.imgur.com/394Pt.png
但在 Safari 中,它看起来像这样: https ://i.stack.imgur.com/IUYaC.png
这是为什么?
解决方案
根据我在 CSS-Tricks 上阅读的内容,Safari 将渐变背景中的透明解释为“透明黑色”。这是链接:https ://css-tricks.com/thing-know-gradients-transparent-black/
所以,只需使用:
.mapTop {
background-image: -webkit-gradient(linear, left bottom, left top, from(rgba(255,255,255,0)), to(#fff));
background-image: -o-linear-gradient(bottom, rgba(255,255,255,0), #fff);
background-image: linear-gradient(to top, rgba(255,255,255,0), #fff);
}
我还为它添加了自动前缀,因此它与所有浏览器兼容(IE 除外)
推荐阅读
- php - 如何在资源类中加载嵌套关系的数据
- visual-studio - 如何修复 Visual Studio 中的附加按钮和运行按钮?
- systemd - Puma systemd 重启超时并且似乎失败,即使它实际上已经成功
- json - 如何将对象参数作为哈希表传递给 json arm 模板?
- youtube-iframe-api - Youtube iframe API - origin 参数问题 - origin=https%3A%2F%2Fwww.test.com
- tableau-desktop - 如何开始使用行级安全性?
- javascript - index.php:27 未捕获类型错误:无法读取未定义的属性“长度”
- python - ctypes cast() 在将 int 指针转换为浮点指针时返回 nan
- sql - 使用 now() 增量更新时间戳字段
- javascript - mailto: 不在 UncontrolledTooltip 上工作