【问题标题】:My font shorthand doesn't work, which include font-size and font-weight properities我的字体速记不起作用,其中包括 font-size 和 font-weight 属性
【发布时间】:2019-06-12 12:49:56
【问题描述】:

在我的代码中,我使用

{
    font-size: 2.5rem;
    font-weight: 100;
}

设置字体,但是当我将其切换为字体简写时,就像这样{font: 100 2.5rem} 它似乎不起作用,我的字体样式更改为默认样式。

pic 看来我已经遵循了字体的简写规则,有人可以帮忙吗?

【问题讨论】:

    标签: html css frontend font-size shorthand


    【解决方案1】:

    font 速记属性需要指定 font-sizefont-familyline-height 和其他 font-* 属性是可选的。

    Reference.

    【讨论】:

      【解决方案2】:

      字体粗细定义了由细到粗的字符。100-400与普通相同,700-900与粗体相同。给出 Font-weight 后,您需要给出 font-family 属性。如果您不想使用任何字体系列,则只需将字体系列设置为无。这对我有用。

      <!DOCTYPE html>
      <html>
      <head>
      <style>
        p.a {
          font: 100 2.5rem none;
        }
        p.b {
          font: 400 2.5rem none;
        }
        p.c {
          font: 700 2.5rem arial, sans-serif;
        }
        p.d {
          font: 800 2.5rem Georgia, serif;
        }
        p.e {
          font: 900 2.5rem normal;
        }
      </style>
      </head>
      <body>
      
        <h1>The font Property</h1>
      
        <p class="a">This is a paragraph. The font size is set to 10 pixels.</p>
      
        <p class="b">This is a paragraph. The font size is set to 10 pixels.</p>
      
        <p class="c">This is a paragraph. The font size is set to 10 pixels.</p>
      
        <p class="d">This is a paragraph. The font size is set to 10 pixels.</p>
      
        <p class="e">This is a paragraph. The font size is set to 10 pixels.</p>
      
      </body>
      </html>

      【讨论】:

      • 没有。 100-400 不一样,700-900 也不一样。当指定字体系列的指定粗细不可用时,会发生舍入。 w3.org/TR/CSS21/fonts.html#propdef-font-weight
      • 嗨@Kravimir,你没有明白我的意思。我只是说字体粗细 100,200,300,400 与普通字体粗细相同,700,800,900 与粗体粗细相同。这意味着对于普通字体粗细我们可以使用 100,200,300,400 作为字体粗细,对于粗体字体粗细我们可以使用 700,800,900 作为字体粗细。
      • 如果它对你有用,那么你可以认为我的回答是正确的并给我点。 @ShendanTang
      • @MakdiaHussain /如果/我误解了你的意思,那我还是不明白你的意思。
      猜你喜欢
      • 2012-04-20
      • 2022-12-21
      • 1970-01-01
      • 2014-07-29
      • 2021-12-20
      • 1970-01-01
      • 1970-01-01
      • 2013-06-29
      • 1970-01-01
      相关资源
      最近更新 更多