Search code examples
cssfont-face

CSS font-face not working for ttf


I am using @font-face like this:

@font-face {
    font-family: DINPro;
    font-weight: bold;
    src: url(../res/fonts/DINPro-Bold.otf) format("opentype");
}
@font-face {
    font-family: DINPro;
    src: url(../res/fonts/DINPro-Regular.otf) format("opentype");
}
@font-face {
    font-family: DFLiHei;
    src: url(../res/fonts/DFLiHei-Regular.ttf) format('truetype');
}
h1{
    font-family: DFLiHei !important;
}

But not working. My folder structure is likely:

/index.html
/css/style.css
/res/fonts/DINPro-Bold.otf
/res/fonts/DINPro-Regular.otf
/res/fonts/DFLiHei-Regular.ttf

Therefore, I think wrong directory is not my problem. Also, not only fail in special browser, but also in chrome and mobile. Any idea?


Solution

  • Convert ttf to woff format

    Try this

    @font-face {
        font-family: DFLiHei;
        src: url(../res/fonts/DFLiHei-Regular.woff) format('woff');
    }
    

    It will work in all browsers