问题:
Button类被默认的tailwind基类覆盖。不确定为什么元素上的类没有被应用。
问题:
如何正确应用我的样式?
截图:
如您所见,.documentCategory__行上背景色被在@tailwind/base中定义index.scss上按钮[type=button]覆盖
/* index.scss */
:root {
--color-primary: #00a3e0;
--color-secondary: #470a68;
--color-success: #87d500;
--color-accent: #e87722;
/* Dark themes below */
--color-dark-primary: rgba(31, 41, 55, 1);
--dark-text: rgba(187, 193, 198, 1);
}
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
我不确定这是否与我切换到dart-scss有关,因此这里是我的Webpack配置,以防我遗漏了什么
import path from 'path'
import { Configuration as WebpackConfiguration, HotModuleReplacementPlugin } from 'webpack'
import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
import HtmlWebpackPlugin from 'html-webpack-plugin'
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import ESLintPlugin from 'eslint-webpack-plugin'
import tailwindcss from 'tailwindcss'
import autoprefixer from 'autoprefixer'
const CopyPlugin = require('copy-webpack-plugin');
interface Configuration extends WebpackConfiguration {
devServer?: WebpackDevServerConfiguration;
}
const config: Configuration = {
mode: 'development',
devServer: {
static: path.join(__dirname, 'build'),
historyApiFallback: true,
port: 4000,
open: true,
hot: true,
},
output: {
publicPath: '/',
},
entry: './src/index.tsx',
module: {
rules: [
{
test: /\.(ts|js)x?$/i,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-react',
'@babel/preset-typescript',
],
},
},
},
{
test: /\.(sa|sc|c)ss$/i,
use: [
'style-loader',
'css-loader',
'sass-loader',
{
loader: 'postcss-loader', // postcss loader needed for tailwindcss
options: {
postcssOptions: {
ident: 'postcss',
plugins: [tailwindcss, autoprefixer],
},
},
},
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
loader: 'file-loader',
options: {
outputPath: '../fonts',
},
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js'],
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/index.html',
}),
new HotModuleReplacementPlugin(),
new CopyPlugin({
patterns: [
// relative path is from src
{ from: 'public/images', to: 'images' },
],
}),
// Add type checking on dev run
new ForkTsCheckerWebpackPlugin({
async: false,
}),
// Add lint checking on dev run
new ESLintPlugin({
extensions: ['js', 'jsx', 'ts', 'tsx'],
}),
],
devtool: 'inline-source-map',
};
export default config
如果有其他文件,我是需要让我知道!
3条答案
按热度按时间1hdlvixo1#
在没有看到您的
index.tsx
的情况下,我只能做出猜测,但以下是导致我们的应用程序出现此问题的原因:在我们的
index.tsx
中,我们导入了index.css
在导入了我们的import App from 'src/App
组件树之后。因此,css被以错误的顺序加载到站点中。首先从组件导入(css模块,正常的css导入),最后是tailwind。转到您的入口文件(可能是
index.tsx
),并尝试将import 'index.scss'
行移到导入根组件的上方。比如这个
阅读更多信息:
https://github.com/tailwindlabs/tailwindcss/discussions/7304#discussioncomment-2256226
von4xj4u2#
即使我遇到了同样的问题,但我使用
Vue3
+element-ui-plus
,花了6个多小时后,我的解决方案是设置:native-type='null'
:<el-button type='primary' round @click='handleClick' :native-type='null'>Click Me</el-button>
但这是一种“黑客”,这要么需要由
Tailwind
或element-ui
团队修复。)讨论就在这里
iyfjxgzm3#
我在使用tailwindcss v3和NextUI时遇到了同样的问题,按钮的背景是“透明的”。通过在按钮的背景中添加type = {null},我解决了这个问题