4

I can't seem to find anything or anyone that has done this. I'm trying to limit how many images we are using, and would like to create a text with a gradient as its "color" and have a gradient outline/stroke around it

So far, I haven't see anything that has incorporated the two together.

I've can get the text gradient done, by itself, and the text outline gradient by itself. Is there a way to combine to two as one?

h1 {
  text-transform: uppercase;
  font-size: 50px;
  font-weight: 800;
  color: rgb(255, 255, 255);
  background-image: linear-gradient(
    rgb(255, 255, 255) 46%,
    rgb(125, 142, 167) 49%,
    rgb(211, 226, 249) 80%
  );
  text-align: center;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 1px rgb(0, 0, 0);
}
h1::first-letter {
  font-size: 125%;
}

h2 {
  font-size: 50px;
  font-weight: 800;
  text-transform: uppercase;
  text-align: center;
  background: -webkit-linear-gradient(
    -86deg,
    #eef85b 5%,
    #7aec8d 53%,
    #09e5c3 91%
  );
  -webkit-background-clip: text;
  -webkit-text-stroke: 4px transparent;
  color: #232d2d;
}
h2::first-letter {
  font-size: 125%;
}

https://codepen.io/deelite310/pen/OQxXrR

1
  • Double your element and position them absolutely the stroked one behind the other one. (This can't be done with ::after since you do use ::first-letter, and it's not really dynamic, so I won't post it as an answer. Commented Feb 28, 2018 at 3:09

2 Answers 2

3

There's a trick I've implement before, with the use of the "data-*" attribute and the pseudo before selector with z-index of -1. Then you'd need to remove the first-letter pseudo possibly for font-variant: small-caps depending on your needs.

Note: Throwing the layer backwards with z-index=-1 could get overlapped by other elements with a z-index.

h1, h2, h3 {
  font-variant: small-caps;
  font-size: 50px;
  font-weight: 800;
  text-align: center;
  -webkit-background-clip: text;
}

h1, h3 {
  color: rgb(255, 255, 255);
  background-image: linear-gradient(
    rgb(255, 255, 255) 46%,
    rgb(125, 142, 167) 49%,
    rgb(211, 226, 249) 80%
  );
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 1px rgb(0, 0, 0);
}

h2, h3::before {
  background: -webkit-linear-gradient(
    -86deg,
    #eef85b 5%,
    #7aec8d 53%,
    #09e5c3 91%
  );
  -webkit-background-clip: text;
  -webkit-text-stroke: 4px transparent;
  color: #232d2d;
}

h3::before {
  content: attr(data-text);
  position: absolute;
  z-index: -1;
}
<h1>Character</h1>
<h2>Character</h2>
<h3 data-text="Character">Character</h3>

Sign up to request clarification or add additional context in comments.

Comments

0

I would love to see this too... However, the only way I have seen this accomplished is using svg text. there is some good info on this here....

SVG Tutorials

1 Comment

thanks I am using SVG on some issues, but It becomes an issue when I need responsive text. Especially on word wrapping. SVG you need to pUt your line breaks in, otherwise, your sVG/viewport goes against each other

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.