CSS渐变具有条纹(不平滑)

时间:2020-01-12 14:12:22

标签: html css cordova

我有一个div带有背景图片。但是图像太亮了,以至于表单元素看起来不错(页面底部和顶部的白色元素),我添加了一个渐变叠加层,应该darken从底部和顶部{在中心透明。

这是我的代码:

.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上一切正常。

注意到条纹了吗?为什么渐变不平滑?

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试先放置前缀行。如果某些浏览器支持这两种浏览器,则它们可能会使用错误的实现。你可以试试看。

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 */

Css troubleshooting

但是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 */

让我知道它是否有效!