javascript - How to achieve the last letter without letter-spacing in a text input field? - Stack Overflow

Dear munity members,I have a small problem, which involves a text input field with letter-spacing. For

Dear munity members,

I have a small problem, which involves a text input field with letter-spacing. For example the following code:

<input type="text" style="letter-spacing:1em; text-align:center;" maxlength="6" id="code" name="code" />

This would cause the text not center properly due to the last letter-spacing at the last letter. Are there alternative methods in which I can achieve spacing, but also text centering capabilities? All solutions are appreciated (incl. javascript and JQuery).

(The user enters a string of 6 characters long, with no spaces.)

Thanks for the response!

PS: I do not think that I forgot any relevant code, because the em can also be replace with 10px. I have a screenshot here: .png

Dear munity members,

I have a small problem, which involves a text input field with letter-spacing. For example the following code:

<input type="text" style="letter-spacing:1em; text-align:center;" maxlength="6" id="code" name="code" />

This would cause the text not center properly due to the last letter-spacing at the last letter. Are there alternative methods in which I can achieve spacing, but also text centering capabilities? All solutions are appreciated (incl. javascript and JQuery).

(The user enters a string of 6 characters long, with no spaces.)

Thanks for the response!

PS: I do not think that I forgot any relevant code, because the em can also be replace with 10px. I have a screenshot here: http://www2.picturepush./photo/a/7889005/640/7889005.png

Share Improve this question edited Mar 26, 2012 at 17:16 Snowflake asked Mar 26, 2012 at 17:09 SnowflakeSnowflake 3,0913 gold badges28 silver badges45 bronze badges 2
  • not nearly enough information here to understand the issue. – DA. Commented Mar 26, 2012 at 17:10
  • It looks pretty well centred in Chromium/Ubuntu... – David Thomas Commented Mar 26, 2012 at 17:16
Add a ment  | 

1 Answer 1

Reset to default 8

What about adding a padding-left of 1em?

<input type="text" style="letter-spacing:1em; text-align:center; padding-left: 1em" maxlength="6" id="code" name="code" />

Here is an example, with the maxlength removed and a width added, so you can see that it is centered properly:

http://jsfiddle/Jgm42/

Note: This looks to only be an issue with some browsers. IE, shockingly, seems to correctly leave off the extra spacing unless there is an adjacent character. You might have to do some browser-specific code.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745207708a4616671.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信