gpt4 book ai didi

css - 将线性渐变与背景混合

转载 作者:太空宇宙 更新时间:2023-11-04 03:03:39 25 4
gpt4 key购买 nike

我希望允许单行元素溢出其容器并水平滚动,但需要淡出效果而不是在外部元素的边缘进行硬切割。

具有线性渐变的伪元素:

 <div class="bg">
<span class="white">Lorem ipsum dolor....</span>
</div>

.bg {
width: 700px;
height: 500px;
margin: auto;
position: relative;
background: white;
box-shadow: 0 0 23px 2px rgba(0,0,0,0.5);
overflow: hidden;
}
.white {
color: #4a525a;
display: inline-block;
padding: 0 100px;
width: 700px;
font-size: 40px;
line-height: 500px;
white-space: nowrap;
overflow: scroll;
-webkit-overflow-scroll: touch;
}
.bg::before {
content:"";
position: absolute;
top: 0;
left: 0;
width: 100px;
height: 100%;
background-image: linear-gradient(to right, white 30%, transparent);
}
.bg::after {
content:"";
position: absolute;
top: 0;
right: 0;
width: 100px;
height: 100%;
background-image: linear-gradient(to left, white 30%, transparent);
}

演示:http://codepen.io/Megagator/pen/jPLzPe?editors=110

这在 Chrome 和 Firefox 中按预期工作,但是 Safari 混合渐变和背景不正确。有没有更兼容的方法来使用 CSS 实现这种效果?

最佳答案

实际上,Safari 严格遵循透明速记的标准:

transparent
Fully transparent. This keyword can be considered a shorthand for transparent black, rgba(0,0,0,0), which is its computed value.

http://www.w3.org/TR/css3-color/#transparent

明确声明白色透明解决了这个问题:

background-image: linear-gradient(to right, white 30%, rgba(255,255,255,0));

关于css - 将线性渐变与背景混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30872407/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com