Adding an external font with CSS in Bootstrap 5 can be quite challenging

Hey there, I'm a newcomer around here and I could use some help with my post. It might not be perfect, but any guidance you can offer would be appreciated.

The issue I'm facing is that I'm having trouble getting the font I downloaded or linked to work, both for my h1 font and body text.

I specifically want to use PressGothic for the h1, but if that doesn't work, I'll settle for Anton.

I've experimented with a few different approaches:

  1. I tried linking the downloaded font files using @font-face
  2. I attempted to call the font using @import url in the CSS and later in the file with font-family, even using "!important" to force it.

After numerous tries, only Oswald seems to work in the body (specifically in the footer).

Is there a solution that doesn't involve customizing bootstrap? I won't be continuing with this project, and I'd prefer not to have the other person redo the bootstrap file. Plus, I'd like to learn from this experience to improve for next time.

Thank you!

@font-face {
  font-family: 'Exo';
  src: url('assets/fonts/Exo-VariableFont_wght.ttf');
}

@font-face {
  font-family: 'PressGothic';
  src: url('assets/fonts/PressGothicPro.ttf') format('truetype');
}

@import url('https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,300;0,400;0,500;0,700;1,100&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@200;300;400;500;600&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Anton&display=swap');
body {
  background: black;
  color: white;
  font-family: 'Oswald', sans-serif;
}

h1 {
  text-transform: uppercase;
  font-size: 5rem;
  font-family: 'Anton', sans-serif !important;
}

p {
  font-family: 'Montserrat', sans-serif;
}
<link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="385a57574c4b4c4a5948780d160a160b">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous" />
<link href="css/style.css" rel="stylesheet" />
</head>

<body id="page-top">

  <header class="text-white">
    <div class="container px-4 text-center">
      <h1>title</h1>
      <p>
        test font
      </p>
  </header>
  <footer class="py-5 bg-dark">
    <div class="container px-4">
      <p class="m-0 text-center text-white">
        copyright
        <a class="text-light" href="assets/doc/qr-code.pdf">
            doc test</a
          >
        </p>
      </div>
    </footer>

Answer №1

It appears that you have successfully imported an external font family using @font-face. However, you are also importing font families from Google Fonts, leading to a conflict between the fonts and potentially causing the font not to display correctly in your project.

To resolve this issue, try removing the imports of the font from Google Fonts.

I trust this solution addresses your concern, but please feel free to reach out if you need further assistance :)

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

What is the best way to implement JavaScript code that can modify the layout of a website across all its pages?

I am facing an issue on my website where, on the index page, clicking a button changes the background color to black. However, this change is not reflected on other pages even though I have linked the JavaScript file to all HTML documents. How can I make i ...

Deleting images based on their class through a loop

Currently, I am in the process of constructing a carousel using data retrieved from an endpoint. The challenge I face is determining the appropriate image size to request from the server. To address this, I perform some front-end processing to dynamically ...

Showing information in a tree structure using HTML, CSS, and JQuery

Trying to figure out how to present a large amount of data in a tree structure. Each node could have multiple children and parents, requiring a dynamic representation. I've explored various JavaScript libraries like D3 and Raphael, but unfortunately, ...

The skipping of crucial text in tab focus is adversely affecting the accessibility of the website

My appbar contains an image link, a warning indicating the user's current environment, and details about the logged-in user. While testing accessibility with a screen reader, I noticed that tab focus skips over the user details in favor of a link in ...

Foundation Unveil Modal hidden from view

I'm currently integrating modals using Foundation 5 in a Rails application. The issue I'm facing is that the modal only works when the page is not scrolled down. If you scroll to the bottom of the page and try to activate the modal by clicking ...

Scrollable content with sticky positioning using CSS3 and JavaScript

I successfully implemented a sidebar using the position: sticky property and it is functioning perfectly. To identify colors in the following text, refer to the script below. When scrolling, the black area remains fixed while the green area sticks to its ...

Express application encountering issue with loading CSS and script files, resulting in net::ERR_ABORTED 404 (Not Found) error

I am facing an issue with my express backend server. When it launches, it is supposed to render an EJS page with index.js in it. However, I encountered 3 errors: Refused to apply style from 'http://localhost:3000/public/styles/style.css' because ...

Round progress indicator with directional pointer

I've been working on creating a round progress bar that features an arrow at the front. This is my current progress: HTML Code: <!-- Container --> <ul class="progress"> <!-- Item --> <li data-name="Item 1& ...

Having issues with custom color themes in a Bootstrap, React, SCSS project

I'm experimenting with custom colors in my bootstrap/react/scss setup. The specific custom color I'm currently using is called "clear". It's interesting to note that when I apply the className "btn-clear" to a button component, the button in ...

Change the CSS element if the current URL is not example.com/page1 or example.com/page2

When I apply the following JS code snippets, my output is incorrect or does not display at all. Below are the codes in question: if (location.href != "website.com/page1" || "website.com/page2") { element.style.backgroundColor='none'; ...

What is the best way to style these CSS elements within the stylesheet?

I'm currently working on customizing a navigation menu in DotNetNuke. Although my question primarily relates to CSS syntax. Can someone please provide guidance on how to style a class that resembles the following? <tr class="mi mi0-0 id58 first"& ...

Is there a way to customize the hamburger icon for the navigation bar in Bootstrap 4?

Struggling to update the icon in the Navbar for bootstrap 4. Here's my current HTML: <nav class="navbar fixed-top navbar-expand-md navbar-custom"> <a class="navbar-brand" href="#"> <img src="images/logo.svg" width="60px" style="m ...

Button with Circular Design by Tailwind

Is there a way to place a circle inside a button with text positioned to the right of it without overlapping in a centered manner? Take a look at this playground HERE <button class="btn btn-change"> <span class="w-5 h-5 bg-red-5 ...

Is it possible to enlarge the window screen using css?

After using zoom at 90%, everything was working fine until we introduced high charts. The hovering property doesn't display in the correct position. Looking for a solution to show a zoomed window on a small screen, like a laptop screen. Does anyone h ...

What is the best way to merge two AngularJS form validation directives criteria using CSS?

When both $dirty and $invalid are true, I would like the input fields to have a red background. However, I am only able to do this one by one, which is not ideal. input.ng-dirty && input.ng-invalid { background-color: red; } ...

Craft a unique parallax effect using Framer Motion's clipping feature

To help visualize my concept, I have sketched it out using Figma. This idea involves a slide transitioning between pages. The goal is to cover the entire page with a sliding effect, and then place a sticker (dubbed the Parallax Box) on top of it. However ...

Is it possible for CSS to accurately crop images by pixels [Sprite Box]?

I attempted to replicate the math used for the previous image cuts and added my own image, but it appears blank. Can you identify where the issue lies? #paymentForm { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webk ...

Error: Placeholder Loading Card malfunctioning

I attempted to incorporate a Placeholder Loading Card into my bootstrap 4 website by adding a sample image, but encountered an issue. The placeholder does not work when the website is loading. Is it supposed to always animate? Does anyone have knowledge ...

Error: Unable to utilize the theme-color() function as expected

Encountered Error: An error occurred during compilation. ./src/@core/scss/react/libs/noui-slider/noui-slider.scss (./node_modules/css-loader/dist/cjs.js??ref--5-oneOf-0-1!./node_modules/postcss-loader/src??postcss!./node_modules/sass-loader/dist/cjs.js??r ...

Images with scratches visible in Chrome

This puzzle may seem easy to some, but it's been quite challenging for me. I've encountered a discrepancy in how Firefox and Chrome render images (specifically technical drawings). Despite my attempts to use image-rendering: -webkit-optimize-cont ...