12

I have an HTML tag with a short maxlength but a long value attribute. I'd like the displayed text to show the end (right side) of the text, rather than the start (left side).

<input maxlength=10 value="A really really really long entry goes in here"/>

currently shows:

"A really r"

instead I'd like it to show:

"es in here"

Cheers,

Ian

Sotiris
  • 38,986
  • 11
  • 53
  • 85
IanSR
  • 1,415
  • 3
  • 16
  • 18

3 Answers3

18

Do you want the visible area to start from the right? you can use css and the following rule input {direction:rtl;}

rtl means from right to left

example: http://jsbin.com/ilejo4

PS: the value of maxlength in your html must be wrapped with quotes, also you have to set the type of the input

Sotiris
  • 38,986
  • 11
  • 53
  • 85
  • 1
    Strangely, if the value starts with a slash `/` (like a filename) - that slash is pushed to the "end" which is now the right side of the string. Use this with care. – mr rogers Aug 18 '14 at 18:42
  • -1 "rtl" does not keep the order when there is punctuation and numbers! Be careful. See https://stackoverflow.com/q/53947553/22470 – powtac Jun 24 '19 at 10:13
0

Add style="text-align:right" to the input tag.

powtac
  • 40,542
  • 28
  • 115
  • 170
0

If you only want to display information, what you can do is place a span inside a div, in the div write overflow:hidden, display flex, justify-content: flex-end;

.contenedor{
  width: 100px;
  background-color: black;
  color: white;
  border-radius: 5px;
  display: flex;
  justify-content: flex-end;
  overflow:hidden;
  padding: 5px;
}
<div class="contenedor"><span>12345555555566final</span></div>