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

后端 未结 19 1940
轻奢々
轻奢々 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 also do it using SVG, if you wish:

    var title = document.querySelector('h1'),
        text = title.innerHTML,
        svgTemplate = document.querySelector('svg'),
        charStyle = svgTemplate.querySelector('#text');
    
    svgTemplate.style.display = 'block';
    
    var space = 0;
    
    for (var i = 0; i < text.length; i++) {
      var x = charStyle.cloneNode();
      x.textContent = text[i];
      svgTemplate.appendChild(x);
      x.setAttribute('x', space);
      space += x.clientWidth || 15;
    }
    
    title.innerHTML = '';
    title.appendChild(svgTemplate);
    
        
            
                
                
            
        
        
    
    
    

    This is not a solution X

    http://codepen.io/nicbell/pen/jGcbq

提交回复
热议问题