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

后端 未结 19 1964
轻奢々
轻奢々 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:25

    Edit (oct 2017): background-clip or rather background-image options are now supported by every major browser: CanIUse

    Yes, you can do this with only one character and only CSS.

    Webkit (and Chrome) only, though:

    http://jsbin.com/rexoyice/1/

    h1 {
      display: inline-block;
      margin: 0; /* for demo snippet */
      line-height: 1em; /* for demo snippet */
      font-family: helvetica, arial, sans-serif;
      font-weight: bold;
      font-size: 300px;
      background: linear-gradient(to right, #7db9e8 50%,#1e5799 50%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }

    X

    Visually, all the examples that use two characters (be it via JS, CSS pseudo elements, or just HTML) look fine, but note that that all adds content to the DOM which may cause accessibility--as well as text selection/cut/paste issues.

提交回复
热议问题