“Táco” is wider than “Taco”. How can I fix that?

后端 未结 2 1338
你的背包
你的背包 2021-01-14 17:29

I\'m trying to load a div with diacritics on top of a div without. The spacing isn\'t working out like I though. (See the snippet below.) How can I fix this?

相关标签:
2条回答
  • 2021-01-14 17:55

    You're going to want to look at font-kerning.

    The font-kerning CSS property controls the usage of the kerning information; that is, it controls how letters are spaced. The kerning information is stored in the font, and if the font is well-kerned, this feature allows spacing between characters to be very similar, whatever the characters are.

    Check out this pen http://codepen.io/anon/pen/JKPMGM, I set kerning to none and they lined up.

    div.text {
            width: 75%;
            position: relative;
            font-kerning:none;
        }
        div.diacritics {
            width: 100%;
            height: 100%;
            position: absolute;
            font-kerning:none;
            top: 0;
            left: 0;
          z-index: -1;
          color: red;
        }
    

    A little more info.

    Kerning adjusts the space between individual letter forms, while tracking (letter-spacing) adjusts spacing uniformly over a range of characters. In a well-kerned font, the two-dimensional blank spaces between each pair of characters all have a visually similar area.

    0 讨论(0)
  • 2021-01-14 18:00

    div.text {
        	    width: 75%;
        	    position: relative;
                font-family: monospace;
        	}
    div.diacritics {
        	    width: 100%;
        	    height: 100%;
        	    position: absolute;
        	    top: 0;
        	    left: 0;
                font-family: monospace;
              z-index: -1;
              color: red;
        	}    	
        <div class="text">String String String String String String String String String String
        	<div class="diacritics">
          Stríng Stríng Stríng Stríng Stríng Stríng Stríng Stríng Stríng Stríng</div>
          </div>
    
        <div class="text">Taco Taco Taco Taco Taco Taco Taco Taco Taco Taco
        	<div class="diacritics">
          Táco Táco Táco Táco Táco Táco Táco Táco Táco Táco</div>
          </div>

    If you are able to make the trade-off, you could always try using a monospace font family.

    0 讨论(0)
提交回复
热议问题