奇怪的用户界面使用tailwindcss和Nextjs渲染

huangapple go评论83阅读模式
英文:

Weird UI rendered using tailwindcss and Nextjs

问题

Here is the translated content:

所以,我正在尝试使用Next.js、TypeScript和Tailwind CSS。我进行了初始提交,然后开始修改layout.tsx文件。

这是在运行开发服务器后我得到的结果:

奇怪的用户界面使用tailwindcss和Nextjs渲染

这是layout.tsx文件的内容:

import "./globals.css";
import type { Metadata } from "next";
import { Inter } from "next/font/google";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
  title: "Quiz app",
  description: "一个简单的测验应用",
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    <html lang="en">
      <body
        className={`${inter.className} bg-slate-700 container mx-auto p-4 text-slate-100`}
      >
        {children}
      </body>
    </html>
  );
}

page.tsx只包含一个带有h1标签的div。

这是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: {},
  plugins: [],
};

预期的渲染应该是一个连续的slate-700颜色背景。

将不需要翻译的部分保留为原文。

英文:

So i was trying out Next.js with typescript and tailwindcss. I did the initial commit and then started modifying the layout.tsx file.

This is what I get after running the dev server

奇怪的用户界面使用tailwindcss和Nextjs渲染

This is the content of layout.tsx file:

import &quot;./globals.css&quot;;
import type { Metadata } from &quot;next&quot;;
import { Inter } from &quot;next/font/google&quot;;

const inter = Inter({ subsets: [&quot;latin&quot;] });

export const metadata: Metadata = {
  title: &quot;Quiz app&quot;,
  description: &quot;A simple quiz app&quot;,
};

export default function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  return (
    &lt;html lang=&quot;en&quot;&gt;
      &lt;body
        className={`${inter.className} bg-slate-700 container mx-auto p-4 text-slate-100`}
      &gt;
        {children}
      &lt;/body&gt;
    &lt;/html&gt;
  );
}

page.tsx only has a div with h1 tag in it

Here is the tailwind.config.js file content:

/** @type {import(&#39;tailwindcss&#39;).Config} */
module.exports = {
  content: [
    &quot;./pages/**/*.{js,ts,jsx,tsx,mdx}&quot;,
    &quot;./components/**/*.{js,ts,jsx,tsx,mdx}&quot;,
    &quot;./app/**/*.{js,ts,jsx,tsx,mdx}&quot;,
  ],
  theme: {},
  plugins: [],
};

The expected render should've been a continuous background of slate-700 color.

Any help will be appreciated.

答案1

得分: 1

我知道问题出在哪里了。感谢 @wongjn 指出这一点。是 globals.css 文件我没有检查。它有线性渐变的设置和一些东西,导致输出呈现成那样。

英文:

I got to know where the issue was. Thanks to @wongjn for pointing this out. It was the globals.css file that I haven't checked. It had the linear-gradient settings and stuff that was rendering the output like that.

答案2

得分: 0

去到 globals.css,并更改 body 的样式。所以不要使用默认的渐变,而是像这样:

body {
  color: rgb(var(--foreground-rgb));
  background: var(--background-rgb);
}

然后按照您的喜好自定义 --background-rgb

英文:

Go to globals.css and change the styles for body. So instead of the default gradient, something like this:

body {
  color: rgb(var(--foreground-rgb));
  background: var(--background-rgb);
}

And customize --background-rgb as you like.

huangapple
  • 本文由 发表于 2023年7月13日 15:10:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76676769.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定