admin管理员组文章数量:1387360
According to v4 docs, to override existing or define new spacing (which includes margin, padding, min-w/h, etc.) you use theme namespace:
--spacing-*
So let's say I would like to define mx-max to represent:
margin-inline: 100vh;
I could achieve this by including the following theme:
@theme {
--spacing-max: 100vh;
}
However this also overrides a default utility, for example min-w-max:
Default:
min-width: max-content;
Override:
min-width: 100vh;
I don't want to override other spacing utils, just margin utils. How would I achieve this, considering in previous tailwind versions you could define it in tailwind.config.js:
module.exports = {
theme: {
extend: {
margin: {
'max': '100vh',
}
}
}
}
According to v4 docs, to override existing or define new spacing (which includes margin, padding, min-w/h, etc.) you use theme namespace:
--spacing-*
So let's say I would like to define mx-max to represent:
margin-inline: 100vh;
I could achieve this by including the following theme:
@theme {
--spacing-max: 100vh;
}
However this also overrides a default utility, for example min-w-max:
Default:
min-width: max-content;
Override:
min-width: 100vh;
I don't want to override other spacing utils, just margin utils. How would I achieve this, considering in previous tailwind versions you could define it in tailwind.config.js:
module.exports = {
theme: {
extend: {
margin: {
'max': '100vh',
}
}
}
}
Share
Improve this question
edited Mar 18 at 16:45
rozsazoltan
11.1k6 gold badges20 silver badges58 bronze badges
asked Mar 18 at 16:24
starter_devstarter_dev
813 bronze badges
1 Answer
Reset to default 0In @theme
, only the listed namespaces exist; nothing else can be declared.
- Theme variable namespaces - TailwindCSS v4 Docs
- Spacing: margin - TailwindCSS v4 Docs
From v4 onwards, padding and margin have been redefined and finally equipped with dynamic calculation. This is the dynamic behavior that prompted you to ask the question, as you want to deviate from the standard. You have the option to do so by leveraging CSS features, allowing you to declare a stronger utility.
@layer utilities {
.mx-max {
margin-inline: 100vh;
}
}
From v4 onwards, this can be written using the @utility
directive, as recommended in the documentation:
- Adding custom utilities - TailwindCSS v3 to v4 Upgrade Docs
@utility
directive - TailwindCSS v4 Docs
@utility mx-max {
margin-inline: 100vh;
}
- TailwindCSS v4 Playground
本文标签: cssTailwindcss V4 How To Override Only MarginStack Overflow
版权声明:本文标题:css - Tailwindcss V4 How To Override Only Margin - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744502344a2609392.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论