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

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

Weird UI rendered using tailwindcss and Nextjs

问题

Here is the translated content:

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

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

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

这是layout.tsx文件的内容:

  1. import "./globals.css";
  2. import type { Metadata } from "next";
  3. import { Inter } from "next/font/google";
  4. const inter = Inter({ subsets: ["latin"] });
  5. export const metadata: Metadata = {
  6. title: "Quiz app",
  7. description: "一个简单的测验应用",
  8. };
  9. export default function RootLayout({
  10. children,
  11. }: {
  12. children: React.ReactNode;
  13. }) {
  14. return (
  15. <html lang="en">
  16. <body
  17. className={`${inter.className} bg-slate-700 container mx-auto p-4 text-slate-100`}
  18. >
  19. {children}
  20. </body>
  21. </html>
  22. );
  23. }

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

这是tailwind.config.js文件的内容:

  1. /** @type {import('tailwindcss').Config} */
  2. module.exports = {
  3. content: [
  4. "./pages/**/*.{js,ts,jsx,tsx,mdx}",
  5. "./components/**/*.{js,ts,jsx,tsx,mdx}",
  6. "./app/**/*.{js,ts,jsx,tsx,mdx}",
  7. ],
  8. theme: {},
  9. plugins: [],
  10. };

预期的渲染应该是一个连续的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:

  1. import &quot;./globals.css&quot;;
  2. import type { Metadata } from &quot;next&quot;;
  3. import { Inter } from &quot;next/font/google&quot;;
  4. const inter = Inter({ subsets: [&quot;latin&quot;] });
  5. export const metadata: Metadata = {
  6. title: &quot;Quiz app&quot;,
  7. description: &quot;A simple quiz app&quot;,
  8. };
  9. export default function RootLayout({
  10. children,
  11. }: {
  12. children: React.ReactNode;
  13. }) {
  14. return (
  15. &lt;html lang=&quot;en&quot;&gt;
  16. &lt;body
  17. className={`${inter.className} bg-slate-700 container mx-auto p-4 text-slate-100`}
  18. &gt;
  19. {children}
  20. &lt;/body&gt;
  21. &lt;/html&gt;
  22. );
  23. }

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

Here is the tailwind.config.js file content:

  1. /** @type {import(&#39;tailwindcss&#39;).Config} */
  2. module.exports = {
  3. content: [
  4. &quot;./pages/**/*.{js,ts,jsx,tsx,mdx}&quot;,
  5. &quot;./components/**/*.{js,ts,jsx,tsx,mdx}&quot;,
  6. &quot;./app/**/*.{js,ts,jsx,tsx,mdx}&quot;,
  7. ],
  8. theme: {},
  9. plugins: [],
  10. };

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 的样式。所以不要使用默认的渐变,而是像这样:

  1. body {
  2. color: rgb(var(--foreground-rgb));
  3. background: var(--background-rgb);
  4. }

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

英文:

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

  1. body {
  2. color: rgb(var(--foreground-rgb));
  3. background: var(--background-rgb);
  4. }

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:

确定