CSS - Access to font | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

CSS - Access to font

Hello, I want to add a font to my code, but I cannot do it with this: @font-face { font-family: 'PixelFont_CMD'; src: url('http://panda.xf.cz/CSS/PixelFont_CMD.ttf') format('truetype'); font-weight: normal; font-style: normal; } When I run code with this code, console says, that I cannot access font. Can somebody help me or give me other way to add font to code? https://code.sololearn.com/WRp7lqD7cbwZ/?ref=app

1st Sep 2018, 6:00 AM
Vojtěch Novák
Vojtěch Novák - avatar
4 Answers
+ 1
I see. The host of the ttf file won't let you use the font directly. It could be intentional or just a default setting that wasn't changed. Here's the longer explanation: https://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work But, since the file is downloadable, you can host it yourself. I tested it on my local machine and it works fine. If you want to use it in the Code Playground, you will want to put the ttf file in Dropbox or some other file repo. I hope this helps!
2nd Sep 2018, 1:49 AM
Janning⭐
Janning⭐ - avatar
0
In the third line, is there a missing semicolon? I tried the font on my page, dosnt work for me too.
1st Sep 2018, 6:30 AM
cocktus
cocktus - avatar
0
It seems fine. Do you have the full code?
1st Sep 2018, 9:50 AM
Janning⭐
Janning⭐ - avatar
0
Updated - Posted code
1st Sep 2018, 1:34 PM
Vojtěch Novák
Vojtěch Novák - avatar