简体   繁体   English

为什么文本颜色在 Tailwind css + next.js 项目中不起作用

[英]Why isn't text-color working in Tailwind css + next.js project

I have a Next js project with tailwind.我有一个顺风的 Next js 项目。 For whatever reason, certain colors work while others don't.无论出于何种原因,某些颜色有效而其他颜色无效。 For example:例如:

 {title ? <div className={`text-2xl mt-2 mb-2 ${title==='Valid Url!' ? 'text-blue-400' : 'text-red-400'}`}>{title}</div> : null}

When I run the code and "title" is not null, text-blue-400 actually changes the text color.当我运行代码并且“title”不为空时,text-blue-400 实际上改变了文本颜色。 But when I run it with "title" as null text-red-400 doesn't actually change the text color.但是当我使用“title”作为空 text-red-400 运行它时,实际上并没有改变文本颜色。 it just remains black.它只是保持黑色。 It's really odd because if I use text-red-500 it works!!!这真的很奇怪,因为如果我使用 text-red-500 就可以了!!!

this is my tailwind.config.js这是我的 tailwind.config.js

 module.exports = { mode: 'jit', purge: ['./pages/**/*.{js,ts,jsx,tsx}', './components/**/*.{js,ts,jsx,tsx}'], darkMode: false, // or 'media' or 'class' theme: { extend: { width: { '92': '23rem', '112': '28rem', '128': '32rem', '160': '40rem', '192': '48rem', '224': '56rem', '256': '64rem', '288': '72rem', '320': '80rem' }, minWidth: { '20': '5rem', '400': '400px' } }, }, variants: { extend: {}, }, plugins: [], }

here are the imports in _app.js这是 _app.js 中的导入

import 'tailwindcss/tailwind.css';
import '../styles/globals.css';
import 'react-datepicker/dist/react-datepicker.css'

and finally this is globals.css最后这是 globals.css

html,
body {
  padding: 0;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen,
    Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif;
}
/*
a {
  color: inherit;
  text-decoration: none;
}

* {
  box-sizing: border-box;
}*/

.tooltip {
  display: none;
  position: absolute;
}

.has-tooltip:hover .tooltip {
  display: block;
  z-index:50;
}

If anyone can help I'd greatly appreciate it.如果有人可以提供帮助,我将不胜感激。 Idk why this isn't working.知道为什么这不起作用。

Sometimes you need to stop and restart when installing Tilwindcss.有时在安装 Tilwindcss 时需要停止并重新启动。

Did you try to stop it and run it again?您是否尝试停止并再次运行它?


also, if you don't need the second conditional operator argument, you can use just a double "&&"此外,如果您不需要第二个条件运算符参数,您可以只使用双“&&”

<>
      {title && 
      <div className={`text-2xl mt-2 mb-2 ${title==='Valid Url!' ? 'text-blue-400' : 'text-red-400'}`}>{title}</div> 
      }
</>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM