<h1>Fun with line-height</h1>

<section> 
  <h2>Funsville</h2>
  <p>When you know the line-height, you can make a linear-grdient that has hard color stops in between each line of text. Gaperiam nemo saepe sunt enim, perferendis aut numquam est doloremque tempora molestias in vero? Eius animi odit earum, fugit optio.</p>
</section>

<section>
  <h2>Emphasize Start</h2>
  <p>It's easiest when the background starts on top of the text like in this case, consectetur adipisicing elit. Corrupti cupiditate, aperiam nemo saepe sunt enim, perferendis aut numquam est doloremque tempora molestias in vero? Eius animi odit earum, fugit optio. Corrupti cupiditate, aperiam nemo saepe sunt enim, perferendis aut numquam est doloremque tempora molestias in vero? Eius animi odit earum, fugit optio</p>
</section>

<section>
  <h2>Fade Out Bottom</h2>
  <p>But we can also make it work for the bottom of text (depite its length) by using calc() in the gradients, substracting it from the elements full height. Sit amet, consectetur adipisicing elit. Corrupti cupiditate, aperiam nemo saepe sunt enim, perferendis aut numquam est doloremque tempora molestias in vero? Eius animi odit earum, fugit optio. Corrupti cupiditate, aperiam nemo saepe sunt enim, perferendis aut numquam est doloremque tempora molestias in vero? Eius animi odit earum, fugit optio</p>
</section>

<section> 
  <h2>Lines</h2>
  <p>There are plenty of little things that can screw this up, but if you're careful, you can create a 1px gradient that repeats at the current line-height so that it's between lines of text no matter what. I first saw Lea Verou do this. Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti cupiditate, aperiam nemo saepe sunt enim, perferendis aut numquam est doloremque tempora molestias in vero? Eius animi odit earum, fugit optio.</p>
</section>

<section>
  <h2>Ticks</h2>
  <p>You can set the background-size of an image to match the line-height, so that it's always the same size of a line. Perferendis Lorem ipsum dolor sit amet, consectetur adipisicing elit. Corrupti cupiditate, aperiam nemo saepe sunt enim, perferendis aut numquam est doloremque tempora molestias in vero? Eius animi odit earum, fugit optio. Corrupti cupiditate, aperiam nemo saepe sunt enim, perferendis aut numquam est doloremque tempora molestias in vero? Eius animi odit earum, fugit optio</p>
</section>
$lh: 1.4em;

body {
  font-size: 1em;
  line-height: $lh;
}

h1 {
  background: #333;
  margin: 0;
  padding: 5% 20%;
  text-transform: uppercase;
  color: #eee;
  font-size: 2em;
}

section {
  padding: 5% 20%;
  h2 {
    margin: 0 0 $lh 0;
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.5em;
    font-size: 1em;
  }
  p {
    margin: 0 0 1em 0;
  }
  @media (max-width: 400px) {
    padding: 10%;
  }
}

section:nth-of-type(1) {
  background: #082838;
  @supports (-webkit-background-clip: text) {
    p {
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-image: linear-gradient(
        to bottom,
        #9588DD,
        #9588DD $lh,
        #DD88C8 $lh,
        #DD88C8 $lh*2,
        #D3DD88 $lh*2,
        #D3DD88 $lh*3,
        #88B0DD $lh*3,
        #88B0DD);
    }
  }
}

section:nth-of-type(2) {
  background: #111;
  p {
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-image: linear-gradient(
      to bottom,
      rgba(white, 0.8),
      rgba(white, 0.8) $lh,
      rgba(white, 0.6) $lh,
      rgba(white, 0.6) $lh*2,
      rgba(white, 0.4) $lh*2,
      rgba(white, 0.4) $lh*3,
      rgba(white, 0.2) $lh*3,
      rgba(white, 0.2));
  }
}

section:nth-of-type(3) {
  background: #333;
  p {
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-image: linear-gradient(
      to bottom,
      rgba(white, 0.8),
      rgba(white, 0.8) calc(100% - 66px),
      rgba(white, 0.6) calc(100% - 66px),
      rgba(white, 0.6) calc(100% - 44px),
      rgba(white, 0.4) calc(100% - 44px),
      rgba(white, 0.4) calc(100% - 22px),
      rgba(white, 0.2) calc(100% - 22px),
      rgba(white, 0.2));
  }
}

section:nth-of-type(4) {
  padding: $lh*2;
  background: #082838;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(white, 0)   0,
    rgba(white, 0) $lh/1em*16px-1,
    rgba(white, 0.1) $lh/1em*16px-1,
    rgba(white, 0.1) $lh/1em*16px
  );
  p {
    opacity: 0.75;
    color: white;
  }
}

section:nth-of-type(5) {
  background: #111;
  p {
    color: #999;
    background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/3/tick.svg");
    padding-left: $lh*2;
    background-size: $lh $lh;
    background-repeat: repeat-y;
  }
}
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.