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

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

    Enter image description here

    I just played with @Arbel's solution:

    var textToHalfStyle = $('.textToHalfStyle').text();
    var textToHalfStyleChars = textToHalfStyle.split('');
    $('.textToHalfStyle').html('');
    $.each(textToHalfStyleChars, function(i,v){
        $('.textToHalfStyle').append('' + v + '');
    });
    body{
        background-color: black;
    }
    .textToHalfStyle{
        display:block;
        margin: 200px 0 0 0;
        text-align:center;
    }
    .halfStyle {
        font-family: 'Libre Baskerville', serif;
        position:relative;
        display:inline-block;
        width:1;
        font-size:70px;
        color: black;
        overflow:hidden;
        white-space: pre;
        text-shadow: 1px 2px 0 white;
    }
    .halfStyle:before {
        display:block;
        z-index:1;
        position:absolute;
        top:0;
        width: 50%;
        content: attr(data-content); /* dynamic content for the pseudo element */
        overflow:hidden;
        color: white;
    }
    
    Dr. Jekyll and M. Hide

提交回复
热议问题