https://github.com/jfairbank/nth-child
Calculate the nth-child equation for CSS selectors
https://github.com/jfairbank/nth-child
Last synced: 7 months ago
JSON representation
Calculate the nth-child equation for CSS selectors
- Host: GitHub
- URL: https://github.com/jfairbank/nth-child
- Owner: jfairbank
- License: mit
- Created: 2015-12-30T19:33:05.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-30T22:29:51.000Z (almost 10 years ago)
- Last Synced: 2025-02-24T16:54:03.914Z (8 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nth-child
Calculate the nth-child equation for CSS selectors.
For example, if you wanted to have a selector for every third child element
(i.e. 1, 4, 7), you would use the selector `nth-child(3n + 1)`. To calculate
this we can take the first two numbers, 1 and 4, and pair them with 0 and 1,
respectively. We treat each pair as an `(x, y)` coordinate pair where the
desired children numbers are the y coordinates (i.e. `(0, 1)` and `(1, 4)`). We
use these two coordinate pairs to calculate the linear equation that represents
the nth-child selector.## Install
$ npm install -g nth-child
## Usage
$ nth-child n1 n2
## Examples
#### Target every child starting with the second child
$ nth-child 2 3
n + 2#### Target every third child
$ nth-child 1 4
3n + 1#### Target the first two children
$ nth-child 2 1
-n + 2