Although I've found similar questions, none explicitly match my goal.
I'm trying to display text with a gradient colour, with low opacity (so you can see the background through it), but also with a (matching) solid gradient border (i.e. text-stroke). I've discovered that answers to similar questions develop a workaround by creating a ::before
underlay state that replicates a (gradient) border effect, but changing the opacity on the text's natural state just displays the colour of the ::before
underlay text instead of the background colour (the desired result).
What I'm wondering is, is there any workaround to effectively create a solid gradient text-stroke with (internal) gradient text that has an opacity lower than 1?
Using the aforementioned other similar questions, I've developed the following code over a period of hours but can't quite figure out how it can be done. You'll notice in my code that I've used different rgba
values - this was simply done to view the result more easily and see if I acheived my intended goal of making the (internal) text have opacity (to enable the background to be seen), as opposed to using identical colours. The more opacity I apply, the more you can see the gradient colours of the workaround/makeshift text-stroke.
body {
background: #000000;
}
h1 {
font-size: 60px;
font-weight: 800;
font-family: arial;
color: rgb(255, 255, 255);
background-image: linear-gradient(to left,
rgba(255, 0, 0, 0.7),
rgba(0, 0, 255, 0.7),
rgba(255, 0, 0, 0.7));
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
margin: 10px;
}
h1::before {
content: attr(data-text);
background: -webkit-linear-gradient(-180deg, #3399ff, #82ed89, #3399ff);
-webkit-background-clip: text;
-webkit-text-stroke: 5px transparent;
position: absolute;
z-index: -1;
}
<h1 data-text="Text">Text</h1>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…