提问人:Kandalia Kiki 提问时间:11/14/2023 最后编辑:Kandalia Kiki 更新时间:11/14/2023 访问量:51
导入字体后 Tailwind CSS 不起作用 [已关闭]
tailwind css not working after importing font [closed]
问:
我正在开发一个下一个.js项目并使用顺风。当我将自定义字体导入全局 .css 时,有一个奇怪的行为
页面.jsx
"use client";
import React from "react";
const page = () => {
return (
<div className=" w-full h-screen flex flex-col justify-center items-center bg-cover bg-center bg-sliding-image ">
<div className={`flex flex-col items-center border `}>
<h1 className="font-greatvibes text-black">The Wedding Of</h1>
</div>
</div>
);
};
export default page;
tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
"./pages/**/*.{js,ts,jsx,tsx,mdx}",
"./components/**/*.{js,ts,jsx,tsx,mdx}",
"./app/**/*.{js,ts,jsx,tsx,mdx}",
],
theme: {
extend: {
backgroundImage: {
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
"gradient-conic":
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
"sliding-image": "url('../assets/images/slidingimage.jpg')",
},
fontFamily: {
satoshi: ["Satoshi", "sans-serif"],
inter: ["Inter", "sans-serif"],
abhaya: ["Abhaya Libre", "serif"],
cormorant: ["Cormorant", "serif"],
greatvibes: ["Great Vibes", "cursive"],
roboto: ["Roboto", "sans-serif"],
},
colors: {
"primary-orange": "#FF5722",
},
transitionDuration: {
0: "0ms",
3000: "3000ms",
},
},
},
plugins: [],
};
全局.css
@import url("https://fonts.googleapis.com/css2?family=Abhaya+Libre:wght@400;500;600&family=Cormorant:wght@400;500;600&family=Great+Vibes&family=Roboto:wght@400;500;700&display=swap");
@tailwind base;
@tailwind components;
@tailwind utilities;
知道这是怎么发生的吗?我什至不认为这有意义
答:
1赞
Hackerbyday
11/14/2023
#1
尝试以“nextjs 方式”导入字体,来自文档:https://nextjs.org/docs/app/building-your-application/optimizing/fonts#with-tailwind-css
你可以添加到你的 layout.jsx(替换为你选择的字体):
import { Inter, Roboto_Mono } from 'next/font/google'
const inter = Inter({
subsets: ['latin'],
display: 'swap',
variable: '--font-inter',
})
const roboto_mono = Roboto_Mono({
subsets: ['latin'],
display: 'swap',
variable: '--font-roboto-mono',
})
export default function RootLayout({ children }) {
return (
<html lang="en" className={`${inter.variable} ${roboto_mono.variable}`}>
<body>{children}</body>
</html>
)
}
在你的 tailwind.config.js 中:
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./pages/**/*.{js,ts,jsx,tsx}',
'./components/**/*.{js,ts,jsx,tsx}',
'./app/**/*.{js,ts,jsx,tsx}',
],
theme: {
extend: {
fontFamily: {
sans: ['var(--font-inter)'],
mono: ['var(--font-roboto-mono)'],
},
},
},
plugins: [],
}
评论
0赞
Kandalia Kiki
11/14/2023
完美工作!为字体制作单独的文件夹后,只需按照文档进行操作即可。只是感觉设置起来有点工作。如果你不使用任何背景图片,我在帖子中使用的方法非常简单,我想知道这是错误还是其他什么
评论