Is it possible to apply CSS to half of a character?

后端 未结 19 1596
轻奢々
轻奢々 2020-11-22 16:46

What I am looking for:

A way to style one HALF of a character. (In this case, half the letter being transparent)

Wh

19条回答
  •  孤街浪徒
    2020-11-22 17:27

    You can use below code. Here in this example I have used h1 tag and added an attribute data-title-text="Display Text" which will appear with different color text on h1 tag text element, which gives effect halfcolored text as shown in below example

    body {
      text-align: center;
      margin: 0;
    }
    
    h1 {
      color: #111;
      font-family: arial;
      position: relative;
      font-family: 'Oswald', sans-serif;
      display: inline-block;
      font-size: 2.5em;
    }
    
    h1::after {
      content: attr(data-title-text);
      color: #e5554e;
      position: absolute;
      left: 0;
      top: 0;
      clip: rect(0, 1000px, 30px, 0);
    }

    Display Text

提交回复
热议问题