Replies: 2 comments
-
This is due to how CSS variables are resolved. You could:
|
Beta Was this translation helpful? Give feedback.
0 replies
-
I use this method:
import { Manrope } from 'next/font/google'
import { Inter } from 'next/font/google'
import { Figtree } from 'next/font/google'
import type { ReactNode } from 'react'
import './global.css'
const manrope = Manrope({
variable: '--font-manrope',
subsets: ['latin'],
style: 'normal',
display: 'swap',
preload: true,
})
const inter = Inter({
variable: '--font-inter',
subsets: ['latin'],
style: 'normal',
display: 'swap',
preload: true,
})
const figtree = Figtree({
variable: '--font-figtree',
subsets: ['latin'],
style: 'normal',
display: 'swap',
preload: true,
})
interface RootLayoutProps {
children: ReactNode
}
export default function RootLayout({ children }: Readonly<RootLayoutProps>) {
return (
<html
lang='en'
data-scroll-behavior='smooth'
className={`${manrope.variable} ${inter.variable} ${figtree.variable}`}
>
<body>{children}</body>
</html>
)
}
@import 'tailwindcss';
@theme {
/* Manrope, Inter, and Figtree are passed from the root html tag as variables. */
/* This is necessary for their optimization using Next.js. */
--font-sans:
var(--font-manrope), var(--font-inter), var(--font-figtree), ui-sans-serif,
system-ui, sans-serif;
}
@layer base {
html {
@apply scroll-smooth font-sans antialiased;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey everyone,
I have a bit of trouble using custom font families with
tailwindcss v4
andNext.js 15
. The part that specially troubles me is that it seems tailwindcss can't get the injected var--font-geist-sans
of by Next.js and only redefining it in@theme
fixes it. I've made a repo that tests out how different classes will render, The page itself contains a script that appends to each the font family actually rendered. Theglobals.css
file contains commented out@theme
font family variables properties , I've also made branches with enabling each one and how it affects the render.layout.tsx
page.tsx
globals.css
package.json
Repo : https://github.com/AliMejbar/test (with branches for each css property once enabled)
Preview : test-tw4-next15.vercel.app
Beta Was this translation helpful? Give feedback.
All reactions