direction: rtl and text-align: left causes symbols to shift around

So I know this is definitely an edge case but I think my issue is very valid. I need to show a bunch of file paths in a list where the beginning of the path isn't so important so I want the overflow ellipsis to be at the beginning to show the file name in full I tried to do this with setting direction: rtl and text-align: left and it works great However, for file paths start start with _, that underscore gets reordered and shifted to the very right. Is there a way I can keep the string intact? If there's a better way to solve this issue without needing to get the client rect in javascript and modifying the string then that's also great! 🙏 https://codepen.io/stefanh-at/pen/GgpjpBp
No description
20 Replies
ἔρως
ἔρως5w ago
https://developer.mozilla.org/en-US/docs/Web/CSS/direction <-- have you read the warning and checked if it works?
StefanH
StefanHOP5w ago
Yeah same behavior :/ I also tried <pre> and all values of unicode-bidi
ἔρως
ἔρως5w ago
have you tried to insert a direction character before and after the _?
StefanH
StefanHOP5w ago
Hmm some kind of 0 width character? Which do you have in mind? Why did i have to prefix all my file paths with _...
ἔρως
ἔρως5w ago
🤣 it's an utf8 character that sets the direction of the text also, have you tried to wrap the _ in a span with a direction?
StefanH
StefanHOP5w ago
I'll try a few more things tomorrow cause it's time to have a zzz but thanks for the suggestion! That might just work
ἔρως
ἔρως5w ago
lets hope it does
StefanH
StefanHOP5w ago
If it doesnt i'll have to just cut off sharp :/
ἔρως
ἔρως5w ago
or replace with a friendly character
StefanH
StefanHOP5w ago
Okay i found it! Random 10 year old stack overflow comment to the rescue! Adding &lrm; to the beginning of the string works So your hunch was right!
ἔρως
ἔρως5w ago
it's the left to right direction mark character? and you just added it to the beginning and everything works?
StefanH
StefanHOP5w ago
Yup
ἔρως
ἔρως5w ago
i thought you would have to add it to the _ but hey, it's good to know this works
StefanH
StefanHOP5w ago
ἔρως
ἔρως5w ago
is it updated in the codepen?
StefanH
StefanHOP5w ago
Nope sry
ἔρως
ἔρως5w ago
can you update it then?
StefanH
StefanHOP5w ago
Yeah i updated it now
ἔρως
ἔρως5w ago
yeah, i expected the character to be needed, but not there it's good that it is at the beginning of the text also, use the dir attribute instead, as per mdn's recommendations
ἔρως
ἔρως5w ago
you then can do something like this
No description

Did you find this page helpful?