Replies: 11 comments 7 replies
-
Agree on this one! For the time being I found that tweaking the text line-height on the |
Beta Was this translation helpful? Give feedback.
-
I ran into this as well and created tailwindlabs/tailwindcss.com#891 so other may not need to research this. |
Beta Was this translation helpful? Give feedback.
-
It would be great to have an option to add margin around divider, so it can be used instead of |
Beta Was this translation helpful? Give feedback.
-
Another way is adding a helper plugin const notFirst = plugin(({ addVariant, e }) => {
addVariant("not-first", ({ modifySelectors, separator }) => {
modifySelectors(({ className }) => {
const element = e(`not-first${separator}${className}`);
// return `.${element} > * + *`;
return `.${element} > :not(:first-child)`;
});
});
}); then use it in HTML like so not-first:before:content-['_|_'] I've got it working on my website canrau.com at the very bottom in the footer, though copying the whole line lacks spaces between the parts, not exactly sure how to fix this, tho in this case it's not too much of a concern to me for now u Edit, tho I changed it back to <span>[..]</span>
{" | "}
<span>[..]</span> |
Beta Was this translation helpful? Give feedback.
-
This is how I do this in React using the classNames helper by Tailwind <p className="flex flex-row divide-x-2">
{categories.map((category, index) => {
return (
<div
key={category.name}
className={classNames("pr-4", index > 0 && "pl-4")}
>
<Link href={category.uri} className="hover:underline">
<a>{category.name}</a>
</Link>
</div>
);
})} Here is the helper - it just concatenates class names: function classNames(...classes) {
return classes.filter(Boolean).join(" ");
} Basically - add padding around items, conditionally skipping the first one. |
Beta Was this translation helpful? Give feedback.
-
Agreed this would be great functionality, I think it would be really easy for tailwind to just add divide-x-SIZE to their classes, as the class would just be: (my example is with a custom size called medium and based on their spacing-x class)
I have added this to my tailwind.css so that I can use it with the responsive classes, but it would be great if tailwind could automatically go through each size and create this new space class. Would there be scope for this to be added? |
Beta Was this translation helpful? Give feedback.
-
+1 on this problem. I feel like there are a lot of use cases for this. Sadly, no easy way to do this without breaking changes on Tailwind imo |
Beta Was this translation helpful? Give feedback.
-
To solve this, do something like: <div class="divide-y divide-green-900">
<div class="py-10 first:pt-0 last:pb-0">
hello
</div>
<div class="py-10 first:pt-0 last:pb-0">
hello
</div>
<div class="py-10 first:pt-0 last:pb-0">
hello
</div>
</div> In other words, keep |
Beta Was this translation helpful? Give feedback.
-
One solutions is to add custom utilities that will use :before to place dividers in the midle between gaps. Usage:
/** @type {import('tailwindcss').Config} */
const plugin = require("tailwindcss/plugin");
const {
default: flattenColorPalette,
} = require("tailwindcss/lib/util/flattenColorPalette");
module.exports = {
plugins: [
plugin(function ({ matchUtilities, theme }) {
matchUtilities(
{
"chop-x": (value, ...more) => {
value = value === "0" ? "0px" : value;
return {
"& > :not([hidden]) ~ :not([hidden])": {
position: `relative`,
},
"& > :not([hidden]) ~ :not([hidden]):before": {
"@defaults border-width": {},
content: "''",
position: "absolute",
top: 0,
left: `calc(var(--tw-chop-x-offset,-1px)*-1)`,
height: "100%",
"border-right-width": `${value}`,
},
};
},
},
{ values: theme("borderWidth"), type: ["line-width", "length", "any"] }
);
matchUtilities(
{
chop: (value) => {
return {
["& > :not([hidden]) ~ :not([hidden]):before"]: {
"border-color": value,
},
};
},
},
{
values: (({ DEFAULT: _, ...colors }) => colors)(
flattenColorPalette(theme("borderColor"))
),
type: ["color", "any"],
}
);
matchUtilities(
{
"chop-offset": (value) => {
return {
[`& > :not([hidden]) ~ :not([hidden]):before`]: {
"--tw-chop-x-offset": value,
},
};
},
},
{ values: theme("spacing") }
);
}),
],
}; |
Beta Was this translation helpful? Give feedback.
-
Since Tailwind 3.4 we can add styling to an element's children. This way, we can use <div class="flex flex-col divide-y *:py-4 first:*:pt-0 last:*:pb-0">
<!-- Other elements -->
</div> |
Beta Was this translation helpful? Give feedback.
-
I ended up wrapping a half-baked solution in a plugin, in case someone finds it useful. Didn't want to have to repeat snippets between project configs. https://github.com/jeroenwtf/tailwindcss-divide-pad#readme If you have better approaches let me know :) |
Beta Was this translation helpful? Give feedback.
-
Hey 👋,
I ran into an issue that utilities
divide-*
andspace-*
cannot be used at the same time. In fact, they can, however, the result is slightly different from the expected one.I would expect the space to split equally around the divider.
So my idea is that instead of dividing the gap between items like this:
use this, e.g.,:
As a result, the divider (
border
) between the items will be divided evenly, and the example below will behave as expected.Note:
Instead of using both (
margin
andpadding
), this can be achieved using pseudo-elements.Beta Was this translation helpful? Give feedback.
All reactions