Reputation: 1514
I have tried a lot of solutions without success.
I would like to create a linear gradient from left to right, which starts with transparent and ends up in black.
.box1 {
border: solid 1px #ccc;
margin: 10px;
max-width: 500px;
height: 40px;
position: relative;
font-size: 30px;
white-space: nowrap;
overflow: hidden;
background-color: #2d2d2d;
color: red;
}
.box1::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-image: linear-gradient(
to right, rgba(255,255,255,0.01), #2d2d2d
);
}
.box2 {
border: solid 1px #ccc;
margin: 10px;
max-width: 500px;
height: 40px;
position: relative;
font-size: 30px;
white-space: nowrap;
overflow: hidden;
background-color: #2d2d2d;
color: red;
}
.box2::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 100px;
background-image: linear-gradient(
to right, rgba(255,255,255,0), #2d2d2d
);
}
.box3 {
border: solid 1px #ccc;
margin: 10px;
max-width: 500px;
height: 40px;
position: relative;
font-size: 30px;
white-space: nowrap;
overflow: hidden;
background-color: rgba(45,45,45,1);
color: red;
}
.box3::before {
content: "";
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 100px;
background: linear-gradient(to right, rgba(255,255,255,0) 0%,rgba(45,45,45,1) 100%);
}
.fade1 {
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 75px;
background: linear-gradient(
to right, rgba(255,255,255,0), black
);
}
.box {
border: solid 1px #ccc;
margin: 10px;
max-width: 500px;
height: 40px;
position: relative;
font-size: 30px;
white-space: nowrap;
overflow: hidden;
background-color: black;
color: white;
}
<div class="box1">
</div>
<div class="box2">
</div>
<div class="box3">
</div>
<div class="box">
<span class="fade1"></span>
</div>
Also here is a codepen for you.
Chrome renders it the way I want, but on Safari the result is not the same. Instead of having transparent "color" it has white or white-ish color.
I know transparent keyword has a different behavior on Safari, so I do not use it at all.
Do you guys have a solution?
Upvotes: 1
Views: 425
Reputation: 1514
Okay. It turned out on Safari the transparent color should have the same rgb as the end color.
So:
.fade1 {
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 75px;
background: linear-gradient(
to right, rgba(0,0,0,0), black
);
}
.box {
border: solid 1px #ccc;
margin: 10px;
max-width: 500px;
height: 40px;
position: relative;
font-size: 30px;
white-space: nowrap;
overflow: hidden;
background-color: black;
color: white;
}
<div class="box">
adsfasdfsdafasdfdasfdasfasdfdasfdasfdsfdasf
<span class="fade1"></span>
</div>
Upvotes: 1