Error while using the custom fonts in css

2020-04-18 05:25发布

问题:

While I tried to use custom font for my website through the CSS file, I'm not getting the required font and it shows only the default font. Please Check the css code and let me know if any changes needed :)

@font-face {
    font-family: Myriad Pro;
    src: url('Myriad.ttf');
    }
#voicetext{
    color:#127bb9;
    font-size:16px;
    font-family:"Myriad Pro";
    text-align:center;
    letter-spacing:3px;
}

回答1:

Unfortunately, it isn't as straight forward as this. For a truly cross-browser solution, you will need to reference more than just the TTF version.

This question: How to embed fonts in HTML? has a full list, and links to Paul Irish's "Bulletproof web fonts" blog entry that caters for all the browser quirks.

If you're in a hurry, and not interested in the specifics, FontSquirrel's Bulletproof @font-face generator seems to utilize the hints from the blog post.



回答2:

My first guess is probably that you've uploaded your font file at the wrong place. Currently, you'll need a Myriad.ttf file in the same directory as your css file.



标签: css fonts