简体   繁体   English

以货币符号结尾的 HTML5 数字输入字段

[英]HTML5 number input field with currency symbol in the end of it

I would like to have a html5 number input field containing the EUR sign, and no matter what editing occurs to the field, for the sign to be persistent.我想要一个包含 EUR 符号的 html5 数字输入字段,无论对该字段进行什么编辑,该符号都是持久的。 I tried to do that, but the EUR sign won't appear inside the field, I want to move this sign at the end of the input but for some reason, I can't do it.我试图这样做,但欧元符号不会出现在字段内,我想在输入的末尾移动这个符号,但由于某种原因,我不能这样做。 I don't want to remove class form-control.我不想删除类表单控件。 Any help?有什么帮助吗?

My snippet:我的片段:

 .input-symbol-euro { position: relative; } .input-symbol-euro input { padding-right: 15px; } .input-symbol-euro:after { position: absolute; top: 0; content: "€"; right: 0px; } .form-control { display: block; width: 50%; height: 34px; padding: 6px 12px; font-size: 14px; line-height: 1.42857143; color: #555; background-color: #fff; background-image: none; border: 1px solid #ccc; border-radius: 4px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s; -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; } .form-control:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6); } .form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control { cursor: not-allowed; background-color: #eee; opacity: 1; }
 <span class="input-symbol-euro"> <input type="number" value="0" min="0" step="1" class="form-control" /> </span>

You need to give the <span> some sort of useful display property so that it will wrap the <input> .您需要为<span>某种有用的display属性,以便它可以包装<input> By default this element has a value of inline .默认情况下,此元素的值为inline In the example below I've used inline-block , but block would do just fine.在下面的示例中,我使用了inline-block ,但是block就可以了。

See updated fiddle .请参阅更新的小提琴

 .input-symbol-euro { position: relative; display: inline-block; width: 50%; } .input-symbol-euro input { padding-right: 15px; width: 100%; } .input-symbol-euro:after { position: absolute; top: 50%; transform: translateY(-50%); margin: auto; content: "€"; right: 20px; } .form-control { display: block; height: 34px; padding: 6px 12px; font-size: 14px; line-height: 1.42857143; color: #555; background-color: #fff; background-image: none; border: 1px solid #ccc; border-radius: 4px; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075); -webkit-transition: border-color ease-in-out .15s, -webkit-box-shadow ease-in-out .15s; -o-transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; transition: border-color ease-in-out .15s, box-shadow ease-in-out .15s; } .form-control:focus { border-color: #66afe9; outline: 0; -webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6); box-shadow: inset 0 1px 1px rgba(0, 0, 0, .075), 0 0 8px rgba(102, 175, 233, .6); } .form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control { cursor: not-allowed; background-color: #eee; opacity: 1; }
 <span class="input-symbol-euro"> <input type="number" value="0" min="0" step="1" class="form-control" /> </span>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM