Skip to content

Instantly share code, notes, and snippets.

@masahirompp
Last active October 12, 2020 12:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masahirompp/7fb18cf56a1d9a1a0bb357e0881f075d to your computer and use it in GitHub Desktop.
Save masahirompp/7fb18cf56a1d9a1a0bb357e0881f075d to your computer and use it in GitHub Desktop.
tailwind css next-sibling margin
...
.-ml-px {
margin-left: -1px;
}
.child-siblings\:m-0 > * + * {
margin: 0;
}
.child-siblings\:m-1 > * + * {
margin: 0.25rem;
}
.child-siblings\:m-2 > * + * {
margin: 0.5rem;
}
...
...
@media (min-width: 640px) {
.sm\:-ml-px {
margin-left: -1px;
}
.sm\:child-siblings\:m-0 > * + * {
margin: 0;
}
.sm\:child-siblings\:m-1 > * + * {
margin: 0.25rem;
}
.sm\:child-siblings\:m-2 > * + * {
margin: 0.5rem;
}
...
}
...
const plugin = require('tailwindcss/plugin')
module.exports = {
theme: {
extend: {}
},
variants: {
margin: ['responsive', 'child-siblings']
},
plugins: [
require('@tailwindcss/custom-forms'),
plugin(function({ addVariant, e }) {
addVariant('child-siblings', ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
return `.${e(`child-siblings${separator}${className}`)} > * + *`
})
})
})
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment