【问题标题】:Font-weight not being applied未应用字体粗细
【发布时间】:2022-01-26 22:39:31
【问题描述】:

我正面临 css 字体粗细问题。我有一个网站,我想减少字体重量,但即使是最轻的重量(即 100 看起来像这样),它似乎也是固定的。

但我希望它看起来像这样 我使用的字体是 Merriweather-Sans

我的 css 文件 1,其中包含与正文和标题相关的 css:

body {
  font-size: $font-size-base;
  line-height: line-height($font-size-base);
  color: $color-black;
}

h1 {
  font-size: $font-size-h1;
  line-height: line-height($font-size-h1);
  margin-bottom: $spacer;
  font-weight: 100;
  color: $color-slate;
}

h2 {
  font-size: $font-size-h2;
  line-height: line-height($font-size-h2);
  font-weight: $font-weight-light;
  color: $color-crimson;
  margin-bottom: $spacer;
  color: $color-slate;
  text-transform: capitalize;
}

h3 {
  font-size: $font-size-h3;
  line-height: line-height($font-size-h3);
  font-weight: $font-weight-normal;
  margin-bottom: $spacer;
  color: $color-slate;
}

h4 {
  font-size: $font-size-h4;
  line-height: line-height($font-size-h4);
  margin-bottom: $spacer;
}

p {
  font-size: $font-size-base;
  line-height: line-height($font-size-base);
  margin-bottom: $spacer;
  color: $color-slate;
}

我的 css 文件 2 包含上面在 css 中声明的变量:

/* === Typography === */
@import url('https://fonts.googleapis.com/css?family=Merriweather+Sans');

$font-family-base: 'Merriweather Sans', sans-serif;

$font-size-base: 1rem;
$font-size-h1: $font-size-base * 3;
$font-size-h2: $font-size-base * 2;
$font-size-h3: $font-size-base * 1.75;
$font-size-h4: $font-size-base * 1.25;
$font-size-lead: $font-size-base * 1.25;
$font-size-small: $font-size-base * 0.875;

$font-weight-light: 200;
$font-weight-normal: 400;
$font-weight-bold: 700;

/* === Line height === */

$line-height-list: 1.5rem;

【问题讨论】:

标签: html css reactjs fonts


【解决方案1】:

这个 import https://fonts.googleapis.com/css?family=Merriweather+Sans 只包含 font-weight 400,我想这就是原因。

而且这个字体只支持font-weight 300-800 https://fonts.google.com/specimen/Merriweather+Sans?query=Merriweather

你可以通过像这样导入来使用 font-weight 300-800

@import url('https://fonts.googleapis.com/css2?family=Merriweather+Sans:wght@300;400;500;600;700;800&display=swap');

【讨论】:

  • 谢谢!但我也有更轻的字体重量。就像正文的字体粗细为 100。我该怎么办?
  • 好吧,就像我说的字体只支持 font-weight 300-800,你应该找到另一个支持你需要的 font-weight 的字体:)
  • Merriweather Sans 可以替换哪种字体?
【解决方案2】:

如果你想使用 Merriweather 的多个权重,你最好导入可变字体而不是六个静态权重:

@import url('https://fonts.googleapis.com/css2?family=Merriweather+Sans:wght@300..800&display=swap');

如果您想在 Google 字体中找到重量很轻的字体,请尝试将“粗细”设置为较低的值进行过滤:

https://fonts.google.com/?thickness=1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2015-11-14
    • 1970-01-01
    • 2012-07-12
    • 2014-10-04
    • 1970-01-01
    相关资源
    最近更新 更多