Tailwindcss: space-x-* does not work in RTL direction

Created on 13 Jul 2020  路  10Comments  路  Source: tailwindlabs/tailwindcss

All 10 comments

I fix this by doing this:

[dir="rtl"] {
    .space-x-4 > :not(template) ~ :not(template) {
        --space-x-reverse: 0 !important;
        margin-left: calc(1rem * var(--space-x-reverse)) !important;
        margin-right: calc(1rem * calc(1 - var(--space-x-reverse))) !important;
    }
}

But I would like to know, there is a way to make space without depends on direction?

Just use tailwindcss-dir and add space variant to tailwind.config.js

variants: {
  space: ['responsive', 'direction'],
},

@hsul4n Not working! still, the margin in the last item and none in the first one 馃槦

@hsul4n Not working! still, the margin in the last item and none in the first one

I fixed this problem by this code:

[dir="rtl"] {
    .space-x-4 > :not(template) ~ :not(template) {
        --space-x-reverse: 0 !important;
        margin-left: calc(1rem * var(--space-x-reverse)) !important;
        margin-right: calc(1rem * calc(1 - var(--space-x-reverse))) !important;
    }
}

@chalist good trick.
But I think the following way is much easier

variants: {
  space: ['responsive', 'direction'],
},

then you can do something like
space-x-6 rtl:space-x-reverse 鉁屸湆

Saves much time, isn't it?

yes sure. But you wrote not working. This is because I write that comment :D

yes sure. But you wrote not working. This is because I write that comment :D

Thank you 馃憤

Sorry @mohamed-ibrahem, I always add style utilities to variants property but looks like this doesn't work with space utility 馃槄, so I would suggest using reverse with RTL direction.

Here's example

<div class="flex space-x-4 rtl:space-x-reverse">
  <div>1</div>
  <div>2</div>
  <div>3</div>
</div>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jvanbaarsen picture jvanbaarsen  路  3Comments

rgaufman picture rgaufman  路  3Comments

lamberttraccard picture lamberttraccard  路  3Comments

ouun picture ouun  路  3Comments

divdax picture divdax  路  3Comments