我使用TailwindCSS和PostCSS,我有这个css代码:
.btn {
@apply py-1;
@apply px-4;
@apply border;
@apply rounded;
}
.btn:hover {
@apply bg-white text-black;
}
.btn:focus {
@apply bg-black text-white;
}在PostCSS中(或使用插件)有没有一种原生的方式来编写下面这样的代码?
.btn {
@apply py-1;
@apply px-4;
@apply border;
@apply rounded;
&:hover {
@apply bg-white text-black;
}
&:focus {
@apply bg-black text-white;
}
}发布于 2020-09-14 18:31:06
首先安装,npm install postcss-preset-env --save-dev。
然后在postcss.config.js文件中启用nesting-rules,
module.exports = {
plugins: [
"tailwindcss",
[
"postcss-preset-env",
{
stage: 3,
features: {
"nesting-rules": true,
},
},
],
],
};您可以在此处找到可以启用的list of features ID
发布于 2021-04-21 04:53:22
你也可以使用postcss-nested插件。
在你的package.json中
{
"dependencies": {
"postcss": "^8.2.9",
"tailwindcss": "^2.0.4",
"postcss-nested": "^5.0.5"
}
}在你的postcss.config.js中
module.exports = {
plugins: [
require('postcss-nested'),
require('tailwindcss'),
]
}发布于 2021-07-26 14:26:18
也适用,遵循对象表示法Reference
module.exports = {
plugins: {
'postcss-import': {},
tailwindcss: {},
autoprefixer: {},
'postcss-preset-env': { stage: 2 },
},
}https://stackoverflow.com/questions/63550584
复制相似问题