项目作者: bugeats

项目描述 :
Minimalist vertical rhythm and horizontal rhythm helpers for stylus.
高级语言: JavaScript
项目地址: git://github.com/bugeats/stylus-vrhr.git
创建时间: 2015-11-04T01:37:03Z
项目社区:https://github.com/bugeats/stylus-vrhr

开源协议:MIT License

下载


stylus-vrhr

Minimalist vertical rhythm and horizontal rhythm plugin for stylus.

I’ve been using these helpers on all my stylus projects for years. It makes your pages look harmonious and consistent. Stop picking random pixel numbers, and use some basic geometry.

Looks like this:

  1. $vertical-rhythm = 20px;
  2. $horizontal-rhythm = 80px;
  3. button
  4. height: vr(2) // 40px
  5. min-width: hr(9/12) // 60px
  6. p
  7. font-size: 33px
  8. line-height: vr(@font-size) // 40px
  9. margin-bottom: vr(2/12) // 3.5px

The vr() and hr() helpers take a plain number and multiply it by the rhythm value. That’s it. As you can see from the example, you can easily use ratios instead. Divisions of 12 are nice.

However, if you pass the helpers a px unit value, the output will be that value rounded up to the nearest rhythm.

Also, all output will be rounded to the nearest half pixel.

Installation

  1. npm install stylus-vrhr

JS API Example:

  1. const stylus = require('stylus');
  2. const vrhr = require('stylus-vrhr');
  3. const rendered = stylus('...')
  4. .use(vrhr())
  5. .render();

Webpack Example:

  1. const vrhr = require('stylus-vrhr');
  2. const webpackConfig = {
  3. module: {
  4. rules: [
  5. {
  6. test: /\.styl$/,
  7. loader: 'stylus-loader',
  8. options: {
  9. use: [
  10. vrhr() // <--- HERE
  11. ]
  12. }
  13. }
  14. ]
  15. }
  16. };

Gulp Example:

  1. const vrhr = require('stylus-vrhr');
  2. gulp.task('styles', function () {
  3. gulp.src('./index.styl')
  4. .pipe(stylus({
  5. use: [
  6. vrhr() // <--- HERE
  7. ]
  8. }))
  9. .pipe(gulp.dest('./index.css'));
  10. });