Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you right-justify text in an HTML textbox?

Tags:

html

css

I have a need to display many numerical values in columns. These values need to be easily editable so I cannot just display them in a table. I am using textboxes to display them. Is there a way for me to right-justify the text displayed in a textbox? It would also be nice if when the user is entering data for it to start displaying what they type from the right.

like image 554
Haabda Avatar asked Oct 03 '08 14:10

Haabda


People also ask

How do I align text right in a text box?

Align text verticallyRight-click the text box for which you want to set vertical alignment. On the shortcut menu, click Format Text Box. In the Format Text Box dialog box, click the Text Box tab. In the Vertical alignment box, select Top, Middle, or Bottom.


1 Answers

Did you try setting the style:

input {     text-align:right; } 

Just tested, this works fine (in FF3 at least):

<html>     <head>         <title>Blah</title>         <style type="text/css">         input { text-align:right; }         </style>     </head>     <body>         <input type="text" value="2">     </body> </html> 

You'll probably want to throw a class on these inputs, and use that class as the selector. I would shy away from "rightAligned" or something like that. In a class name, you want to describe what the element's function is, not how it should be rendered. "numeric" might be good, or perhaps the business function of the text boxes.

like image 152
Chris Marasti-Georg Avatar answered Sep 28 '22 04:09

Chris Marasti-Georg