0

I've got a mock-up (img) that I'm attempting to replicate and I'm having a hard time getting everything in just the right place (img).

If I didn't have the gradient over the top this would be easy -- I would just use two separate h1 elements and move them around as needed. The problem is if I do that, the gradient doesn't persist over both elements (img).

I can do other styling changes to the second word (like making it smaller or changing its colour) by wrapping it inside of another tag but I just want to move it slightly up and slightly to the left and that doesn't seem to work.

Here is some working code, does anyone have any thoughts?

#foo {
  font-family: 'Fugaz One', 'arial black', sans-serif;
 position: relative;
 transform: rotate(-7.7deg);
 color: transparent;
 -webkit-background-clip: text;
 background-clip: text;
 background-image: -webkit-linear-gradient(7.7deg, #ef8181, #fa9551); 
 background-image:    -moz-linear-gradient(7.7deg, #ef8181, #fa9551); 
 background-image:     -ms-linear-gradient(7.7deg, #ef8181, #fa9551); 
 background-image:      -o-linear-gradient(7.7deg, #ef8181, #fa9551); 
 background-image:         linear-gradient(7.7deg, #ef8181, #fa9551); 
 font-size: 16vw;
 left: -2vw;
 top: -10vh;
}
<h1 id="foo">TEXT<br>THERE</h1>
Josh McGee
  • 443
  • 6
  • 16

2 Answers2

2

#foo {
  display: flex;
  flex-direction: column;
  font-family: 'Fugaz One', 'arial black', sans-serif;
  position: relative;
  color: transparent;
  -webkit-background-clip: text;
  background-clip: text;
  transform: skew(-10deg) rotate(-7.7deg);
  line-height: 0.9;
  background-image: -webkit-linear-gradient(7.7deg, #ef8181, #fa9551);
  background-image: -moz-linear-gradient(7.7deg, #ef8181, #fa9551);
  background-image: -ms-linear-gradient(7.7deg, #ef8181, #fa9551);
  background-image: -o-linear-gradient(7.7deg, #ef8181, #fa9551);
  background-image: linear-gradient(7.7deg, #ef8181, #fa9551);
  font-size: 16vw;
}

span {
  margin-left: 15px;
  margin-bottom: 5px;
}

span:nth-child(even) {
  margin-left: 35px;

}
<h1 id="foo"><span>TEXT</span><span>THERE<span></h1>

I would recommend adding line-height and text-indent to #foo. I added

#foo { line-height: 13vw; text-indent: 11px; }

line-height will help reduce the spacing between each work, and text-indent helps offset the text since it has been rotated. I hope this helps :).

As a side note an SVG would be a great option to use here instead of CSS.

Rafael
  • 3,593
  • 3
  • 17
  • 27
  • Thanks for the response. I haven't used SVG before, is there any chance you could show a quick example of how you could move each line individually while having the same gradient persistent across both? – Josh McGee Dec 07 '18 at 04:13
  • 1
    In order to move each word individually, you should wrap each word in a `span` tag. `span` tags by default display inline so it won't impact the gradient. Lastly, you can use `margin-left` to move the `span` individually. `text-indent` won't work on span tags because they're inline elements. `

    TEXT
    THERE

    `
    – Rafael Dec 07 '18 at 04:23
  • ah great! I had tried using span to select the second word individually, but didn't think of using margin-left. That's perfect, moves it left and right exactly how I wanted it to. Do you know what I would do to move up and down? I've tried using transform:translate() and margin-top and they don't seem to work? – Josh McGee Dec 07 '18 at 04:32
  • Margin top/bottom doesn't work for inline elements. Another route you could take is to remove the `
    `and control the line breaking manually. This can be done by applying `display: flex`, `flex-direction: column`, and `line-height: 14vw` to `#foo`. Now the span tags are flex children and margin top/bottom will work.
    – Rafael Dec 07 '18 at 04:44
  • sorry, I haven't worked with flex before, can you give an example of what you mean? My html looks like this and I think that because the span elements are within the h1, it thinks that there's only one element in the flex box?

    TEXT HERE

    – Josh McGee Dec 07 '18 at 05:05
  • I've updated my answer for you to see a working example. – Rafael Dec 07 '18 at 05:19
1

You can adjust the vertical spacing between the two words with the line-height property. You can move the second word to the left by using the text-indent property to move the first line/word to the right and then offsetting the left property.

#foo {
  font-family: 'Fugaz One', 'arial black', sans-serif;
 position: relative;
 color: transparent;
 -webkit-background-clip: text;
 background-clip: text;
        transform:skew(-10deg) rotate(-7.7deg);
        line-height: 0.9;
        text-indent:-10px;
 background-image: -webkit-linear-gradient(7.7deg, #ef8181, #fa9551); 
 background-image:    -moz-linear-gradient(7.7deg, #ef8181, #fa9551); 
 background-image:     -ms-linear-gradient(7.7deg, #ef8181, #fa9551); 
 background-image:      -o-linear-gradient(7.7deg, #ef8181, #fa9551); 
 background-image:         linear-gradient(7.7deg, #ef8181, #fa9551); 
 font-size: 16vw;
 left: 0vw;
 top: -10vh;
}
<h1 id="foo">TEXT<br>THERE</h1>

P.S. I also added a little bit Skew to the transform property. I think in general an easier approach would be to keep each word in a separate h1 element and create two separate linear gradients, one applied to the first word and the other to the second.

Hope this helps. Good luck!

Neil VanLandingham
  • 1,016
  • 8
  • 15
  • thanks for the response. I had used line-height before, but the problem is that it chops off the top of some of my letters (S, B and C specifically) when the distance between the two words was too close. Good work around using text-indent, but I'm wondering if there's another way to do it that is a bit more general? Say if there was a paragraph of text and you just wanted to move one of the words in the middle slightly offset from the rest? – Josh McGee Dec 07 '18 at 04:04
  • hmm the skew doesn't seem to help the top of the letters from being chopped for me. And also by skewing the text it makes it less like the mock-up objective. I thought about having separate h1 with separate gradient colours (selected from the mock-up), but I've got got lots of lines that this applies to and there's got to be a more efficient way than copying and pasting all of those colour codes. – Josh McGee Dec 07 '18 at 04:25