首页 > 解决方案 > 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 上一切正常。

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

坡度

标签: htmlcsscordova

解决方案


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

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 疑难解答

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

让我知道它是否有效!


推荐阅读