Converting Tailwind 3 half-container plugin #18542
Replies: 2 comments 2 replies
-
Just use ./css/container-half-plugin.js import plugin from 'tailwindcss/plugin';
const containerHalfPlugin = plugin(function({ addBase, theme }) {
const screens = theme('screens');
const entries = Object.entries(screens)
.filter(([_, val]) => typeof val === 'string')
.sort((a, b) => {
return parseInt(a[1].replace(/\D/g, ''), 10) - parseInt(b[1].replace(/\D/g, ''), 10);
})
.map(([_, val]) => ({
[`@media (min-width: ${val})`]: {
'.container-half': {
'max-width': `${parseInt(val, 10) / 2}rem`,
},
},
}));
addBase(entries);
});
export default containerHalfPlugin; ./css/globals.css @import "tailwindcss";
@plugin "./container-half-plugin.js"; Note: Make sure the relative file path is correct. I haven't tested it. Please let me know if I messed anything up :'D I just made the entries declaration passed to |
Beta Was this translation helpful? Give feedback.
-
I tried it out but there were two problems:
Thanks for the effort though! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I used to use the code below for a handy .container-half class. I tried adding it to Tailwind 4 but there are two problems:
Any ideas of where I am going wrong?
Update:
It seems easier to do this using the @Utility function, although I am still curious as to how I would do this using the original plugin approach.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions