如何在HTML文本框中右对齐文本? [英] How do you right-justify text in an HTML textbox?

查看:1622
本文介绍了如何在HTML文本框中右对齐文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在列中显示许多数值。这些值需要容易编辑,所以我不能只是在表中显示它们。我使用文本框来显示它们。有没有办法让我右键调整文本框中显示的文本?

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.

推荐答案

当用户输入数据时,用户可以开始显示他们从右边输入的数据。您尝试设置样式:

Did you try setting the style:

input {
    text-align:right;
}

刚刚测试,这很好(至少在FF3):

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>

你可能想在这些输入上引入一个类,并使用该类作为选择器。我会避开rightAligned或类似的东西。在类名中,您想要描述元素的函数是什么,而不是如何呈现它。 数字可能是好的,或者可能是文本框的业务功能。

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.

这篇关于如何在HTML文本框中右对齐文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆