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

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

    This can be achieved with just CSS :before selector and content property value.

    .halfed, .halfed1 {
      float: left;
    }
    
    .halfed, .halfed1 {
      font-family: arial;
      font-size: 300px;
      font-weight: bolder;
      width: 200px;
      height: 300px;
      position: relative; /* To help hold the content value within */
      overflow: hidden;
      color: #000;
    }
    
    
    
    
    .halfed:before, .halfed1:before   {
      width: 50%; /* How much we'd like to show */
      overflow: hidden; /* Hide what goes beyond our dimension */  
      content: 'X'; /* Halfed character */
      height: 100%;
      position: absolute;
      color: #28507D;
    
    }
    
    
    
    /* For Horizontal cut off */ 
    
    .halfed1:before   {
      width: 100%;
      height: 55%;
      
    }
    X
    X

    >> See on jsFiddle

提交回复
热议问题