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

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

    FWIW, here's my take on this doing it only with CSS: http://codepen.io/ricardozea/pen/uFbts/

    Several notes:

    • The main reason I did this was to test myself and see if I was able to accomplish styling half of a character while actually providing a meaningful answer to the OP.

    • I am aware that this is not an ideal or the most scalable solution and the solutions proposed by the people here are far better for "real world" scenarios.

    • The CSS code I created is based on the first thoughts that came to my mind and my own personal approach to the problem.

    • My solution only works on symmetrical characters, like X, A, O, M. **It does not work on asymmetric characters like B, C, F, K or lower case letters.

    • ** HOWEVER, this approach creates very interesting 'shapes' with asymmetric characters. Try changing the X to a K or to a lower case letter like an h or a p in the CSS :)

    HTML

    
    

    SCSS

    .half-character { 
      display: inline-block;
      font: bold 350px/.8 Arial;
      position: relative;
    
      &:before, &:after {
        content: 'X'; //Change character here
        display: inline-block;
        width: 50%;
        overflow: hidden;
        color: #7db9e8;
      }
      &:after {
        position: absolute;
        top: 0;
        left: 50%;
        color: #1e5799;
        transform: rotateY(-180deg);
      }
    }
    

提交回复
热议问题