我有一个带有背景图片的 div
。但是图像太亮了,所以表单元素在上面看起来不错(页面底部和顶部的白色元素)我添加了一个渐变叠加层,应该从底部变暗
大约 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%;
}
这是 Samsung 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 */
让我知道它是否有效!
关于html - CSS 渐变有条纹(不平滑),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59704665/