bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

RTL alignment problems: navbar-nav and navbar-brand

Open ibleaman opened this issue 1 year ago • 3 comments

I came across some alignment problems when adding a navbar to a multilingual website, where some of the pages have dir="rtl" specified in the root. Here are minimal examples:

Bootstrap 5.3.3 defines .ms-auto (and other .ms- values) based on margin-left. Also, .navbar-brand is defined with a margin-right property.

ibleaman avatar Jul 26 '24 18:07 ibleaman

Hi @ibleaman, from my understanding of what is explained in Bootstrap's documentation, if you want to enable RTL in Bootstrap-powered pages you need to include the RTL version of the CSS.
I have tried replacing the stylesheet link in the fiddle you shared with the RTL version and the result seems to be the same as the fixed version of the fiddle.
Here's the link tag: <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.rtl.min.css" integrity="sha384-dpuaG1suU0eT09tx5plTaGMLBsfDLzUCCUXOY2j/LSvXYuG6Bqs43ALlhIqAJVRb" crossorigin="anonymous">
Hope I was of any help!

TommasoAllegretti avatar Jul 26 '24 19:07 TommasoAllegretti

@TommasoAllegretti Thank you for your quick response! Yes, I did overlook that step on the RTL documentation page.

Using the RTL version of Bootstrap fixes the problem in my jsfiddle link 2. However, it creates the same alignment problem if you use it in link 1, because .ms-auto is now defined as:

.ms-auto {
  margin-right: auto !important;
}

So: Is there no way to use a single Bootstrap 5 CSS file on a multilingual website, whether the original version or the RTL version, so that it works across all pages regardless of their direction? The documentation on spacing suggests that this is exactly what .ms- is supposed to accomplish:

s - (start) for classes that set margin-left or padding-left in LTR, margin-right or padding-right in RTL

The RTL documentation page also suggests that start/end are what's used in the CSS, not left/right. But both the original and the RTL versions of Bootstrap 5 still use left and right here.

I thought this was supposed to be an improvement over Bootstrap 4, which used ml instead of ms.

ibleaman avatar Jul 26 '24 20:07 ibleaman

I am not sure what the evolution of Bootstrap regarding this feature is, but according to "LTR and RTL at the same time", the solution to your problem should be RTLCSS String Maps. I am not aware of your project's details but I hope that can be helpful in solving your issue.

TommasoAllegretti avatar Jul 27 '24 17:07 TommasoAllegretti

I'm closing this issue, as importing the RTL version of Bootstrap 5 is good enough for my use case.

Thanks again @TommasoAllegretti !

ibleaman avatar Jul 30 '24 17:07 ibleaman