1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
# postcss-quantity-queries
[![npm version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Coverage Status][coveralls-image]][coveralls-url]
> [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
```js
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:
```css
:at-least(count) { ... }
```
input:
```css
ul > li:at-least(4) {
color: rebeccapurple;
}
```
output:
```css
ul > li:nth-last-child(n+4),
ul > li:nth-last-child(n+4) ~ li {
color: rebeccapurple;
}
```
### at-most
Target `count` items or less:
```css
:at-most(count) { ... }
```
input:
```css
ul > li:at-most(4) {
color: rebeccapurple;
}
```
output:
```css
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`:
```css
:between(start, end) { ... }
```
input:
```css
ul > li:between(4, 6) {
color: rebeccapurple;
}
```
output:
```css
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:
```css
:exactly(count) { ... }
```
input:
```css
ul > li:exactly(4) {
color: rebeccapurple;
}
```
output:
```css
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) `:at-least(count) { … }` | Target `count` items or more
[#](#at-most) `:at-most(count) { … }` | Target `count` items or less
[#](#between) `:between(start, end) { … }` | Target a range of items between `start` and `end`
[#](#exactly) `: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.
```css
@at-least count [, selector] { ... }
```
```css
@at-most count [, selector] { ... }
```
```css
@between start end [, selector] { ... }
```
```css
@exactly count [, selector] { ... }
```
```css
ul > li {
@at-least 4 span {
color: rebeccapurple;
}
}
ul > li {
@between 4 6 {
color: rebeccapurple;
}
}
```
Check out the [tests](test/fixture) for more examples.
## Credits
* [Pascal Duez](https://github.com/pascalduez)
## Licence
postcss-quantity-queries is [unlicensed](http://unlicense.org/).
[PostCSS]: https://github.com/postcss/postcss
[Quantity Queries mixins]: https://github.com/danielguillan/quantity-queries
[Quantity Queries for CSS]: http://alistapart.com/article/quantity-queries-for-css
[Styling elements based on sibling count]: http://lea.verou.me/2011/01/styling-children-based-on-their-number-with-css3
[Daniel’s demo on CodePen]: http://codepen.io/danielguillan/pen/GgBOxm
[npm-url]: https://www.npmjs.org/package/postcss-quantity-queries
[npm-image]: http://img.shields.io/npm/v/postcss-quantity-queries.svg?style=flat-square
[travis-url]: https://travis-ci.org/pascalduez/postcss-quantity-queries?branch=master
[travis-image]: http://img.shields.io/travis/pascalduez/postcss-quantity-queries.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/pascalduez/postcss-quantity-queries
[coveralls-image]: https://img.shields.io/coveralls/pascalduez/postcss-quantity-queries.svg?style=flat-square
[depstat-url]: https://david-dm.org/pascalduez/postcss-quantity-queries
[depstat-image]: https://david-dm.org/pascalduez/postcss-quantity-queries.svg?style=flat-square
[license-image]: http://img.shields.io/npm/l/postcss-quantity-queries.svg?style=flat-square
[license-url]: UNLICENSE
|