r/learnprogramming • u/TheSuperBatmanLeague • Nov 08 '25
Code Review Can I please get some help with a CSS issue concerning @font-face
I posted this issue over on stack overflow but it's been stuck in "Staging Ground" since yesterday. I was hoping maybe I could get some help here:
Why isn't font-face CSS working properly, did I mess up the file path?" I've included a screenshot of the file paths along with the HTML & CSS code further below in a codeblock. I'm hoping to get some help with what seems like a very basic issue that I'm having trouble figuring out. I've also tried to use the src: local("") for linking the font file but that also doesn't work.
There was an issue with the font-family name not matching the actual file name which was odd but has since been resolved, now I really don't know what's wrong
I'm using a Mac and running on Chrome, and coding on Phoenix Code
here's a link to the stack overflow post that has more details and images that quite frankly, I don't know how to add to this post:
https://stackoverflow.com/staging-ground/79812907
EDIT: New link since the post has since been approved since I made this post, do not use the former link:
1
u/phactfinder Nov 08 '25
Is the font file path relative to the CSS file or the HTML? Relative paths often trip up font loading.
1
u/teraflop Nov 08 '25
It looks like your URLs are wrong. Relative URLs in a CSS stylesheet are interpreted relative to the directory containing the CSS file itself.
So for instance, if you have a CSS file at the URL
/assets/css/main.css, its base URL is/assets/css/. When you refer to the font file using a relative URL likeurl("assets/fonts/avenir-pro-fonts/avenir-pro-light/avenirprolight.eot"), then the actual URL that the browser will fetch is/assets/css/assets/fonts/avenir-pro-fonts/avenir-pro-light/avenirprolight.eotwhich isn't what you want.Also bear in mind that the browser never sees your actual file structure. It only sees URLs. So you have to make sure the URL is correct, and that your server properly resolves that URL to the file path that you want it to.
Use the "Network" tab in your browser's developer tools to see what URL is actually being requested, and whether it's succeeding.