
Security News
Open Source Maintainers Feeling the Weight of the EU’s Cyber Resilience Act
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
tailwindcss-children
Advanced tools
Tailwind CSS plugin to add variants that target child elements
This plugin requires Tailwind CSS 1.2 or later. If your project uses an older version of Tailwind, you should install the latest 1.x version of this plugin (npm install tailwindcss-children@1.x
).
npm install tailwindcss-children
// tailwind.config.js
module.exports = {
variants: {
display: ['children', 'default', 'children-first', 'children-last', 'children-odd', 'children-even', 'children-not-first', 'children-not-last', 'children-hover', 'hover', 'children-focus', 'focus', 'children-focus-within', 'focus-within', 'children-active', 'active', 'children-visited', 'visited', 'children-disabled', 'disabled', 'responsive'],
},
plugins: [
require('tailwindcss-children'),
],
};
The above configuration would generate the following CSS:
.children\:block > * {
display: block;
}
.block {
display: block;
}
.children\:first\:block > :first-child {
display: block;
}
.children\:last\:block > :last-child {
display: block;
}
.children\:odd\:block > :nth-child(odd) {
display: block;
}
.children\:even\:block > :nth-child(even) {
display: block;
}
.children\:not-first\:block > :not(:first-child) {
display: block;
}
.children\:not-last\:block > :not(:last-child) {
display: block;
}
.children\:hover\:block > :hover {
display: block;
}
.hover\:block:hover {
display: block;
}
.children\:focus\:block > :focus {
display: block;
}
.focus\:block:focus {
display: block;
}
.children\:focus-within\:block > :focus-within {
display: block;
}
.focus-within\:block:focus-within {
display: block;
}
.children\:active\:block > :active {
display: block;
}
.active\:block:active {
display: block;
}
.children\:visited\:block > :visited {
display: block;
}
.visited\:block:visited {
display: block;
}
.children\:disabled\:block > :disabled {
display: block;
}
.disabled\:block:disabled {
display: block;
}
/* etc. */
Which you can then use in your HTML like this:
<ul class="children:block children:not-first:border-t children:border-gray children:hover:bg-gray">
<li>
First item
</li>
<li>
Second item
</li>
<li>
Last item, this one doesn't have a bottom border
</li>
</ul>
You can also override children:
classes on specific children if needed:
<ul class="children:block children:bg-gray">
<li>
First item
</li>
<li class="bg-red">
Second item, this one has a red background
</li>
<li class="bg-blue">
Third item, this one has a blue background
</li>
<li>
Last item
</li>
</ul>
The above depends on the order of the generated CSS, so make sure to add the default
variant after the children
one in the array of variants (as well as the hover
variant after the children-hover
variant if you want to override a children:hover:*
utility, etc.).
[2.1.0] - 2020-05-09
children-not-last
variantchildren-not-first
variant to > :not(:first-child)
(instead of > * + *
) for consistency with children-not-last
FAQs
Tailwind CSS plugin to add variants that target child elements
The npm package tailwindcss-children receives a total of 1,461 weekly downloads. As such, tailwindcss-children popularity was classified as popular.
We found that tailwindcss-children demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The EU Cyber Resilience Act is prompting compliance requests that open source maintainers may not be obligated or equipped to handle.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.