How to create small SPACES in HTML?

后端 未结 5 1911
傲寒
傲寒 2021-01-31 09:08

There is em dash and en dash. Is there an \"en\" equivalent to   ? Is there an en equivalent to pure Ascii 32?

I want a better way to

5条回答
  •  天涯浪人
    2021-01-31 09:39

    ... and various other non-standard space characters are not properly implemented in some fixed fonts.

    This will will foul up your rendering on the web browser end in an uncontrollable manner, and you can't fix it by being specific about the font, because you can't control what actual font is being used by the web browser — even if you specify the font-name or font-family, that doesn't mean the font they have is the same as the font you have.

    But you can build a 100%-compatible space of any size you want, though, and it's very easy. The em value is the current font-size. It's the height, but whatever the width of the font is, it's always a constant relative to the height in a fixed-width font. So you can take advantage of that.

    Here's how to make a 1/2 width, non-breaking space within the context of a fixed-width font that works with everything. I show it implemented in a span's style="" option, but of course you can make a CSS class instead to make its use less clumsy:

     
    

    Here's how to make a 1/4 width, non-breaking space:

     
    

    ...and so on.

    This always works with space sizes smaller than the current full-width space because the character is shorter than the other characters on the line, so they control the line spacing, not the shorter character.

    If you want a space that is wider than one space, use a combination of full spaces and shorter spaces. While you will get a wider space if you use something like 1.5em, you will also get a taller space, and so that will affect the line spacing.

    While this solution is annoyingly cumbersome, it has the desirable attribute of always working — which none of the others do.

提交回复
热议问题