2014-09-24 109 views
6

我用下面的代码来对齐输入文本字段的内容:文本对齐输入标签

Path <input type="text" value="http://stackoverflow.com/questions" style="text-align: right;"> 

问题:
这不长文本的情况下工作。

因为我正在显示文件夹路径,所以我有兴趣显示最后一个文件夹。
我经历了许多与文本对齐有关的帖子帖子,但他们都建议使用“text-align:right”。

+0

可以拨弄它,请。 – Tushar 2014-09-24 09:41:20

回答

4

您可以将文本输入的direction更改为rtl,以便它显示路径的最后部分。

如需进一步信息,请参阅我的回答类似的问题在这里:

input[type="text"] { 
 
    /* text-align: right; */ 
 
    direction: rtl; 
 
}
Path <input type="text" value="https://stackoverflow.com/questions">

+0

@downvoter,小心点评?我不这么认为。 OP在这个问题中只标记了'html'和'css',唯一可能的CSS解决方案被降低了。 – 2014-09-24 17:10:18

0

试着做这样的,这个属性仅添加此标签dir="rtl"

<input type="text" value="http://stackoverflow.com/questions" dir="rtl"> 
+2

为什么选择downvoted?它的工作。这里只需要“文本对齐” – Manwal 2014-09-24 09:45:31

+0

http://www.w3schools.com/tags/att_global_dir.asp – Shamanth 2014-09-24 10:00:35

1

rtl黑客真好,但是如果你真的想改变它的价值就会很难。如果你不想这样做,为什么首先要把它做成input

所以用户也可在输入端使用一段JavaScript代码设置光标:

// Wrap it in a function, if you like. 
 
function selectEnd(input) { 
 
    var pos = input.value.length; 
 
    input.setSelectionRange(pos, pos); 
 
    input.blur(); // Switch from not focus.. 
 
    input.focus(); // .. to focus, to force the cursor into view. 
 
} 
 

 
// Call it for your input. 
 
selectEnd(document.getElementById('path'));
Path <input id="path" type="text" value="http://stackoverflow.com/questions" style="text-align: right;">