React is not applying the font as expected

Currently, I am working on setting up a @font-face in my index.css file:

@font-face {
    font-family: "Raleway";
    src: url(../assets/fonts/Raleway/Raleway-VariableFont_wght.ttf) format(truetype),
}

Next, I am trying to apply this font family by specifying it in the font-family property within the body tag:

body {
    position: relative;
    font-family: "Raleway";
    overflow-x: hidden;
    overflow-y: auto;
}

Even though I have imported the index.css file into my index.js, the specified font is still not being applied to the body.

Answer №1

To improve your website's design, consider the following changes in your CSS file:

@font-face {
  font-family: "Raleway";
  src: local("Raleway"),
       url(../assets/fonts/Raleway/Raleway-VariableFont_wght.ttf) 
       format(truetype),
}
body {
  position: relative;
  font-family: "Raleway";
  overflow-x: hidden;
  overflow-y: auto;
}

Here is an example of a component using the specified CSS:

import React from "react"

// Include CSS File
import "index.css"

const So74327630 = (props) => <div>Example</div>

export default So74327630

For more detailed guidance on handling images, fonts, and files with Create React App, refer to this resource: "Adding Images, Fonts, and Files"

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

There seems to be an issue with authentication in React JS and AWS Cognito as the logins are

I've been encountering an issue with logging in. Every time I try, I keep receiving the error message: Logins don't match. Please include at least one valid login for this identity or identity pool. I already have a registered user and have confi ...

When you click on a sublevel in the vertical CSS and JavaScript onclick menu, it disappears automatically

I'm a beginner when it comes to Javascript, and I'm still getting the hang of CSS/HTML. Currently, I am working on creating a vertical menu using CSS and javascript. My goal is to have the sublevels appear on the right side of the menu when someo ...

I would like the dropdown menu to only appear on mobile devices

After creating a dropdown menu, I now want it to only appear in mobile view and not in other views. I believe this can be achieved using "visible-xs" or a similar method, but I am struggling with the coding. Below is my HTML code: <nav class="navb ...

Including Previous & Next Buttons in Product Categories

I have set up the display of category products on the home page using the block below: {{block type="catalog/product_list" template="catalog/product/home_short.phtml" category_id="5" column_count="6"}}. I now want to include previous and next buttons to ...

When I click on the button, the page reloads instead of executing the essential code

On my website, there is a settings page where users can edit their profiles. After editing, they click the update button which triggers the updateProfileData function. This works smoothly in Chrome browser, but in Firefox, the page reloads as soon as the b ...

Providing a data point for each frame of animation within React Native

Running Animated.timing with this.state.ys, setting toValue: 0 and duration as 4000 milliseconds. ).start(); Is there a way to send ys.Value to the parent component whenever Animated completes its action? ...

Customizing CSS by replacing link file styles with code in the HEAD section

UPDATE: After further examination, it appears that the code is functioning correctly. My apologies for any confusion. I am attempting to override certain CSS rules on specific pages. Below is an example of my approach. Can anyone confirm if this is a vali ...

The Clash of Backdrop Modals and Dropdown Menus

Looking for a solution to ensure that the datetimepicker stays in place when a user scrolls, even after opening the Modal backdrop with the "Open" button? The challenge lies in maintaining the position fixed for the modal while preventing the datetimepic ...

Issue with Color Attribute in Heading within an Ionic Content Element

The color attribute doesn't seem to be working in Ionic 2. It works fine with normal Ionic tags, but not with HTML tags. Can someone help me with this? The code is provided below. <ion-content> <div class="page-home"> <h1 color="second ...

Enhancing User Interfaces with React and CSS Styling

I need to incorporate two unique React components on my webpage: Component1 and Component2. Code for Page1: <Component1/> <Component2/> While the individual components will have their own CSS files for styling, I also have a page1.css file f ...

Incorporating dynamic images from local sources into a listview in a React Native

I'm currently having an issue with loading local images in a React Native app that I'm developing. As per the instructions provided in the documentation at https://facebook.github.io/react-native/docs/images.html It's mentioned in the guid ...

Display or conceal the location where the click event occurs within a single div

progress $(".button-toggle").click(function(e){ $(this).parents.find('#second').toggle(); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="first"> <a href="#" class= ...

What is the process for generating an array of arrays in a React component?

I'm currently working on developing a word-guessing game similar to Wordle using React. The interesting twist in this game is that players have the ability to choose both the number of attempts allowed and the length of the word they are trying to gue ...

Child div within a parent div with absolute positioning does not extend to the full height of the webpage

I am currently facing an issue with a bug in my project that I am working on. The mobile menu is not taking the full height of the viewport when the screen size is less than 768px, even though it has been set to 100%. It only becomes visible when toggled ...

React component unable to process form submission

In my React application, I have created a form to input certain values which will then be stored in a MongoDB database named tasks. The code block I have implemented is as follows: import React, { useState, useEffect } from 'react'; import &apos ...

How can I adjust a large image to fit the browser window using CSS?

I have a large image (3000px by 2000px) that I want to use as the background for my website and adjust it to fit the window size. Currently, I have implemented the following CSS: body { background: url('image.jpg') !important; background ...

The installation of the .ipa file was unsuccessful on any iOS device

Currently in the process of developing a hybrid app using react-native. The Android version of the app is working flawlessly, however, I encountered an error when attempting to build the .ipa file for iOS - receiving a message stating "app could not be ins ...

Utilizing SingleSpa Micro-frontends in Development standalone mode without Internet connectivity

Seeking guidance on how to override dependencies of a Single-Spa running Micro frontend in standalone mode. The challenge I face is needing to run my Micro frontend in development standalone mode using Webpack Dev Server in an environment without Internet ...

``I am curious about using react-particles-js as a dynamic background for my React projects. It would

Currently, I am in the process of developing my portfolio using React.js and have implemented react-particles-js for the background. However, I want this component to function as the background itself. Are there any alternative solutions similar to react-p ...

Updating an object within an array of objects can be achieved by utilizing the setState method in React

I'm currently working with React, where my state is structured as an array of objects. I'm looking for a way to specifically update only one element in the state.data array, such as the object with id 1. I'm curious about: how to properly ...