如何使用 CSS 将数字输入右对齐和文本输入左对齐?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3792109/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:50:49  来源:igfitidea点击:

How can I align numeric input right and text input left with CSS?

css

提问by Mawg says reinstate Monica

If I have two <input type="text" ...and I know that one should aceept text and the other a numeric value (and will check that in PHP when validating the form), can I align the contents of the text box left & the contents of the numeric box right using CSS?

如果我有两个<input type="text" ...并且我知道一个应该接受文本,另一个应该接受一个数值(并且在验证表单时会在 PHP 中检查它),我可以使用左对齐文本框的内容和右对齐数字框的内容吗? CSS?

采纳答案by ihappyk

The latest update for this can be done like below

对此的最新更新可以如下完成

  1. <input type="number" />for Numbers Type of text fields.
  2. <input type="text"/>for text type of input fields
  1. <input type="number" />用于数字类型的文本字段。
  2. <input type="text"/>用于输入字段的文本类型

Then you can make use of CSS.

然后你可以使用CSS。

input[type=number] {
  text-align:right;
}


input[type=text] {
  text-align:left;
}

This would help you a lot if you add more fields to your webpage.

如果您向网页添加更多字段,这将对您有很大帮助。

回答by Rob

<style type="text/css">
     .right { text-align: right; } </style>

<input type="text" /> <input type="text" class="right"/>

回答by user3045873

Just correction regarding CSS external file:

关于 CSS 外部文件的更正:

input.right{
    text-align: right;
}