Variants for using quantity queries with Tailwind CSS
npm install tailwindcss-quantity-queriessh
npm install -D tailwindcss-quantity-queries
`
Then add the plugin to your tailwind.config.js file:
`js
/* @type {import('tailwindcss').Config} /
module.exports = {
theme: {
// ...
},
plugins: [
require('tailwindcss-quantity-queries'),
// ...
],
};
`
$3
You can now use the plugin's variants in your HTML classes. The plugin supports the following syntax for selecting elements based on their child count:
- Less Than: children-[<3] — Applies styles if the parent has more than 2 children.
- Greater Than: children-[>5] — Applies styles if the parent has less than 6 children.
- Exact Count: children-[3] — Applies styles if the parent has exactly 3 children.
- Range: children-[2-5] — Applies styles if the parent has between 2 and 5 children.
Example:
`html
Child 1
Child 2
Child 3
`
#### Group Variants
The plugin also supports group variants, allowing you to apply styles based on the count of child elements in a group. Use the following syntax:
- Group Less Than: group-children-[<3]
- Group Greater Than: group-children-[>5]
- Group Range: group-children-[2-5]
Example:
`html
Child 1
Child 2
Child 3
``