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

时间:2022-08-22 12:15:55

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?

如果我有两个

3 个解决方案

#1


17  

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

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

#2


3  

The latest update for this can be done like below

最新的更新可以像下面这样完成

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

  3. <input type="text"/> for text type of input fields
  4. 用于输入字段的文本类型

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.

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

#3


0  

Just correction regarding CSS external file:

关于CSS外部文件的纠正:

input.right{
    text-align: right;
}

#1


17  

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

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

#2


3  

The latest update for this can be done like below

最新的更新可以像下面这样完成

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

  3. <input type="text"/> for text type of input fields
  4. 用于输入字段的文本类型

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.

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

#3


0  

Just correction regarding CSS external file:

关于CSS外部文件的纠正:

input.right{
    text-align: right;
}