css - 将文件导入嵌套选择器

标签 css postcss

是否有用于将文件导入/嵌套在选择器中的 postcss 解决方案?我无法让 postcss-importpostcss-nested 执行我想要的操作。

.some-selector {
    @import 'some.css';
}

给定一个文件,例如import-me.css 包含

div {
    color: red;
}

我想处理entry.css

.some-class {
  @import 'import-me.css';
}

然后查看输出

.some-class div {
   color: red;
}

谢谢!

更新:对于简单的示例,您可以使用 postcss-nested-importpostcss-nested 来避免它,但这有几个缺点,因为 (a) postcss-nested-import 路径与运行它的脚本相关,而 css 约定是导入应该与调用文件相关 (b) 维护者已放弃它 https://github.com/eriklharper/postcss-nested-import/issues/2 <--- 本期依次引用https://github.com/postcss/postcss-import/issues/214这是一个死线程:-(

最佳答案

postcss-partial-import 似乎可以解决问题。

https://github.com/jonathantneal/postcss-partial-import

关于css - 将文件导入嵌套选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53870918/

相关文章:

html - Logo 图像溢出菜单栏

css - 尝试在 calc() 中使用 theme() 时出现解析错误

html - 如何使我的元素(img 和视频)100% 高度并水平居中?

html - npm run build 并观看非常慢

javascript - Grunt PostCSS 编译非常慢

postcss - 找不到模块 precss

带有 @nguniversal 的 Angular SSR 和用于 PostCSS 支持的自定义 webpack

html - 修复 css 中的对齐方式

jquery - jQuery 的 CSS 技巧

html - CSS:全宽 Flex 列不会在 Webkit 上彼此堆叠