【问题标题】:How to make   same width as regular space?如何使宽度与常规空间相同?
【发布时间】:2021-12-30 01:16:58
【问题描述】:

在学习 HTML 时,我认为   具有相同的宽度,但以下示例显示这不成立。

<!DOCTYPE html>
<html lang="en">
   <meta charset="utf-8" />
</html>
<body style="font-family: Charter">
   Foo Foo&nbsp;Foo
</body>

大多数字体的空格都是相同的,但例如,Charter 不一样(很容易找到其他示例)。这是为什么?我该如何解决?

【问题讨论】:

    标签: html css fonts space


    【解决方案1】:

    来自the Unicode specification的第6章:

    无间断空间。 U+00A0 不间断空间 (NBSP) 是 U+0020 空间的不间断对应物。它具有相同的宽度,但换行的行为不同。

    如果给定字体中空格和不间断空格的宽度不同,那么这是该字体的错误,除了更改字体之外您无能为力。

    【讨论】:

      【解决方案2】:

      您可以随时更改单个空间的字体大小

      <!DOCTYPE html>
      <html lang="en">
         <meta charset="utf-8" />
      </html>
      <body style="font-family: Charter">
         Foo Foo<span style='font-size:10px;'>&nbsp;</span>Foo
      </body>

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-12-05
        • 2012-11-22
        • 1970-01-01
        • 2021-02-09
        • 2018-09-03
        • 2014-03-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多