The properties of the NextFont variable cannot be utilized in the CSS global scope when using the var() function

// font.ts file

import { Quicksand, Syncopate } from 'next/font/google';

export const quickSandRegular = Quicksand({
  subsets: ['latin'],
  variable: '--font-quicksand-reg',
  weight: '400',
  display: 'swap',
});
export const quickSandSmBold = Quicksand({
  subsets: ['latin'],
  variable: '--font-quicksand-smbold',
  weight: '600',
  display: 'swap',
});

export const syncopateRegular = Syncopate({
  subsets: ['latin'],
  variable: '--font-syncopate-reg',
  weight: '400',
  display: 'swap',
});

export const syncopateBold = Syncopate({
  subsets: ['latin'],
  variable: '--font-syncopate-bold',
  weight: '700',
  display: 'swap',
});

//layout.tsx file

import {
  quickSandRegular,
  quickSandSmBold,
  syncopateBold,
  syncopateRegular,
} from '@/lib/fonts';

export default function RootLayout({
 children,
}: Readonly<{
  children: React.ReactNode;
}>) {return (
    <html lang="en">
      <body
        className={`${[
          syncopateRegular.variable,
          syncopateBold.variable,
          quickSandRegular.variable,
          quickSandSmBold.variable,
        ]}  `}
      >
        {children}
      </body>
    </html>
  );
}
// global.css file
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
  .card {
    & .header {
      font-family: var(--font-syncopate-reg);
      @apply center;
    }
  }
}
// page.tsx file

export default function CustomerList() { 
  return (<Card className="card">
        <CardHeader>
          <CardTitle className="header">RIMIX</CardTitle>
        </CardHeader>
      </Card>)
}

I attempted to modify the font using NextFont's variable in my CSS file, but it did not take effect.

Following the guidance from NextJs documentation, I tried specifying the font family inside my css file using the defined variable name.

const syncopateRegular = Syncopate({
  subsets: ['latin'],
  variable: '--font-syncopate-reg', /** using this in global css file in var() */
  weight: '400',
  display: 'swap',
});

However, the font of my text remained unchanged.

Initially, I suspected the issue was due to using .className instead of .variable suffix for the fonts inserted into the Root Layout, but that was not the cause.

Answer №1

After delving into the documentation, I successfully tackled this issue by realizing that I needed to include the .variable classNames individually instead of placing them all in an array.

<body
        className={`${syncopateRegular.variable} ${syncopateBold.variable} ${quickSandRegular.variable} ${quickSandSmBold.variable}  `}
      >
        {children}
      </body>

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

Issue with PrimeNG DataTable contextMenu alignment inside TabView

I encountered an issue with displaying a DataTable - contextMenu when it is placed within a TabView. The contextMenu was appearing off-center. However, the DataTable - contextMenu worked perfectly fine when it was not wrapped in a TabView. To address this ...

What causes a header to appear transparent when it has a background color set in HTML?

I'm attempting to create a webpage that resembles Gmail. I have a header with a background color, but when I scroll, the content in the body becomes visible. Here is the view without scrolling: https://i.stack.imgur.com/UQ2sO.png However, while scr ...

Having some trouble in the production process, would greatly appreciate any suggestions or clues

While deploying my ecommerce app on Vercel, I encountered an error related to authentication using Next-auth. The specific error message is: TypeError: Cannot read properties of null (reading 'id') at a (/vercel/path0/.next/server/app/dashboa ...

How come my JavaScript regular expression doesn't function properly when applied to elements in an array?

let numbers = new Array('1','2','3'); let letters = new Array('a','b','c'); let length = numbers.length; let str = 'abcdefgabcdefg'; for (let i=0; i<length; i++) { let regex = new ...

What is the best way to apply typography theme defaults to standard tags using Material-UI?

After reading the documentation on https://material-ui.com/style/typography/ and loading the Roboto font, I expected a simple component like this: const theme = createMuiTheme(); const App = () => { return ( <MuiThemeProvider theme={theme}> ...

Tips for altering the icon fill color in toastr notifications

I have customized toastr success and error messages in my application by changing the background and font colors. Now, I want to update the colors of the icons displayed in these messages. Despite my thorough search, I have been unable to find a way to mod ...

What are the steps for implementing a two-column layout in reveal.js?

When creating my slides using reveal.js, I write them in Markdown code. I am now looking to present my content (text, bulleted lists, or images) in a traditional two-column text layout. While I am open to a more complex initial setup, I want to ensure that ...

How to eliminate the hashtag from the slug while referencing an element by its id in Next.js

Is there a way to eliminate the # from the URL when referencing an element by its id (changing domain.com/#contact to domain.com/contact)? For example, if you click this link: <Link href="about"><a>Contact</a></Link>, the ...

What could be causing the position sticky to not function properly in my script?

Can someone help me troubleshoot an issue with the TopOptions image and component sticking to the top of the page? {!categorySearch && ( <div className="max-w-2xl mx-auto z-40 relative overflow-x-hidden font-metropolis_semibold" ...

Both the Stripe webhook events customer.subscription.created and customer.subscription.updated are fired simultaneously

With nextjs 13 API and Stripe integration, a challenge arises after creating a customer subscription where two events are triggered simultaneously: `customer.subscription.created` and `customer.subscription.updated`. The desired outcome is to have only one ...

Adjust the height and width dynamically in CSS/HTML based on various screen dimensions

There are 2 major concerns I have regarding this layout : .feature_content (with a grey background) does not adjust its height and width to different screen sizes. Currently, on large screens, .feature_content is positioned far from the footer. There is ...

Fixing the Overflow Property in CSS

I just started learning about css, and I've encountered a problem with the code for the overflow property: div.hidden { background-color: #00FF00; width: 1000px; height: 1000px; overflow: hide; } ...

Error: Unable to access the 'error' property because it is undefined

I have already defined the error, but I am getting an error message stating "TypeError: Cannot read property 'error' of undefined". I am stuck here and would appreciate any ideas on how to move forward. Thank you for your assistance. Error scr ...

Issue with routing in Next.js 13.4 - tailAdmin interface

I recently utilized a template from https://github.com/TailAdmin/free-nextjs-admin-dashboard. However, I'm encountering a 404 error when trying to access my new blog page. The path causing the issue is "/app/blog/[id].tsx" import React from "r ...

Aligning MaterialUI Grid items vertically within various Grid containers

Looking to implement a design that features three vertical columns. The first and last columns will display MaterialUI cards, while the middle column will showcase a vertical line with dots aligned vertically with the start of each card. The height of the ...

Initiating a file download using HTML

When I try to initiate a download by specifying the filename, instead of downloading, it opens in a new tab. The code snippet below shows what I am currently using. Additionally, I am working on Chrome Browser. <!DOCTYPE html> <html> < ...

Safari browser experiencing issues with JQuery Slider functionality

I am facing an issue with a slider that works perfectly in all browsers except Safari. I have been struggling to figure out the root cause of this problem. You can view the fiddler code here: http://jsfiddle.net/sjramsay/UyvvL/ It appears that when the co ...

What is the best way to add padding between form elements in Bootstrap 4?

Is there a way to add space between form elements in Bootstrap 4? The code snippet below shows an example where the full name has spacing from '@' but the username does not have any. Any suggestions on how to fix this? <form class="form-inlin ...

Consistently maintaining a uniform distance between icons and the border box is essential

I am working on a team overview for a company where data such as name, job title, and information are fetched from the database. Due to varying lengths of information, the icons are not aligning properly in one line. https://i.sstatic.net/cEmKj.png Does ...

Is it possible to rearrange column order in Bootstrap 4x according to different viewport sizes?

One of the great things about Bootstrap is its ability to rearrange columns regardless of the HTML structure. However, I am looking to have a different order of elements when the viewport size is smaller (e.g., Mobile). The current HTML structure looks li ...