简体   繁体   English

方向问题:rtl CSS 属性

[英]Issue with the direction: rtl CSS property

I have an HTML element and I need to display a folder / file path within it that can sometimes be very long.我有一个 HTML 元素,我需要在其中显示一个有时可能很长的文件夹/文件路径。

I also want to keep it on a single line (within a width constrained container) so I obviously need to add some ellipsis to it.我还想将它保留在一行上(在宽度受限的容器内),所以我显然需要向它添加一些省略号。

Another requirement is that I should always see the deepest folder nodes in that path (this is helpful when the path is long, because the latest nodes is what you're actually interested in).另一个要求是我应该始终看到该路径中最深的文件夹节点(当路径很长时这很有用,因为最新的节点是您真正感兴趣的)。

The problem is, this is quite hard to achieve if I'm to use the direction: rtl;问题是,如果我要使用direction: rtl; ,这很难实现direction: rtl; CSS property, because it will move other characters around, such as / or even paranthesis. CSS 属性,因为它会移动其他字符,例如/甚至括号。

Take a look at this example: https://jsfiddle.net/r897duu9/1/ (as you can see, I didn't use the text-overflow: ellipsis property as this will, for some reason, override the direction: rtl property).看看这个例子: https : //jsfiddle.net/r897duu9/1/ (如你所见,我没有使用text-overflow: ellipsis属性,因为出于某种原因,这会覆盖direction: rtl财产)。

What I've tried so far and it works on modern browsers is adding the unicode-bidi: plaintext;到目前为止我已经尝试过并且它在现代浏览器上工作的是添加unicode-bidi: plaintext; CSS property, but according to the Mozilla Developer Network this is experimental and not well supported across not-so-modern cough IE browsers. CSS 属性,但根据Mozilla Developer Network 的说法,这是实验性的,在不太现代的咳嗽IE 浏览器中没有得到很好的支持。 The fiddle for this is here: https://jsfiddle.net/n05b3jgt/1/ .小提琴在这里: https : //jsfiddle.net/n05b3jgt/1/

Does anyone know a better way to achieve this, that would be well supported across a wide range of browsers?有没有人知道实现这一目标的更好方法,这将在各种浏览器中得到很好的支持?

I looked at the other solutions but I think this is simpler and more effective.我查看了其他解决方案,但我认为这更简单、更有效。

 .title-wrapper { max-width: 200px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl; } .title { unicode-bidi: plaintext; }
 <div class="title-wrapper"> <span class="title">asdasd/qweqwe/xcvxcv/rtyrty/dfgdfgdfgdfgdfgd</span> </div>

You may use direction on container then reset it on text.您可以在容器上使用方向,然后在文本上重置它。

 .container { width: 340px; background:gray; direction:rtl; overflow:hidden; text-align:left; position:relative; } .container:before{ position: absolute; content: '...'; background: white; left: 0; } .text-with-path { display:inline-block; white-space:nowrap; text-indent:1em; direction:ltr;
 <div class="container"> <div class="text-with-path"> /Root/someFolder/SomeAnotherFolder/AgainSomeotherFolder/MyPictures/MyDocs (recent) </div> </div> <hr/> <div class="container"> <div class="text-with-path"> /MyPictures/MyDocs (recent) </div> </div>

or just use float if your main issue is which way text overflows或者如果您的主要问题是文本溢出的方式,则使用 float

 .container { width: 340px; background:gray; overflow:hidden; position:relative; } .container:before{ position: absolute; background:gray; content: '...'; left: 0; } .text-with-path { float:right; margin-left:-999px; }
 <div class="container"> <div class="text-with-path"> /Root/someFolder/SomeAnotherFolder/AgainSomeotherFolder/MyPictures/MyDocs (recent) </div> </div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM