4

So I have a HTML page, linked to a CSS file which is supposed to change the font of a div class called header, to a custom font named KeepCalm. Here's the code for defining the font-face:

@font-face {
  font-family: 'KeepCalm';
  src: url('Files\Fonts\KeepCalm.eot?') format('eot'), url('Files\Fonts\KeepCalm.woff') format('woff'), url('Files\Fonts\KeepCalm.ttf') format('truetype');
}

Here is the code to change the font-face of the header div class:

.header {
    font-family: KeepCalm;
}

However the fonts are not showing up in any browser I try, chrome, firefox or IE. I have already looked up how to fix it and have not yet found a solution.

Here is the link to the font I'm using: Here.

5
  • Check if your font is being downloaded or not. It's possible tha your path is wrong. stackoverflow.com/questions/18900720/… Commented May 12, 2016 at 0:36
  • @EduardoArrudaPimentel I have tripple checked the path, and I'm not sure what you mean by checking if it's downloaded or not; I am using a local file, saved into a subfolder called ...\Files\Fonts Commented May 12, 2016 at 1:15
  • @AndréDion: that would seem to be the answer. Commented May 12, 2016 at 18:22
  • @AndréDion The debugger does say that the downloadable font download failed. Can you please link me to a tutorial or something to set up a web server, and will it cost? I'm not very experienced sorry. Commented May 13, 2016 at 0:07
  • @TacoMakerMan You can run a web server on your machine and serve up your files there, you don't need to pay for an external host. Just Google "<your OS> web server" and you'll get plenty of information. Commented May 13, 2016 at 11:45

3 Answers 3

3

It turns out that I was using the "Files\Fonts\" as the path of the font, although since it was the css file I was using, it was already in the "Files" folder so I just needed it to change to "Fonts\KeepCalm.tff". Stupid mistake but it's easy to miss.

Sign up to request clarification or add additional context in comments.

Comments

2

Supposing that your folders are like this:

|-- index.html
|--|Files
   |--|Fonts
      |-- KeepCalm-Medium.eot (Created by http://transfonter.org/)
      |-- KeepCalm-Medium.woff (Created by http://transfonter.org/)
      |-- KeepCalm-Medium.woff2 (Created by http://transfonter.org/)
      |-- KeepCalm-Medium.ttf (Original File)

I created this html code:

<html>
    <head>
        <meta charset="utf-8">
        <title>Stack Overflow Test</title>
        <style type="text/css" media="screen">
            @font-face {
              font-family: 'KeepCalm';
              src:  
                    url('Files/Fonts/KeepCalm-Medium.eot?') format('embedded-opentype'),
                    url('Files/Fonts/KeepCalm-Medium.woff') format('woff'),
                    url('Files/Fonts/KeepCalm-Medium.woff2') format('woff2'),
                    url('Files/Fonts/KeepCalm-Medium.ttf') format('truetype');
            }
            .header {
                font-family: KeepCalm;
            }
        </style>
    </head>
    <body>

    <div class="header">
        Keep Calm
    </div>


    </body>
</html>

And it works. If you have the same folders that supposed and named correct the font files it will work. And you do not need a webserver. Simple html, and works.

3 Comments

Okay, so I changed the font-face section to the way you suggested and added the single quotes to the font-family. It didn't do anything, so I also tried to use your tests and neither of them did anything either. I have no idea why.
Could you upload your font in a public link? I will download it and check the code.
I added the link to the main question for you to check out. I converted the ttf file to all the other file formats that I used.
2

First your src is not formatted right try to change it like this:

src: url('/Files/Fonts/KeepCalm.eot?')

Note: always practice to use relative paths.

8 Comments

I'm not exactly sure what this changes, I tried this and it did nothing new. You just added a "/" at the beginning right?
no your slash are inverted take a look it must be a common slash not a back slash
@winresh14 Oh I see. I replaced them with regular slashes and it did not change anything.
check the file if it's existing. is your website is already live?
@winresh14 The file definitely exists, it's not currently live, just a .html file at the moment.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.