【问题标题】:Finer Control of Text Accent/Boldness Through CSS通过 CSS 更好地控制文本重音/粗体
【发布时间】:2019-07-26 06:26:44
【问题描述】:

我一直在尝试一些方法来使用 CSS 为字体粗细创建更好的控制。我们在 IE、Edge、Chrome、Safari、Opera 和 Firefox 中运行以下操作系统/设备要求。只需要现代浏览器,不需要旧的东西。

操作系统支持/设备要求

现代浏览器:适用于 PC/笔记本电脑的 Windows、MAC、iOS、Android、Linux 移动设备:iPhone 4+、三星 S2+、iPad 平板电脑、三星平板电脑、Windows 平板电脑

总结

我已经包含了一个包含三个不同测试用例的工作示例。 first 测试用例过于模糊,尤其是在 IE/Edge 中。它在某些操作系统/设备/浏览器上不太模糊,但不够统一,无法满足我们的需求。它使用text-shadow: 1px 1px #999; 设置粗体。

第二个测试用例在所有设备/操作系统/浏览器上的外观最为统一,但呈现出一些模糊性。它使用text-shadow: 1px 0.1px rgba(0, 0, 0, 0.35); 来实现更精细的粗体分辨率。

第三个测试用例对于我们的用例来说太粗了。它使用color: #000;font-weight: 600; 设置粗体。我尝试了较浅的颜色,但仍然留下较粗的字符,这是我们不想要的。

有人知道解决这个问题的更好方法吗?

更新

我选择的答案指向了具有所需半色调字体粗细的字体样式,这是我在原始问题中要求的更好方法。

我最初的问题没有充分说明我现在在此处添加的两个主要目标。

所需功能:

  1. 类似于 Arial 的字体粗细,介于网络安全 Arial 字体中的字体粗细之间。
  2. 一种在不增加正常文本间距和不使用不同颜色的情况下突出显示某些文本的方法。

上述第 1 项已通过此问题的答案得到解决。通过切换到类似于 Arial 的 Google 字体,实现了所需的半色调。此外,我们的用户对新基本字体的反馈都是积极的。更清晰、更易于阅读、不那么皱巴巴等。大约 17K 的下载非常值得。

原始问题的 cmets 是正确的。文本阴影功能不能用于使用 CSS 创建字体粗细。为什么?

  1. 字体粗细通常用于创建一组可缩放字体,这些字体的字体粗细随着字体粗细数字的增加而增加,即 500、600、700 等。关键字是可缩放的。字体粗细 500 和 600 会随着字体大小的增加而保持其纵横比。

下图说明了字体粗细的可伸缩性。

  1. Text-shadow 为给定字体添加了固定的文本效果。随着字体大小的增加,阴影效果会减弱。例如,对于 50 像素或 70 像素的字体大小,肉眼可能看不到 16 像素文本字体的细微文本效果。这里的关键点是 文本阴影不会随着字体大小的增加而线性缩放

下图说明了 CSS 中 box shadow 和 text-shadow 的固定性质。最小的盒子被它的阴影相形见绌,而最大的盒子上的阴影效果相对于元素大小来说是很小的。

我将为这个问题添加另一个答案,试图解决我的更新要求并包含我的特定解决方案的详细信息。

感谢大家的帮助和反馈。

body {
  padding: 0;
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: normal;
  font-size: 15px;
  font-style: normal;
  font-variant: normal;
  text-transform: none;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -webkit-font-smoothing: subpixel-antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #383838;
  width: 100%;
  height: 100%;
  -webkit-text-size-adjust: none !important;
  -ms-text-size-adjust: none !important;
  -moz-text-size-adjust: none !important;
  border: none;
  text-align: center;
  text-rendering: optimizelegibility;
  min-width: 300px !important;
}

h3,
h4,
h5,
h6 {
  display: block;
  font-family: inherit;
  line-height: 1.1;
  color: #000;
  opacity: 1.0;
  font-weight: normal;
  text-align: center;
  margin: 10px auto 6px auto;
  font-size: 1em;
}

h3 {
  font-size: 1.05em;
}

h4 {
  font-size: 1.1em;
}

h5 {}

h6 {
  margin: .25em auto;
}

.center-block {
  display: block;
  width: auto;
  text-align: center;
  margin-right: auto;
  margin-left: auto;
}

.test-boldness {
  text-shadow: 1px 0.1px rgba(0, 0, 0, 0.23);
}

.bold {
  font-weight: 500;
  color: #000;
}

.bolder {
  font-weight: 500;
  color: #000;
  text-shadow: 1px 0.1px rgba(0, 0, 0, 0.35);
}

.boldest {
  color: #000;
  font-weight: 600;
}

.test-boldness {
  text-shadow: 1px 0.1px rgba(0, 0, 0, 0.35);
}

.test-boldness-1pxsolid {
  text-shadow: 1px 1px #999;
}

div {
  font-family: inherit;
  color: #383838;
}
<!DOCTYPE html>

<head></head>
<html>

<body>
  <br />
  <br />
  <div class="center-block"><span class="test-boldness-1pxsolid">How Used: </span>Visible accent. This one has most blurring on all required OS/devices.</div>
  <br />
  <div>
    <span style='font-weight: 300'>300</span>
    <span style='font-weight: 400'>400</span>
    <span style='font-weight: 500'>500</span>
    <span class='test-boldness'>Custom 550</span>
    <span style='font-weight: 600'>600</span>
    <span style='font-weight: 700'>700</span>
    <br />
    <br />
    <div class="center-block"><span class="test-boldness">How Used: </span>Visible accent. Less blurring/most uniform on required OS/devices. Is there a better way to do this?</div>
    <br />
    <br />
    <div class="center-block"><span class="boldest">How Used: </span>Visible accent. This one is clearest but too bold, especially on some of the required OS/devices.</div>
    <br />
    <h3>Test Cases</h3>
    <br />
    <h3 class="test-boldness-1pxsolid">TEST ABCDKTM test abcdktm-1pxsolid</h3>
    <h3 class="test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</h3>
    <h3>TEST ABCDKTM test abcdktm</h3>
    <h4 class="test-boldness-1pxsolid">TEST ABCDKTM test abcdktm-1pxsolid</h4>
    <h4 class="test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</h4>
    <h4>TEST ABCDKTM test abcdktm</h4>
    <h5 class="test-boldness-1pxsolid">TEST ABCDKTM test abcdktm-1pxsolid</h5>
    <h5 class="test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</h5>
    <h5>TEST ABCDKTM test abcdktm</h5>
    <h6 class="test-boldness-1pxsolid">TEST ABCDKTM test abcdktm-1pxsolid</h6>
    <h6 class="test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</h6>
    <h6>TEST ABCDKTM test abcdktm</h6>
    <div class="center-block bold test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</div>
    <div class="center-block bold">TEST ABCDKTM test abcdktm</div>
    <div class="center-block bolder test-boldness">TEST ABCDKTM test abcdktm font-weight: 500</div>
    <div class="center-block bolder">TEST ABCDKTM test abcdktm font-weight: 500</div>
    <div class="center-block boldest">TEST ABCDKTM test abcdktm font-weight: 600</div>
    <div class="center-block boldest">TEST ABCDKTM test abcdktm font-weight: 600</div>

</body>

</html>

【问题讨论】:

  • 网络不是印刷媒体。你没有得到同样精细的控制。如果您的浏览器/字体不支持不同的字体粗细,那就没有什么可做的了。
  • @Cody 感谢您抽出宝贵时间回复。我知道 Windows 应用程序与 Web 应用程序之间的区别。我也做了很多 C、C++、C# 开发。开箱即用的 Web 浏览器字体权重不会这样做。但是,我认为您所做的声明在技术上是不准确的,即如果浏览器不支持不同的字体粗细,就没有什么可做的了。查看我更新的代码,300 400 500 自定义(见案例 2)600 700。这确实弥合了 FW 500 和 600 之间的差距。我的问题不是是否可以做某事,它可以。问题是:如何做得更好(不那么模糊)。再次感谢。
  • 通过添加阴影来模拟粗体是一种反模式。除了它非常模糊(并且不可避免地会,考虑到你是如何实现它的)这一事实之外,它并没有传达与“粗体”相同的语义。通过寻找一种实现您想要的权重的字体,然后在您的网站上使用该字体而不是标准(有限)网络安全字体之一,您会得到更好的服务。
  • 您可能正在为大多数浏览器不像设计程序那样抗锯齿这一事实而苦苦挣扎,因此您的字体粗细并不完全符合您的期望(浏览器呈现更粗的方式是我会描述它)。看看这篇文章。我敢打赌,如果您抗锯齿,您可以获得您希望的重量(您在图形设计程序中看到的重量)。 devhints.io/css-antialias
  • @Cody Gray 有什么具体原因您不考虑导入相关的font-family 来解决问题吗?

标签: html css


【解决方案1】:

我没有阅读问题或答案,因为它们都太长了,但我添加这个以防它解决其他人的问题。

就我而言,我可以使用 -webkit-text-strike-width 很好地控制文本粗体。

【讨论】:

    【解决方案2】:

    我对我们扩展要求的回答

    我想为那些试图处理我在原始问题中提到的一个或两个问题的其他人记录我们的方法。

    正如其他人已经指出的那样,您无法使用 CSS text-shadow 实现中间字体粗细。如果您尝试使用 JavaScript 和 CSS 来模拟字体粗细(真是个坏主意),那将会非常复杂,而且您永远无法实现字体粗细功能提供的良好跨平台一致性。

    旁注:注意 JavaScript 一词的 Stack Overflow 字体加粗。 font-width 和 height 在 Firefox 中明显更大,这就是我现在使用的。这是更改内联文本字体粗细的正常副作用。

    问题 1. 缺少字体粗细(减少粗体增量)

    以下说明了我们一直试图解决的两个问题之一。第一个示例使用网络安全字体。第二个使用Open-Sans 来实现所需的半色调字体粗细。 这解决了我们的第一个问题。不,我没有大喊大叫。没有办法在 SO 上添加微妙的文本效果,也不需要。 Here is a good link with font images。本文档引导我选择 Open Sans 字体。

    第一个粗体字体是我们使用的网络安全字体的唯一选择。第二个是我们从谷歌下载的 Open Sans 字体。粘贴的图像不符合字体正义。如果你运行代码 sn -p,你会看到它真正的样子。

    从上面,您可以使用网络安全的 Arial 字体系列观察更粗的字体粗细如何影响文本。 Open Sans 字体更像我们正在寻找的字体。但是,如果您想为一个单词或一组单词添加内嵌强调,则在 500 和 600 字体粗细之间切换会导致字体高度显着增加和字体变粗。这在 MHO 中,从美学角度来看并不是最佳解决方案。

    问题 2. Subtle Text Accents(小于下一个不改变文本宽度或高度的字体粗细)

    首先,使用文本阴影效果比较上述两个表格的更微妙的版本(如下)。

    如果您运行 sn-p 并使用 + 键放大一两级,文本重音仍然可以辨别。

    下面的表格要小一些,因为文本阴影不会影响元素的宽度或高度(请参阅下面的 W3.org 注释)。文本阴影可能会侵犯相邻字符,这可能是坏的或好的,这取决于设计者的意图。 顺便说一句,我们的用户 100% 选择了第二组突出显示的表格字体。他们说它们看起来更清晰、更干净、更锐利、不那么厚等等。

    来自 W3.org:

    • 与 box-shadow 不同,文本阴影不会被剪裁到阴影形状,并且如果文本是部分透明的,则可能会显示出来。
    • 与 box-shadow 一样,文本阴影不会影响布局,也不会触发滚动或增加可滚动区域的大小。

    请看下面的段落。它包含在代码 sn-p 中。很容易挑选出一组比相邻文本更粗且略高的突出显示的单词。如果您运行 sn-p,您会注意到字体比下面的复制图像更清晰。我们的用户非常喜欢内嵌文本和表格的更微妙的文本突出显示。

    对于我们希望强调的字词,我们一直使用较深的文本颜色。对于较大的字体,我们的用户说它“足够”,但“不是很好”。他们的抱怨是,对于较小的字体,颜色差异并不明显。

    问题是黑色#000 字体会随着字体变小而变成浅灰色阴影(见下图),这是我们无法更改的字体渲染问题。这是我们的第二期

    我们能够解决这个问题,令我们满意的是,我们添加了一个小的/水平的亚像素文本阴影。我们能够实现相对清晰、看起来更大胆的文本重音,即使字体大小增加(比如 14 像素到 28 像素)也可以观察到。至少可以说,我们的用户对新字体文本阴影突出显示效果的视觉改进感到非常兴奋。

    您可以通过在不同的操作系统、设备和浏览器上运行示例来自行判断。我们对用户就是这样做的。我们让他们通过并排比较相同和不同操作系统上的设备(移动/PC)来确定他们的偏好。

    注意事项

    • 文本阴影需要一些实验。文本粗细就可以了。
    • 未创建所有浏览器、操作系统和硬件文本渲染。预计会发生变化。
    • 预计文本高亮效果会随着字体大小的增加而减弱。
    • 如果您可以为文本重音使用最深的色调,那么在大得多的字体上仍然可以看到色调的差异,这提供了优雅降级的途径。

    以下 12 行文本分为两组。

    first 组 6 行反映了左侧列中的默认 Open Sans 600 字体 和应用于 600 字体粗细的 重音文本在右栏中。

    第二组 6 行反映了左侧列中的默认 Open Sans 500 字体和应用于 500 字体粗细的重音文本在右栏中。

    同样,如果您运行代码 sn-p,您将看到比复制/粘贴更好的质量结果。

    堆栈溢出问题here 也解决了我们的第二个问题。该解决方案是我找到的最简单的解决方案,但是对于 text-shadow: 0 0 0.3px;

    <div>Testing 123: </div>
    <div style="text-shadow: 0 0 .2px">Testing 123: </div>
    <div style="text-shadow: 0 0 .4px">Testing 123: </div>
    <div style="text-shadow: 0 0 .6px">Testing 123: </div>
    <div style="text-shadow: 0 0 .8px">Testing 123: </div>
    <div style="text-shadow: 0 0 1px">Testing 123: </div>

    @import url('https://fonts.googleapis.com/css?family=Open+Sans:400,600');
    body {
      padding: 0;
      margin: 0;
      font-family: 'Open Sans', sans-serif;
      font-weight: normal;
      font-size: 15px;
      font-style: normal;
      font-variant: normal;
      text-transform: none;
      font-synthesis: none;
      -webkit-font-smoothing: antialiased;
      -webkit-font-smoothing: subpixel-antialiased;
      -moz-osx-font-smoothing: grayscale;
      color: #383838;
      width: 100%;
      height: 100%;
      -webkit-text-size-adjust: none !important;
      -ms-text-size-adjust: none !important;
      -moz-text-size-adjust: none !important;
      border: none;
      text-align: center;
      text-rendering: optimizelegibility;
      min-width: 300px !important;
    }
    
    h3,
    h4,
    h5,
    h6 {
      display: block;
      font-family: inherit;
      color: rgba(0, 0, 0, .83);
      text-align: center;
      margin: 10px auto 6px auto;
      font-size: 1em;
      font-weight: 500;
    }
    
    h3 {
      font-weight: 500;
      font-size: 1em;
      color: rgba(0, 0, 0, 0.9);
      text-shadow: 0.45px 0 0 rgba(0, 0, 0, 0.9);
    }
    
    h4 {
      color: rgba(0, 0, 0, 0.9);
      text-shadow: 0.1px 0 0 rgba(0, 0, 0, 0.9);
      text-shadow: 0.3px 0 0 rgba(0, 0, 0, 0.9);
      font-size: 1em;
    }
    
    h5,
    .darker-font {
      color: rgba(0, 0, 0, 0.9);
      text-shadow: 0.08px 0 0 rgba(0, 0, 0, 0.9);
      font-size: 1em;
    }
    
    .center-block {
      display: block;
      width: auto;
      text-align: center;
      margin-right: auto;
      margin-left: auto;
    }
    
    .margintb-8 {
      margin-top: 8px;
      margin-bottom: 8px;
    }
    
    .column0,
    .column1,
    .column2,
    .column3,
    .column-w {
      display: table-column;
      width: auto;
      align-content: center;
    }
    
    .table-r {
      display: table;
      border: 1px solid #606060;
      margin: auto;
      align-content: center;
      background: #fff;
    }
    
    .row-r {
      display: table-row;
    }
    
    .cell-r-center,
    .cell-r-left,
    .cell-r-right,
    .cell-r-center-border,
    .cell-r-left-border,
    .cell-r-right-border {
      display: table-cell;
      text-align: center;
      padding: 4px;
      white-space: nowrap;
    }
    
    .cell-r-left,
    .cell-r-left-border {
      text-align: left;
    }
    
    .cell-r-right,
    .cell-r-right-border {
      text-align: right;
    }
    
    .cell-r-center-border,
    .cell-r-left-border,
    .cell-r-right-border {
      border-top: 1px solid #606060;
    }
    
    div {
      font-family: inherit;
      color: #333;
      text-align: left;
    }
    
    .inline-block {
      vertical-align: middle;
      display: inline-block;
    }
    
    .shadow-text-bold,
    .shadow-text-bolder,
    .shadow-text-boldest {
      font-weight: 500;
      color: rgba(0, 0, 0, 0.84);
      text-shadow: 0.15px 0.15px 0.1px rgba(0, 0, 0, 0.84)
    }
    
    .shadow-text-bolder {
      text-shadow: 0.3px 0.3px 0.1px rgba(0, 0, 0, 0.84)
    }
    
    .shadow-text-boldest {
      color: rgba(0, 0, 0, 0.9);
      text-shadow: 0.08px 0 0 rgba(0, 0, 0, 0.9);
    }
    <!DOCTYPE html>
    
    <head></head>
    <html>
    
    <body>
      <br />
      <div>The first two tables apply default font-weights of 500 and 600 to achieve text highlighting betweeen column headings and table content.</div>
      <div class="center-block">
        <div style="font-family: Arial, Helvetica, sans-serif;">
          <div class="center-block margintb-8" style="font-weight: 600; color: #000">Subscriptions Arial Web Safe</div>
          <div class="center-block">
            <div class="text-container-light-overflow-container">
              <div class="table-r">
                <div class='column0'></div>
                <div class='column-w'></div>
                <div class='column-w'></div>
                <div class='row-r'>
                  <div class='cell-r-center' style="font-weight: 600">#</div>
                  <div class='cell-r-center' style="font-weight: 600">Expiration</div>
                  <div class='cell-r-center' style="font-weight: 600">Available</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border cell-40'> 1 </div>
                  <div class='cell-r-center-border cell-100'>07/01/2027</div>
                  <div class='cell-r-center-border cell-100'> $1927.90</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border cell-40'> 2 </div>
                  <div class='cell-r-center-border cell-100'>07/01/2027</div>
                  <div class='cell-r-center-border cell-100'> $1400.00</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border'> </div>
                  <div class='cell-r-center-border'>--------</div>
                  <div class='cell-r-center-border' style="font-weight: 600"> $2327.90</div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div style="font-family: 'Open Sans';">
          <div class="center-block margintb-8" style="font-weight: 600; color: #000">Subscriptions Open Sans</div>
          <div class="center-block">
            <div class="text-container-light-overflow-container">
              <div class="table-r">
                <div class='column0'></div>
                <div class='column-w'></div>
                <div class='column-w'></div>
                <div class='row-r'>
                  <div class='cell-r-center' style="font-weight: 600">#</div>
                  <div class='cell-r-center' style="font-weight: 600">Expiration</div>
                  <div class='cell-r-center' style="font-weight: 600">Available</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border cell-40'> 1 </div>
                  <div class='cell-r-center-border cell-100'>07/01/2027</div>
                  <div class='cell-r-center-border cell-100'> $1927.90</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border cell-40'> 2 </div>
                  <div class='cell-r-center-border cell-100'>07/01/2027</div>
                  <div class='cell-r-center-border cell-100'> $1400.00</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border'> </div>
                  <div class='cell-r-center-border'>--------</div>
                  <div class='cell-r-center-border' style="font-weight: 600"> $2327.90</div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <br />
        <div style="font-family: 'Open Sans';">
          <span>The</span>
          <span class="shadow-text-boldest">second two tables</span><span> apply default font-weight of 500 and subtle text-shadowing to achieve text highlighting betweeen column headings and table content. There are also</span>
          <span class="shadow-text-boldest">three examples</span><span> of inline text highlighting in this paragraph to enhance content without screaming or altering the base text-font width, which is a <span class="shadow-text-boldest">real plus at times</span>.
          Just remember that the text-shadow effect will diminish as the font-size is increased and can cause <span style="font-weight: 600">unwanted destortions</span> when the font-size is made <span class="shadow-text-boldest" style="font-size: 6px; font-weight: 600;">very small.</span></span>.
          Notice the second from last "unwanted destortions" text. It is the Open Sans font at 600 font-weight. It is noticeably higher and thicker than the adjacent text. Compare to the text-shadow versions earlier in the paragraph.
        </div>
        <div style="font-family: Arial, Helvetica, sans-serif;">
          <div class="center-block shadow-text-bold margintb-8">Subscriptions Arial Web Safe</div>
          <div class="center-block">
            <div class="text-container-light-overflow-container">
              <div class="table-r">
                <div class='column0'></div>
                <div class='column-w'></div>
                <div class='column-w'></div>
                <div class='row-r'>
                  <div class='cell-r-center shadow-text-bold'>#</div>
                  <div class='cell-r-center shadow-text-bold'>Expiration</div>
                  <div class='cell-r-center shadow-text-bold'>Available</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border cell-40'> 1 </div>
                  <div class='cell-r-center-border cell-100'>07/01/2027</div>
                  <div class='cell-r-center-border cell-100'> $1927.90</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border cell-40'> 2 </div>
                  <div class='cell-r-center-border cell-100'>07/01/2027</div>
                  <div class='cell-r-center-border cell-100'> $1400.00</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border'> </div>
                  <div class='cell-r-center-border'>--------</div>
                  <div class='cell-r-center-border shadow-text-bold'> $2327.90</div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div style="font-family: 'Open Sans';">
          <div class="center-block shadow-text-bold margintb-8">Subscriptions Open Sans</div>
          <div class="center-block">
            <div class="text-container-light-overflow-container">
              <div class="table-r">
                <div class='column0'></div>
                <div class='column-w'></div>
                <div class='column-w'></div>
                <div class='row-r'>
                  <div class='cell-r-center shadow-text-bold'>#</div>
                  <div class='cell-r-center shadow-text-bold'>Expiration</div>
                  <div class='cell-r-center shadow-text-bold'>Available</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border cell-40'> 1 </div>
                  <div class='cell-r-center-border cell-100'>07/01/2027</div>
                  <div class='cell-r-center-border cell-100'> $1927.90</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border cell-40'> 2 </div>
                  <div class='cell-r-center-border cell-100'>07/01/2027</div>
                  <div class='cell-r-center-border cell-100'> $1400.00</div>
                </div>
                <div class='row-r'>
                  <div class='cell-r-center-border'> </div>
                  <div class='cell-r-center-border'>--------</div>
                  <div class='cell-r-center-border shadow-text-bold'> $2327.90</div>
                </div>
              </div>
            </div>
          </div>
          <div class="center-block">
            <div class="center-block margint-16" style="font-weight: 600; color: rgba(0, 0, 0, 0.9);">
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.65px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.55px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.45px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.3px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.08px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0 0">Testing 123</span>
              </div>
            </div>
            <div class="center-block" style="color: rgba(0, 0, 0, 0.9)">
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.65px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.55px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.45px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.3px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0.08px 0 0 rgba(0, 0, 0, 0.9)">Testing 123</span>
              </div>
              <div>
                <span class="inline-block">Testing 123: </span><span class="inline-block" style="text-shadow: 0 0 rgba(0, 0, 0, 0.0);">Testing 123</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </body>
    
    </html>

    【讨论】:

      【解决方案3】:

      发生了什么事

      字体现在的工作方式是字体具有可以使用的各种字体粗细。要使用字体粗细,它们需要在您的用户浏览器中可用。浏览器通常没有安装支持 9 种典型字体粗细(100、200、300、400、500、600、700、800、900)的字体。它将向上或向下舍入到最接近的可用值。

      你能做些什么

      您可以尝试找到支持您想要的所有字体粗细的字体并将其导入。我在谷歌字体上找到了一些:https://fonts.google.com/?stylecount=18.

      修改后的代码

      我所做的只是将“Montserrat”导入您的代码并将 Montserrat 字体分配给您的正文。

      @import url('https://fonts.googleapis.com/css?family=Montserrat:100,200,300,400,500,600,700,800,900');
      
      body {
        padding: 0;
        margin: 0;
        font-family: 'Montserrat', sans-serif;
        font-weight: normal;
        font-size: 15px;
        font-style: normal;
        font-variant: normal;
        text-transform: none;
        font-synthesis: none;
        color: #383838;
        width: 100%;
        height: 100%;
        -webkit-text-size-adjust: none !important;
        -ms-text-size-adjust: none !important;
        -moz-text-size-adjust: none !important;
        border: none;
        text-align: center;
        text-rendering: optimizelegibility;
        min-width: 300px !important;
      }
      
      h3,
      h4,
      h5,
      h6 {
        display: block;
        font-family: inherit;
        line-height: 1.1;
        color: #000;
        opacity: 1.0;
        font-weight: normal;
        text-align: center;
        margin: 10px auto 6px auto;
        font-size: 1em;
      }
      
      h3 {
        font-size: 1.05em;
      }
      
      h4 {
        font-size: 1.1em;
      }
      
      h5 {}
      
      h6 {
        margin: .25em auto;
      }
      
      .center-block {
        display: block;
        width: auto;
        text-align: center;
        margin-right: auto;
        margin-left: auto;
      }
      
      .test-boldness {
        text-shadow: 1px 0.1px rgba(0, 0, 0, 0.23);
      }
      
      .bold {
        font-weight: 500;
        color: #000;
      }
      
      .bolder {
        font-weight: 500;
        color: #000;
        text-shadow: 1px 0.1px rgba(0, 0, 0, 0.35);
      }
      
      .boldest {
        color: #000;
        font-weight: 600;
      }
      
      .test-boldness {
        text-shadow: 1px 0.1px rgba(0, 0, 0, 0.35);
      }
      
      .test-boldness-1pxsolid {
        text-shadow: 1px 1px #999;
      }
      
      div {
        font-family: inherit;
        color: #383838;
      }
      <!DOCTYPE html>
      
      <head></head>
      <html>
      
      <body>
        <br />
        <br />
        <div class="center-block"><span class="test-boldness-1pxsolid">How Used: </span>Visible accent. This one has most blurring on all required OS/devices.</div>
        <br />
        <div>
          <span style='font-weight: 300'>300</span>
          <span style='font-weight: 400'>400</span>
          <span style='font-weight: 500'>500</span>
          <span class='test-boldness'>Custom 550</span>
          <span style='font-weight: 600'>600</span>
          <span style='font-weight: 700'>700</span>
          <br />
          <br />
          <div class="center-block"><span class="test-boldness">How Used: </span>Visible accent. Less blurring/most uniform on required OS/devices. Is there a better way to do this?</div>
          <br />
          <br />
          <div class="center-block"><span class="boldest">How Used: </span>Visible accent. This one is clearest but too bold, especially on some of the required OS/devices.</div>
          <br />
          <h3>Test Cases</h3>
          <br />
          <h3 class="test-boldness-1pxsolid">TEST ABCDKTM test abcdktm-1pxsolid</h3>
          <h3 class="test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</h3>
          <h3>TEST ABCDKTM test abcdktm</h3>
          <h4 class="test-boldness-1pxsolid">TEST ABCDKTM test abcdktm-1pxsolid</h4>
          <h4 class="test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</h4>
          <h4>TEST ABCDKTM test abcdktm</h4>
          <h5 class="test-boldness-1pxsolid">TEST ABCDKTM test abcdktm-1pxsolid</h5>
          <h5 class="test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</h5>
          <h5>TEST ABCDKTM test abcdktm</h5>
          <h6 class="test-boldness-1pxsolid">TEST ABCDKTM test abcdktm-1pxsolid</h6>
          <h6 class="test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</h6>
          <h6>TEST ABCDKTM test abcdktm</h6>
          <div class="center-block bold test-boldness">TEST ABCDKTM test abcdktm 0.1px Op LT 1</div>
          <div class="center-block bold">TEST ABCDKTM test abcdktm</div>
          <div class="center-block bolder test-boldness">TEST ABCDKTM test abcdktm font-weight: 500</div>
          <div class="center-block bolder">TEST ABCDKTM test abcdktm font-weight: 500</div>
          <div class="center-block boldest">TEST ABCDKTM test abcdktm font-weight: 600</div>
          <div class="center-block boldest">TEST ABCDKTM test abcdktm font-weight: 600</div>
      
      </body>
      
      </html>

      补充阅读

      1. https://www.quirksmode.org/css/text/fontweight.html
      2. https://drafts.csswg.org/css-fonts-4/#missing-weights

      【讨论】:

      • 感谢您抽出宝贵时间做出建设性的回应。我从您的链接中阅读了信息。我已经熟悉了大部分信息。我正在做另一次扫描以查看字体下载,但过去没有找到在所有设备、操作系统和浏览器上都有效的 Arial、Helvetica、sans-serif 字体集(行为相同且粗度可接受)。我确实尝试了第一个链接中使用的字体,并且相同的设置表现不同。 IE、Edge 和 Firefox 相同,但与 Chrome 和 Opera 不同。我还有很多测试要做,但会发布结果。再次感谢。
      • @RMo 我选择了您对我最初问题的回答,因为您 a) 使用 Google 可下载字体说明了中间字体粗细,并且 b) 您还向我指出了我最终找到的 Google 位置可接受的替代字体。 elbrant的回答也很有帮助,但我只能检查一个。我修改了我最初的问题以更清楚地定义我们的需求,并发布了一个额外的答案,希望能帮助那些找到此链接的人。
      【解决方案4】:

      CSS 提供的font-weight 值比您想象的要广泛得多。 Mozilla's CSS font-weight 页面甚至列出了我不知道的重量值。 shock! 值的范围是 1-1000,通常以 100 的间隔增加,有几个偏差。这可能不是一个完美的解决方案,但您可能会发现一些您没有意识到的选项。

      【讨论】:

      • 感谢您的反馈。字体系列必须是 Arial、Helvetica、sans-serif 或视觉等效字体。如果我能找到它,我会使用它。问题是我还没有找到现成的解决方案。困难在于一些较旧的 iOS 手机(4+)多年来没有更新过操作系统或浏览器。我仍在研究许多选项,包括来自 RMo 的选项。我还有一些字体系列要下载和测试,但正如您可以想象的那样,考虑到要验证的所有设备、操作系统和浏览器变体,它的工作量很大。再次感谢
      • Helvetica 似乎不再是在线选项。唯一能够在您的页面上看到它呈现的用户是像我一样拥有它的用户。给Google Fonts Roboto 看看,看看是否能满足您的要求。
      • 欣赏链接。我评估了 Roboto 字体,它与我们的基线字体非常相似(几乎相同)。但是,它并没有真正提高字体粗细分辨率。在 Google 网站上,我找到了“Open Sans”,它与我们的基线非常接近。它确实有一个不太粗的半色调字体粗细。我仍在运行更多测试来评估。再次感谢您的帮助。
      猜你喜欢
      • 2011-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      • 1970-01-01
      • 2023-01-24
      • 2014-09-04
      相关资源
      最近更新 更多