Replies: 6 comments 4 replies
-
You would just do something like this 👍 // tailwind.config.js
const plugin = require('tailwindcss/plugin')
module.exports = {
plugins: [
plugin(function({ addVariant, e }) {
addVariant('third-child', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`third-child${separator}${className}`)}:nth-child(3)`
})
})
})
]
} I'm not totally sure what you are asking when you say "Can really see how I would deal with the n parameter that should be passed in" though. |
Beta Was this translation helpful? Give feedback.
-
CSS is just static right, so you can't exactly have dynamic parameters in class names. But you can name the variant // tailwind.config.js
const plugin = require('tailwindcss/plugin')
module.exports = {
plugins: [
plugin(function({ addVariant, e }) {
addVariant('child(3)', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`child(3)${separator}${className}`)}:nth-child(3)`
})
})
})
]
} There's no way to do like a "function call" from inside the class attribute of your HTML though. |
Beta Was this translation helpful? Give feedback.
-
Now with jit I mode, can we really do |
Beta Was this translation helpful? Give feedback.
-
https://dev.to/wheelmaker24/why-you-don-t-need-every-css-pseudo-selector-in-tailwind-css-3kn1 |
Beta Was this translation helpful? Give feedback.
-
I have tried, but this does not work // tailwind.config.js
const plugin = require('tailwindcss/plugin')
module.exports = {
plugins: [
plugin(function ({ addVariant, e }) {
addVariant(`nth-child-var`, ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`nth-child-var${separator}${className}`)}:nth-child(var(--variable-number))`
})
})
}),
],
} |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to just use the
addVariant
function in Tailwind to add a nth-child(n) pseudo-class?Can really see how I would deal with the n parameter that should be passed in.
Beta Was this translation helpful? Give feedback.
All reactions