一个自动为背景图添加 width 和 height 的 PostCSS 插件

阅读 402
收藏 6
2019-01-16
原文链接:github.com

A PostCSS plugin to add CSS rules width and height for background-image automatically.

Get Started

Installation

$ yarn add postcss-background-image-auto-size --dev

Usage

// postcss.config.js
const autoSize = require('postcss-background-image-auto-size');

module.exports = {
    plugins: [
        autoSize(),
    ],
};

Example

/* Before */
.logo {
    background-image: url('./images/logo.png');
}

/* After */
.logo {
    background-image: url('./images/logo.png');
    width: 400px;
    height: 400px;
}

License

Licensed under the MIT License

评论