How to set different font-weight for fallback font?

前端 未结 2 1116
情书的邮戳
情书的邮戳 2021-02-15 13:53

I\'ve came across a problem with custom font i use for my website.

So i use following CSS for text.

font-family: \"Open Sans\",Helvetica,Arial;
font-wei         


        
相关标签:
2条回答
  • 2021-02-15 14:05

    Unfortunately, there is no way to define fallback font specific styling using CSS alone.

    As such you may want to attempt to work out the font being used, then apply a style as a result, see here for one method which works out the width resulting from applying a font to an element before 'best guessing' which it is.

    That said, it is essentially a hack/workaround.

    Otherwise, you could look into implementing a method to identify where the symbols are and then wrap them in styles span tags, again this would be a fairly dirty hack as opposed to a clean solution.

    0 讨论(0)
  • 2021-02-15 14:15

    You could define a new @font-face for each font you want.

    @font-face {
          font-family: 'mainFont';
          src: url(/*Link to Open Sans*/);
          font-weight: 600;
    }
    
    @font-face {
          font-family: 'secondaryFont';
          src: local('Helvetica');
          font-weight: 400;
    }
    
    @font-face {
          font-family: 'tertiaryFont';
          src: local('Arial');
          font-weight: 600;
    }
    

    Then you'll end up with font-family: 'mainFont', 'secondaryFont', 'tertiaryFont'; which should get the desired results.

    0 讨论(0)
提交回复
热议问题