Recently, I added some new fonts (specifically Roboto) to my Linux Ubuntu PC and wanted to incorporate them into my CSS using the @font-face
rule. However, I encountered an issue when specifying different font weights within the src: ;
property as shown in this example:
@font-face {
font-family: 'Roboto';
src: local('Roboto'), local('Roboto-Regular'), url('Roboto.ttf') format('truetype');
font-weight: 400;
}
.
The Issue:
I noticed that only certain font styles/weights such as font-weight: 400
(regular) and font-weight: 600
(bold) were working properly. Any attempt to change it to font-weight: 500
(medium) or others seemed to have no effect.
.
Attempts at Resolving the Issue:
1) Creating a separate @font-face
declaration for the medium weight:
@font-face {
font-family: 'Roboto';
src: local('Roboto Medium'), local('Roboto-Medium'), url('Roboto-Medium.ttf') format('truetype');
font-weight: 500;
}
Outcome: The console displayed an error message:
Failed to decode downloaded font: pathToMySite/css/Roboto-Medium.ttf
, and the styling remained consistent with the regular weight.
2) Checking the installed fonts by listing all available options using the Linux command: fc-list | grep "Roboto"
, which confirmed the existence of various Roboto font variations.
Results:
lots/of/paths/Roboto-Regular.ttf: Roboto:style=Regular
lots/of/paths/Roboto-Italic.ttf: Roboto:style=Italic
(...)
(multiple paths were listed for different font styles)
3) Verifying the presence of all Roboto variations through the Linux "Fonts" application showcased that all variants were indeed installed and visually distinct from each other.
4) After refreshing the page using CTRL + F5
and ensuring that the browser cache was disabled, the problem persisted.
In conclusion: Despite having all fonts correctly installed on the system, the CSS stylesheet fails to recognize anything beyond the regular and bold font weights, raising questions about their accessibility or correct identification.
If you have any insights or solutions to offer, I would greatly appreciate your input! Thank you for your assistance!