html - CSS渐变有条纹(不平滑)
问题描述
我有一个div
有背景图像的。但是图像太亮了,所以表单元素在上面看起来不错(页面底部和顶部的白色元素)我添加了一个渐变叠加层,它应该darken
从底部和顶部大约 20% 并且在中心是透明的.
所以这是我的代码:
.landing-carousel .carousel-item::before {
background: rgb(111,111,111); /* Old browsers */
background: -moz-linear-gradient(top, rgba(111,111,111,0.1) 0%, rgba(255,255,255,0) 20%, rgba(255,255,255,0) 80%, rgba(111,111,111,0.1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(111,111,111,0.1) 0%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 80%,rgba(111,111,111,0.1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(111,111,111,0.1) 0%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 80%,rgba(111,111,111,0.1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6f6f6f', endColorstr='#6f6f6f',GradientType=0 ); /* IE6-9 */
content: "";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
这是三星 Galaxy A9 的结果(Windows 上也是如此)。但在三星 Galaxy S6/S7/S10 上一切正常。
注意到条纹了吗?为什么渐变不平滑?
解决方案
尝试先放置前缀行。如果某些浏览器同时支持两者,它们可能会使用错误的实现。你可以试试这个。
background: -moz-linear-gradient(top, rgba(111,111,111,0.1) 0%, rgba(255,255,255,0) 20%, rgba(255,255,255,0) 80%, rgba(111,111,111,0.1) 100%); /* FF3.6-15 */
background: -webkit-linear-gradient(top, rgba(111,111,111,0.1) 0%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 80%,rgba(111,111,111,0.1) 100%); /* Chrome10-25,Safari5.1-6 */
background: linear-gradient(to bottom, rgba(111,111,111,0.1) 0%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 80%,rgba(111,111,111,0.1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
background: rgb(111,111,111); /* Old browsers */ //Put this at the end, but i'd just delete this line.
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6f6f6f', endColorstr='#6f6f6f',GradientType=0 ); /* IE6-9 */
但是Caniuse表示现在您可以删除大多数前缀,因为 Chrome 和 Firefox 支持它就好了。所以尝试删除它们,也许只是试试这个
background: linear-gradient(to bottom, rgba(111,111,111,0.1) 0%,rgba(255,255,255,0) 20%,rgba(255,255,255,0) 80%,rgba(111,111,111,0.1) 100%); /* W3C, IE10+, FF16+, Chrome26+, Opera12+, Safari7+ */
background: rgb(111,111,111); /* Old browsers */ //Put this at the end, but i'd just delete this line.
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6f6f6f', endColorstr='#6f6f6f',GradientType=0 ); /* IE6-9 */
让我知道它是否有效!
推荐阅读
- javascript - 无法在画布上设置高度和宽度
- reactjs - 如何合并页脚?
- c# - SystemParameters.IsRemotelyControlled 始终为假
- c# - SqlException 导致所有后续数据库调用失败并出现相同的异常
- sql - Postgres:COALESCE 中的数学函数
- c# - Blazor 使用 HTML 和 CSS 最小化 .NET 中的聊天窗口
- javascript - 从 JavaScript 按提交时如何更改 Html 页面?
- function - Idris,类型加法(增量)
- ada - 使用 STRING_SPLIT 时如何处理索引错误?
- java - 如何在没有存储库的情况下使用 JGIT 创建差异?