Giter Site home page Giter Site logo

dasx10 / gulp-px2rem-converter Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 435 KB

Convert all px to rem

Home Page: https://www.npmjs.com/package/gulp-px2rem-converter

License: MIT License

JavaScript 62.16% TypeScript 19.70% CSS 11.15% Less 3.50% SCSS 3.50%
gulpplugin css converter px rem px2rem gulp scss less media

gulp-px2rem-converter's Introduction

gulp converter pixel to rem

Build Status

Convert all px to rem

install

npm i -D gulp-px2rem-converter

use

const gulp = require('gulp');
const pxToRem = require('gulp-px2rem-converter')

function css(){
    return gulp.src('./*.css')
    .pipe(pxToRem())
    .pipe(gulp.dest('./dist'))
}

module.exports.css = css;

If you are not using :root or html or they do not have a font-size then you can ignore it. The default value 16px will be taken or you can specify this value manually

pxToRem(16)

or

pxToRem('16px')

or

pxToRem('100%')

run

gulp css

example

input

html{
    font-size: 62.5%;
}
div{
    padding: 160px;
    border:1px solid red;
}
@media (min-width:120px){
    div{
        padding: 120px;
    }
}

output

html{
    font-size: 62.5%;
}
div{
    padding: 16rem;
    border:0.1rem solid red;
}
@media (min-width:12em){
    div{
        padding: 12rem;
    }
}

example use :root

input


:root{
    font-size: 20px;
}
html{
    font-size: 20px;
}
div{
    padding: 40px;
}
@media(min-width:1200px){
    div{
        padding: 60px;
    }
}

output

:root{
    font-size: 20px;
}
html{
    font-size: 1rem;
}
div{
    padding: 2rem;
}
@media(min-width:60em){
    div{
        padding: 3rem;
    }
}

info

The plugin works with units such as % or px. If you are using other devices, do not use this plugin. Unable to compute units that are dynamic by the browser.

Also converts all @media to em where px was used. Using em will resize all dimensions to those specified by the user. rem is not used due to bugs in Safari browsers

The plugin is not case sensitive. You can enter both px and PX or Px

Doesn't work if you use font-size in :root or html in @ media. By default will take only the first font-size in :root or html if there is no font-size value in :root

compatibility

css less(http://lesscss.org/) scss

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.