【问题标题】:CSS grid support for autoprefixer on webpack在 webpack 上对 autoprefixer 的 CSS 网格支持
【发布时间】:2018-04-28 13:12:02
【问题描述】:

我在一个项目中使用带有 postcss 和 webpack 的 autoprefixer。我也在使用 CSS 网格。但是,当我构建代码时,我注意到 CSS 网格的 ms 前缀不起作用。

这是我的 postcss.config.js,它适用于诸如 flexbox 之类的东西。

如何启用 CSS 网格支持?

module.exports = {
  plugins: [
    require('autoprefixer')
  ]
}

【问题讨论】:

    标签: css webpack internet-explorer-11 css-grid postcss


    【解决方案1】:

    默认情况下,autoprefixer 不会为网格属性添加前缀。

    autoprefixer documentation:

    Autoprefixer 有 4 个功能,可以通过以下方式启用或禁用 选项:

    ...

    grid: true 将为 IE 启用网格布局前缀。

    设置options 的语法类似于:

    const autoprefixer = require('autoprefixer');
    const plugin = autoprefixer({ grid: true });
    module.exports = { plugins: [ plugin ] }
    

    话虽如此,MDN 对网格属性的自动前缀有这样的说法:

    流行的工具 autoprefixer 已更新以支持 -ms- 使用新网格属性时的网格版本。除非你的布局 是非常简单的基于行的放置,这很可能会导致你更多 它解决的问题。我不建议让 autoprefixer 运行 在网格属性上,而是使用 IE 版本编写一个版本 网格布局,如果它对你有意义的话。

    此外,Rachel Andrew 就这个话题写了a thorough post

    在那篇文章中,她指出以下几点:

    ...即使在两个版本的 规范,旧规范的功能和实现 和新的有很大的不同。这意味着您不能简单地运行 自动前缀并认为工作已完成。

    【讨论】:

    • 你会这样写吗? const autoprefixer = require('autoprefixer'); const plugin = autoprefixer({ grid: true }); module.exports = { 插件:[ 插件 ] }
    • 你是最棒的!! :) 谢谢 !! :)
    猜你喜欢
    • 2018-02-14
    • 2019-04-12
    • 2018-04-16
    • 2017-04-22
    • 2019-12-08
    • 2022-06-11
    • 2019-01-29
    相关资源
    最近更新 更多