Unable to load custom fonts

I've been attempting to upload Gotham fonts onto a website I'm constructing, but unfortunately, it doesn't seem to be working. Despite my efforts to troubleshoot by searching through various resources, including Google, the issue persists. It seems there might be a syntax problem with the upload that I am unable to identify, and I'm hopeful that another set of eyes can spot it.

In the past, I have successfully loaded custom fonts on a Rails application, however, this is the first time I am dealing with pure front-end development. I have created a font file - Gotham_fonts - containing six files with the .otf extension.

style.css

@font-face {
  font-family: 'Gotham-Book';
  src: url('Gotham_fonts/Gotham-Book.otf') format('otf');
}

body {
  font-family: 'Gotham-Book', arial, sans-serif;
}

Despite trying different variations and even using !important, the issue remains unresolved. Do you think my fonts folder should actually be placed inside my CSS folder?

Answer №1

Your code is looking good overall, but there seems to be a mistake in the format string you used:

@font-face {
  font-family: 'Gotham-Book';
  src: url('/Gotham_fonts/Gotham-Book.otf') format('opentype');
}

It's crucial to use the correct path to the font file, and there are multiple options available:

  • An absolute path from the root can be used like this:

    url('/Gotham_fonts/Gotham-Book.otf')
    . This method is recommended as it works regardless of where the font file is referenced. However, keep in mind that it may only work in the production environment if your test setup has each project stored in separate folders.

  • Alternatively, you can opt for a relative path. In this case, the path should be relative to the CSS file. For example, if the CSS file is in the parent folder of Gotham_fonts, you can use

    url('Gotham_fonts/Gotham-Book.otf')
    as you did. But if the CSS file is located in a folder like CSS_files, you would need to use
    url('../Gotham_fonts/Gotham-Book.otf')
    .

Answer №2

To start off, you can utilize a webfont generator like to create OTF, TTF, EOT, and WOFF variations of your font. It's beneficial to have all four versions as different browsers may require or prefer specific formats.

Next, make sure your CSS (while keeping your HTML intact) appears similar to the following:

@font-face {
    font-family: "Gotham-Book";
    src: url("../Gotham_fonts/Gotham-Book.eot");
    src: 
    url("../Gotham_fonts/Gotham-Book.woff") format("woff"),
    url("../Gotham_fonts/Gotham-Book.otf") format("opentype");
}

The use of '../' in the URL paths assumes that both your CSS folder and 'Gotham_Fonts' folder are located in the same parent directory.

Please feel free to reach out if you need further assistance!

Answer №3

After some investigation, I realized that the issue might have been with the font files I was using. To troubleshoot, I decided to switch to a different font-family collection. Luckily, this change resolved the path problem. Here's the updated code snippet:

@font-face {
    font-family: 'geomanistregular';
    src: url('../fonts/geomanist-regular-webfont.eot');
    src: url('../fonts/geomanist-regular-webfont.eot?#iefix') format('embedded-opentype'),
         url('../fonts/geomanist-regular-webfont.woff2') format('woff2'),
         url('../fonts/geomanist-regular-webfont.woff') format('woff'),
         url('../fonts/geomanist-regular-webfont.ttf') format('truetype'),
         url('../fonts/geomanist-regular-webfont.svg#geomanistregular') format('svg');
    font-weight: normal;
    font-style: normal;

}

I must say, it's quite a nice font after all. Many thanks to those who assisted me with this!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Arranging an image and button within a column div row using Bootstrap

I'm encountering an issue with Bootstrap where I am trying to align the blue buttons neatly below the image. Link to the image: img Here is a visual representation: https://i.sstatic.net/tB5mU.png This is the code snippet: <div class="row&q ...

The method for retrieving and entering a user's phone number into a text field upon their visit

Objective: To enhance the user experience by automatically filling in the phone number input field when a mobile user views the page, making it easier to convert them into leads. A privacy policy will, of course, be in place. This page will offer a promo ...

What are the steps to modify the properties of an HTML class with JavaScript?

Currently, I am working on a project where I have an html element that contains one of the grades. <span class="tooltip"> <span class="grade">83.49%</span> </span> I am interested in learning how to cha ...

Difficulty in adjusting the height of the popover menu that appears when using the Select Validator in Material UI

I am having trouble adjusting the height of a popover that emerges from a select validator form in Material UI. Despite attempting various methods, including adding the following CSS to the main class: '& .MuiPopover-paper': { height: &apos ...

Using the same Angular component with varying input values

Recently, I encountered a puzzling issue that has left me unsure of where to even start investigating the possible causes. I am currently utilizing a library called angular-stl-model-viewer, which is based on Three.js. The problem arises when I call a comp ...

Loading indicator displayed at the top of a div using JavaScript/jQuery

My current challenge involves implementing a progress bar, similar to the pace.js progress bar. The issue arises when the browser is refreshed, as the pace.js progress bar loads on top of the body instead of within a specified div. It is important that the ...

Excessive content overflowing in Bootstrap's card-body

I need help with fitting plotly figures into bootstrap cards in a card deck. The content within the card-body is flowing outside of the card width. I want to constrain the figures within the cards, as their height is defined but not width. <html> ...

Instructions for creating a distinct click listener for each <img> element inside a table cell

Within my table, each row contains multiple columns with images as data. I successfully implemented a 'common listener' that is triggered when any image within a table row is clicked. $('#mytable tbody td img').click(function () { // ...

Ways to verify if all javascript and css files have been successfully loaded

I have been exploring different ways to notify users if certain resources do not load correctly. So far, I have come across the following methods: For CSS, I stumbled upon an example in the source code of Trello: <div id="nocss"> Your browser ...

error TS2559: The type 'BookInterface[]' does not share any properties with the type 'BookInterface'

Hello, I am currently working on a project using Angular 7 and encountering the error TS2559: Type 'BookInterface[]' has no properties in common with type 'BookInterface'. Despite making changes to the code, the issue persists. Below is ...

Utilizing the active tab feature within CSS

I am currently working with a detailed structure of bootstrap theme classes. Currently, I am in the process of designing a menu. This is the code snippet for the navigation bar design in Bootstrap- <div class="navbar navbar-fixed-top navbar-invers ...

How can you make a Tempory Drawer wider in Material Components Web?

Increasing the Width of a Temporary Drawer in Material-components-web Greetings! I am currently facing an issue with Material-components-web In the provided demo here, I would like to extend the width of the Temporary drawer to accommodate additional co ...

Text that is arranged vertically and adjusts its size and layout

I'm currently facing a challenge with vertical text display Check out my plunker What I'm attempting to accomplish is vertical text where: If a short text is placed inside the vertical text div, it should be aligned in the middle of the div I ...

Using a color as a substitute for a background image on mobile devices

Is there a way to create a fallback in my CSS for changing the background image to a color when viewed on a mobile browser once the pixels reach the max-width? In the snippet below, the media query "only screen and (max-width: 600px)" works if the top bod ...

How can I trigger a function by clicking on a link that was generated dynamically with jQuery?

I am dynamically creating multiple <a href="#"></a> elements with dynamically assigned id attributes like <a href="#" id='delete"+id+"'></a>. The IDs generated will be like delete01, delete02, .... I want to trigger a func ...

Text below div will be displayed

When hovering over a div, an identical one will appear next to it with more information. Unfortunately, the content appears under the div but retains the styling like border-radius and background color. This is how my HTML looks: The div that needs ...

Utilizing identical CSS for both mobile and desktop interfaces, while customizing margins and paddings separately

I am facing a problem on my website where the padding and margins appear differently on different devices. I have compared screenshots of the site on an Android device and my desktop PC: Site displayed on mobile device: Desktop view: Below is the CSS co ...

What is the correct way to add a dollar sign before a database tag?

I'm currently working on developing a website with an account system, but I've hit a roadblock. I attempted to achieve this using the following code: <?php echo "<p>$</p>"$userRow['username']; ?>. My goal is to have s ...

Setting the root position of a div: How can it be done?

Imagine a scenario where a div element is designed to follow the mouse cursor on the screen. This functionality is achieved by manipulating the document's `mousemove` event and adjusting the div's `left` and `top` positions based on the event dat ...

Creating an arrow dialog box in Material UI: A step-by-step guide

I have successfully created an arrow box (div) using custom CSS and HTML. However, I am facing difficulty in implementing the same design in Material UI with React JS. The code below demonstrates how to achieve this using custom CSS. My question is: How ...