代码之家  ›  专栏  ›  技术社区  ›  Elias Zamaria

css:根据备用字体设置字体权重

  •  8
  • Elias Zamaria  · 技术社区  · 16 年前

    我正在尝试根据所选字体设置元素的字体权重。例如,我可能正在尝试这样做:

    h1 {
        font-family: Arial Narrow, Impact, sans-serif;
        font-weight: ?;
    }
    

    比方说,如果用户的系统上安装了arial narrow,我希望字体粗体,但如果浏览器必须使用impact,我希望字体粗体;如果用户的系统没有这两种字体,我希望字体粗体。这可能吗?如果是,我该怎么做?

    2 回复  |  直到 10 年前
        1
  •  6
  •   Community Mohan Dere    9 年前

    我99.99999%的确信如果没有一些真正的javascript魔术,这是不可能实现的,即使有了javascript 该死 很难找出最后使用的是哪种字体。

    相关: get computed font-family in JavaScript 真的是你问的

        2
  •  0
  •   luixxiul    10 年前

    这不管用吗?未经测试的。

    <style>
    @font-face {
        font-family: "ArialBold";
        src: local("Arial Narrow");
        font-weight: bold;
    }
    @font-face {
        font-family: "ImpactNormal";
        src: local("Impact");
        font-weight: normal;
    }
    @font-face {
        font-family: "SansSerifBold";
        src: local("sans-serif");
        font-weight: bold;
    }
    h1 {
        font-family: ArialBold, ImpactNormal, SansSerifBold;
    }
    </style>