Autoprefixer: -webkit-box vs -webit-flex

Created on 8 Feb 2017  路  22Comments  路  Source: postcss/autoprefixer

iOS 7 and higher needs the newer -webkit-flex instead of the old -webkit-box in order to work.
How can I set this right in the autoprefixer? I'm always getting the old -webkit-box.

Also -webkit-justify-content: space-between; need to be added instead of -webkit-box-pack: justify;

Or am I missing something?

Most helpful comment

Also there is no browserslist option. Add this to your package.json:

  "browserslist": [
    "defaults",
    "last 5 iOS versions"
  ]

All 22 comments

Remove all prefixes from you code if you use Autoprefixer. So write only:

.foo {
  display: flex
}

Yeah, we do:

```
display: flex;
flex-flow: row wrap;
justify-content: space-between;

But autoprefixer 'compiles' it to:

display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-flow: row wrap;
flex-flow: row wrap;
-webkit-box-pack: justify;
-ms-flex-pack: justify;
justify-content: space-between;
```
And not display: -webkit-flex;

Set browsers what you need to support into browserslist config: https://github.com/ai/browserslist

We've checked:
"last 3 iOS versions",
"last 4 iOS versions",
"iOS",
"ios_saf",

But we never get the "display: -webkit-flex;"
Are you?

How do you run Autoprefixer? By gulp, webpack or PostCSS CLI?

You have a syntax error in your config and your Autoprefixer runner didn鈥檛 show it to you.

We use gulp:

var gulp = require('gulp'),
    sass = require('gulp-sass'),
    sourcemaps = require('gulp-sourcemaps'),
    prefix = require('gulp-autoprefixer'),
    notify  = require('gulp-notify'),
    svgmin = require('gulp-svgmin');

gulp.task('sass', function() {
  return gulp.src('scss/*.scss')
    .pipe(sourcemaps.init())
    .pipe(sass()).on('error', notify.onError(function (error) {
      return 'An error occurred while compiling sass.' + error;
    }))
    .pipe(prefix({browserslist: ['last 3 iOS versions']}))
    .pipe(sass({outputStyle: 'expanded'}))
    .pipe(gulp.dest('css'))
});

gulp.task('watch', function () {
  gulp.watch('scss/**/*.scss', ['sass']);
});

gulp.task('default', ['watch']);

display: -webkit-box; should only be used for old iOS:

display: -webkit-box;  /* OLD - iOS 6-, Safari 3.1-6, BB7 */
display: -webkit-flex; /* NEW - Safari 6.1+. iOS 7.1+, BB10 */

gulp-autoprefixer is unofficial plugin. Use official gulp-postcss as in official docs https://github.com/postcss/autoprefixer#gulp

Also there is no browserslist option. Add this to your package.json:

  "browserslist": [
    "defaults",
    "last 5 iOS versions"
  ]

We now use the official gulp-postcss and it works! Thanks!

I'm having the same problem but I'm using the autoprefixer via postcss-cli. With this configuration:

"browserslist": [
    "defaults",
    "last 2 versions",
    "ie >= 10",
    "Android >= 4",
    "Safari >= 6"
  ]

I think i should get these results (and it works in the https://autoprefixer.github.io):

Original:

.example {
    display: flex;
    flex-wrap: wrap;
}

Prefixed:

.example {
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-wrap: wrap;
        -ms-flex-wrap: wrap;
            flex-wrap: wrap;
}

But this is what I'm getting:
```css
.example {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
}

This issue appeared when I updated postcss-cli from version 2.6.0 to 3.0.0. With version 2.6.0 of the CLI the prefixing is done properly but with 3.0.0 not.

Steps to reproduce:

  1. Compile the css above with the browserlist config above using postcss-cli version 2.6.0 and take note of the results
  2. Compile the css above with the browserlist config above using postcss-cli version 3.0.0 and take note of the results

ping @ai

What input CSS do you have, what output, what is browserslist config content?

Here you go:

browserslist

"browserslist": [
  "defaults",
  "last 4 versions",
  "last 6 iOS versions",
  "last 6 Android versions",
  "last 6 Safari versions",
  "last 2 ie versions"
]

input css

.example {
  display: flex;
  flex-wrap: wrap;
}

output css with postcss-cli version 2.6.0

.example {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
      -ms-flex-wrap: wrap;
          flex-wrap: wrap; }

output css with postcss-cli version 3.0.0

.example {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
      flex-wrap: wrap; }

Could you try move browsers to browsers option? Maybe we found a issue in postcss-cli and it doesn't send current file path to plugins?

Sure but what do you mean by:

Could you try move browsers to browsers option?

I'm not really sure.

autoprefixer ({ browsers: "" })

So, tested with this script and the same css as above.

var autoprefixer = require('autoprefixer')
var postcss = require('postcss')
var fs = require('fs')

fs.readFile('./postcsstest.css', 'utf8', function (err, data) {
  if (err) {
    return console.log(err)
  }

  postcss([
    autoprefixer({
      browsers: 'defaults, last 4 versions, last 6 iOS versions, last 6 Android versions, last 6 Safari versions, last 2 ie versions'
    })
  ])
  .process(data)
  .then(function (result) {
    result.warnings().forEach(function (warn) {
      console.warn(warn.toString())
    })
    console.log(result.css)
  })
})

output css with postcss-cli version 3.0.0

.example {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
      -ms-flex-wrap: wrap;
          flex-wrap: wrap;
}

output css with postcss-cli version 2.6.0

.example {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-flex-wrap: wrap;
      -ms-flex-wrap: wrap;
          flex-wrap: wrap;
}

And as the CLI doesn't get used it doesn't affect the results.

@sarukuku sorry, I will send you to postcss-cli repo. I think it is their problem.

@ai no worries, I'll open an issue there

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Malvoz picture Malvoz  路  36Comments

raphaelgoetter picture raphaelgoetter  路  31Comments

tobiastom picture tobiastom  路  26Comments

jens-duttke picture jens-duttke  路  19Comments

kossnocorp picture kossnocorp  路  24Comments