Giter Site home page Giter Site logo

webmechanic / postcss-quantity-queries Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pascalduez/postcss-quantity-queries

0.0 1.0 0.0 108 KB

PostCSS 8 plugin enabling quantity-queries

License: The Unlicense

JavaScript 50.04% CSS 43.05% Makefile 6.91%

postcss-quantity-queries's Introduction

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.

postcss-quantity-queries's People

Contributors

grawl avatar greenkeeper[bot] avatar pascalduez avatar

Watchers

 avatar

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.