最初に「$」記号を含むテキスト入力フィールドを作成し、フィールドにどのような編集が行われても、記号が持続するようにしたいと考えています。
数字だけを入力できるようにすればよかったのですが、それは単なる手の込んだ追加です。
最初に「$」記号を含むテキスト入力フィールドを作成し、フィールドにどのような編集が行われても、記号が持続するようにしたいと考えています。
数字だけを入力できるようにすればよかったのですが、それは単なる手の込んだ追加です。
境界線のない入力フィールドの周囲に境界線のあるスパンを使用して、固定のプレフィックスまたはサフィックスを持つ入力フィールドをシミュレートすることを検討してください。基本的なキックオフの例を次に示します。
.currencyinput {
border: 1px inset #ccc;
}
.currencyinput input {
border: 0;
}
<span class="currencyinput">$<input type="text" name="currency"></span>
親.input-icon
div を使用します。必要に応じて追加し.input-icon-right
ます。
<div class="input-icon">
<input type="text">
<i>$</i>
</div>
<div class="input-icon input-icon-right">
<input type="text">
<i>€</i>
</div>
transform
アイコンをとに垂直に揃え、top
に設定pointer-events
しnone
て、クリックが入力にフォーカスするようにします。padding
必要に応じてとを調整width
します。
.input-icon {
position: relative;
}
.input-icon > i {
position: absolute;
display: block;
transform: translate(0, -50%);
top: 50%;
pointer-events: none;
width: 25px;
text-align: center;
font-style: normal;
}
.input-icon > input {
padding-left: 25px;
padding-right: 0;
}
.input-icon-right > i {
right: 0;
}
.input-icon-right > input {
padding-left: 0;
padding-right: 25px;
text-align: right;
}
受け入れられた回答とは異なり、これにより、エラーが発生した場合の赤い境界線など、入力検証の強調表示が保持されます。
入力フィールドをスパンにラップできますposition:relative;
。:before
content:"€"
次に、通貨記号を追加して にし
ますposition:absolute
。ワーキングJSFiddle
HTML
<span class="input-symbol-euro">
<input type="text" />
</span>
CSS
.input-symbol-euro {
position: relative;
}
.input-symbol-euro input {
padding-left:18px;
}
.input-symbol-euro:before {
position: absolute;
top: 0;
content:"€";
left: 5px;
}
更新 テキストボックスの左側または右側にユーロ記号を配置する場合。ワーキングJSFiddle
HTML
<span class="input-euro left">
<input type="text" />
</span>
<span class="input-euro right">
<input type="text" />
</span>
CSS
.input-euro {
position: relative;
}
.input-euro.left input {
padding-left:18px;
}
.input-euro.right input {
padding-right:18px;
text-align:end;
}
.input-euro:before {
position: absolute;
top: 0;
content:"€";
}
.input-euro.left:before {
left: 5px;
}
.input-euro.right:before {
right: 5px;
}
'$' をテキスト入力フィールドの中ではなく前に置きます。送信後に「$」を解析する必要がないため、数値データの検証が非常に簡単になります。
JQuery.validate () (またはその他) を使用して、通貨を処理するクライアント側の検証規則を追加できます。これにより、入力フィールド内に「$」を含めることができます。ただし、セキュリティのためにサーバー側の検証を行う必要があるため、「$」を削除する必要があります。
$<input name="currency">
私が好むもう1つの解決策は、通貨記号の画像に追加の入力要素を使用することです。検索テキストフィールド内で虫眼鏡の画像を使用した例を次に示します。
html:
<input type="image" alt="Subscribe" src="/graphics/icons/search-button.png">
<input type="text" placeholder="Search" name="query">
css:
#search input[type="image"] {
background-color: transparent;
border: 0 none;
margin-top: 10px;
vertical-align: middle;
margin: 5px 0 0 5px;
position: absolute;
}
これにより、左側のサイドバーに次の入力が表示されます。
ブートストラップのためにその作品
<span class="form-control">$ <input type="text"/></span>
入力フィールドで class="form-control" を使用しないでください。
.currencyinput {
border: 1px inset #ccc;
padding-bottom: 1px;//FOR IE & Chrome
}
.currencyinput input {
border: 0;
}
<span class="currencyinput">$<input type="text" name="currency"></span>