hiding text using “text-indent”

2019-03-25 04:33发布

I'm trying to hide some text inside an <li> element using CSS by setting text-indent: -999px;.
For some reason this doesn't work when I set the direction of the document to "rtl" (right to left - my site is in Hebrew).
When direction is "rtl" the text still shows...
Anyone knows why, and a way around this?

10条回答
Luminary・发光体
2楼-- · 2019-03-25 05:04

I found the best way is to make the text a transparent color:

color: rgba(0,0,0,0);

Note: This bug still exists in firefox 12 (text-indent value is ignored on rtl)

查看更多
叼着烟拽天下
3楼-- · 2019-03-25 05:09

My problem was with text-align. In case you modify align mode of the element or parent element(s) wrapping it to left, you must give a negative index for text-indent. Otherwise you must give a positive value.

.case1{text-indent:-999px;text-align:left;overflow:hidden;display:block}

Otherwise

.case2{text-indent:999px;text-align:right;overflow:hidden;display:block}
查看更多
Animai°情兽
4楼-- · 2019-03-25 05:13

I prefer this solution:

.hide_text { text-indent: 100%; white-space: nowrap; overflow: hidden; }
查看更多
趁早两清
5楼-- · 2019-03-25 05:14

Along with text-indent: -9999px try using display: block;. It solved for me.

Additionally, if you need the li elements to float horizontally (e.g. a horizontal menu), use float: left;.

查看更多
我只想做你的唯一
6楼-- · 2019-03-25 05:14

What about setting direction:ltr on the elements you're trying to give negative text-indent?

Demo: jsfiddle.net/Marcel/aJBnN/1/

查看更多
Ridiculous、
7楼-- · 2019-03-25 05:20

text-align: right; works for me

查看更多
登录 后发表回答