Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

postcss-quantity-queries

pascalduez21.6kUnlicense0.5.0

PostCSS plugin enabling quantity-queries

css, quantity-queries, postcss, postcss-plugin

readme

postcss-quantity-queries

npm version Build Status Coverage Status

PostCSS plugin enabling quantity-queries.

This plugin is derived from the Sass Quantity Queries mixins by Daniel Guillan.
For informations about quantity queries check those resources:
Quantity Queries for CSS
Styling elements based on sibling count
Daniel’s demo on CodePen

Installation

npm install postcss-quantity-queries --save-dev

Usage

const fs = require('fs');
const postcss = require('postcss');
const quantityQueries = require('postcss-quantity-queries');

const input = fs.readFileSync('input.css', 'utf8');

postcss()
  .use(quantityQueries)
  .process(input)
  .then(result => {
    fs.writeFileSync('output.css', result.css);
  });

API

at-least

Target count items or more:

:at-least(count) { ... }

input:

ul > li:at-least(4) {
  color: rebeccapurple;
}

output:

ul > li:nth-last-child(n+4),
ul > li:nth-last-child(n+4) ~ li {
  color: rebeccapurple;
}

at-most

Target count items or less:

:at-most(count) { ... }

input:

ul > li:at-most(4) {
  color: rebeccapurple;
}

output:

ul > li:nth-last-child(-n+4):first-child,
ul > li:nth-last-child(-n+4):first-child ~ li {
  color: rebeccapurple;
}

between

Target a range of items between start and end:

:between(start, end) { ... }

input:

ul > li:between(4, 6) {
  color: rebeccapurple;
}

output:

ul > li:nth-last-child(n+4):nth-last-child(-n+6):first-child,
ul > li:nth-last-child(n+4):nth-last-child(-n+6):first-child ~ li {
  color: rebeccapurple;
}

exactly

Target exactly count items:

:exactly(count) { ... }

input:

ul > li:exactly(4) {
  color: rebeccapurple;
}

output:

ul > li:nth-last-child(4):first-child,
ul > li:nth-last-child(4):first-child ~ li {
  color: rebeccapurple;
}

All pseudo-selector extensions

Selector Description
# :at-least(count) { … } Target count items or more
# :at-most(count) { … } Target count items or less
# :between(start, end) { … } Target a range of items between start and end
# :exactly(count) { … } Target exactly count items

At-rule API

There is also an at-rule API available, similar to pre-processors.
Although it might get deprecated at some point.
The recommended API is the pseudo-selectors one.

@at-least count [, selector] { ... }
@at-most count [, selector] { ... }
@between start end [, selector] { ... }
@exactly count [, selector] { ... }
ul > li {
  @at-least 4 span {
    color: rebeccapurple;
  }
}

ul > li {
  @between 4 6 {
    color: rebeccapurple;
  }
}

Check out the tests for more examples.

Credits

Licence

postcss-quantity-queries is unlicensed.

changelog

postcss-quantity-queries change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Unreleased

0.5.0 - 2017-05-07

Changed

  • PostCSS 6 upgrade.

0.4.0 - 2015-09-04

Changed

  • PostCSS 5 upgrade.

0.3.1 - 2015-05-02

Fixed

  • Use standard package keyword (#319)

0.3.0- 2015-04-08

Changed

  • Use latest PostCSS 4.1.* plugin API.
  • Upgrade to Babel 5.0.

0.2.0 - 2015-03-12

Added

  • A new pseudo-selectors API. (#2)

0.1.0 - 2015-03-09

  • Initial release.