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
ἔρως
ἔρως4mo ago
https://developer.mozilla.org/en-US/docs/Web/CSS/direction <-- have you read the warning and checked if it works?
StefanH
StefanHOP4mo ago
Yeah same behavior :/ I also tried <pre> and all values of unicode-bidi
ἔρως
ἔρως4mo ago
have you tried to insert a direction character before and after the _?
StefanH
StefanHOP4mo 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 _...
ἔρως
ἔρως4mo 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
StefanHOP4mo 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
ἔρως
ἔρως4mo ago
lets hope it does
StefanH
StefanHOP4mo ago
If it doesnt i'll have to just cut off sharp :/
ἔρως
ἔρως4mo ago
or replace with a friendly character
StefanH
StefanHOP4mo 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!
ἔρως
ἔρως4mo ago
it's the left to right direction mark character? and you just added it to the beginning and everything works?
StefanH
StefanHOP4mo ago
Yup
ἔρως
ἔρως4mo ago
i thought you would have to add it to the _ but hey, it's good to know this works
StefanH
StefanHOP4mo ago
ἔρως
ἔρως4mo ago
is it updated in the codepen?
StefanH
StefanHOP4mo ago
Nope sry
ἔρως
ἔρως4mo ago
can you update it then?
StefanH
StefanHOP4mo ago
Yeah i updated it now
ἔρως
ἔρως4mo 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
ἔρως
ἔρως4mo ago
you then can do something like this
No description

Did you find this page helpful?