Search code examples
csspseudo-elementpseudo-class

How to create this text effect with CSS?


Is it possible to create a text effect like this with CSS using some peudo element or so?? This effect where a text element is in the back of the heading text.


Solution

  • Yes, it is possible. Here is a very basic example that I threw together. Essentially, use a position:absolute using the :before CSS selector.

    .block {
      float: left;
      width: 50%;
    }
    
    h2 {
      padding: 1em 0;
    }
    
    h2:before {
      content: attr(data-num);
      position: absolute;
      font-size: 3em;
      line-height: .4em;
      color: #eee;
    }
    
    h2 span {
      position: relative;
      z-index: 1;
    }
    <div class="block">
      <h2 data-num="01"><span>Research</span></h2>
      <p>Lorem ipsum dolor sit amet</p>
      <p><a href="#">Find out more</a></p>
    </div>
    <div class="block">
      <h2 data-num="02"><span>Wireframing</span></h2>
      <p>Lorem ipsum dolor sit amet</p>
      <p><a href="#">Find out more</a></p>
    </div>