上記のようなフォームを作成したいと思います。テキストボックスにプレースホルダを追加できます。しかし、ユーザーがキープレースホルダーを押したとき。テキストボックス内のキーを押すと、テキストボックスの上にプレースホルダを表示する必要があります。テキストでプレースホルダを作成する方法
1
A
答えて
1
は、一つ以上のa-z
を追いました例えば、"Billy Joe"
,"Norma Jean"
,"Sarah Jane"
のように、入力の終わり、または2つのファーストネームを扱うための入力の終わりで大文字小文字を区別しない文字。 <label>
要素は<input>
要素に隣接する。 css
:invalid
,:valid
,:before
; :after
。
input
が:invalid
がnone
にred
からborder
、outline
に設定されています。隣接して設定されるlabel
要素:before
content
~、label
:after
content
~!
; :valid:focus
であなたは何を試してみました?UTF-8
"CHECK MARK"
✓
@charset "UTF-8";
#input {
height: 3.14em;
left: 0px;
outline: none;
padding: 6px;
margin: 4px;
width: 150px;
}
#input:valid {
border: 1px solid green;
box-shadow: .015em .015em .015em green;
}
#input:invalid {
border: 1px solid red;
box-shadow: .015em .015em .015em red;
}
#input:invalid + [for="input"]:before {
content: "das";
}
#input + [for="input"]:after {
font-weight: bold;
left: 160px;
top: 12px;
position: absolute;
}
#input:invalid + [for="input"]:after {
content: "!";
color: red;
}
#input:valid + [for="input"]:after {
content: "\2713";
color: green;
}
#input:valid + [for="input"]:before {
content: "First Name";
color: #ccc;
}
label[for="input"]:before {
position: absolute;
left: 12px;
padding: 6px;
}
<meta charset="UTF-8" />
<input id="input" type="text" pattern="^[a-zA-Z]+(?:\s[a-zA-Z]+$|$)" required autofocus/>
<label for="input"></label>
1
#lbl{
color:green;
}
#in{
border:none
}
#in,#in_container,#lbl{
background:white
}
#in_container{
display:inline-block;
border:solid 1px black;
}
<div id="in_container">
<span id="lbl">First Name</span>
<br>
<input type='text' id="in">
</div>
1
いくつかのCSSマジック:
.input-group * {
left: 0;
position: absolute;
font-family: sans-serif;
}
.input-group input {
height: 30px;
font-size: 20px;
padding-top: 12px;
}
.input-group label {
padding-left: 3px;
padding-top: 2px;
opacity: .5;
}
<div class="input-group">
<input id="first-name" type="text">
<label for="first-name">First Name</label>
</div>
あなたはあなたのために働いて解を得るまでは基本的には、ちょうどサイズで遊びます。私は、それぞれの "入力ボックス"セクションをグループ化し、テキスト入力にスーパーインポーズされたラベルで構成されています。ここで
1
#container {
position: relative;
}
#container * {
font-size: 20px;
}
#my-input {
height: 30px;
}
#lbl-my-input {
line-height: 1.5;
position: absolute;
color: #bebebe
}
#my-input:focus {
padding-top: 40px;
}
<div id="container">
<label id="lbl-my-input" for="my-input">First</label>
<input id="my-input" type="text">
</div>
私の考えです:
- 私はdivの
- にラベルと入力を入れて、私はdivの位置を作り、ラベル位置絶対=>ラベルがします重複した入力
私は入力のためのCSSを使用します:フォーカス。フォーカスが起こると、入力のパディングトップが拡張されます。
残りは
それを美しくするために(選択)右行の高さ、フォントサイズ、およびパディングをスタイリングされ
0
私は、このためのソリューションを持っています。あなたがスペース文字に続いて、入力の先頭に1つ以上のa-z
文字の大文字小文字を区別しません一致するhtml
required
、autofocus
とRegExp
^[a-zA-Z]+(?:\s[a-zA-Z]+$|$)
とpattern
属性を使用することができます
<label style="visibility: hidden;" id="label">User Name</label>
<input id="textField" type="text" placeholder="User Name" onfocus="showLabel()" onblur="hideLabel()"></input>
<script>
function showLabel() {
var label = document.getElementById("label");
var textField = document.getElementById("textField");
textField.placeholder="";
label.style.visibility = "inherit";
}
function hideLabel() {
var label = document.getElementById("label");
var textField = document.getElementById("textField");
textField.placeholder="User Name";
if (!textField.value) {
label.style.visibility = "hidden";
}
}
</script>
関連する問題
- 1. テキストでブートストラップスライダーを作成する方法
- 2. プレースホルダの目的のカスタムUITextViewを作成する方法c。?
- 3. テキストのプレースホルダを取得する方法は?
- 4. GWTテキスト入力フィールドにプレースホルダを追加する方法
- 5. django-cms 3.0.0で特定のプラグインのプレースホルダを作成する方法
- 6. デフォルトのテキスト(プレースホルダ)
- 7. HTML5の数値入力でプレースホルダのテキストを表示する方法
- 8. PHPで太字のテキストを作成する方法.xlsファイル
- 9. rでテキストIDのシーケンスを作成する方法は?
- 10. IBで斜めのテキスト(UILabel)を作成する方法は?
- 11. FastReport - SQLテキストでダイアログフォームを作成する方法
- 12. IE7のボタンでテキスト入力行を作成する方法は?
- 13. androidで複数行の編集テキストを作成する方法
- 14. 複数のテキスト行をアンドロイドで作成する方法は?
- 15. デフォルトのレイアウトでテキスト領域を作成する方法
- 16. TextViewでテキストの枠線を作成する方法は?
- 17. アイコンとテキストでタブを作成する方法TabLayout android
- 18. 複数のテキストを含むListViewを作成する方法
- 19. Itextsharpのテキスト部分にboldfontを作成する方法
- 20. データファイルからPythonにテキストを再作成する方法
- 21. Silverlight-選択可能なテキストのコンテンツコントローラを作成する方法
- 22. Appelaratorのテキストの影/ステッカー効果を作成する方法
- 23. JavaFX:クリック可能なテキストを作成する方法
- 24. 属性付きテキストの配列を作成する方法
- 25. テキスト入力を作成する最良の方法Redux
- 26. Androidでテキストを共有するためのアプリピッカーを作成する方法は?
- 27. Visual Studioエディタでテキストの色を変更するアドインを作成する方法?
- 28. テキストでスライダを作る方法
- 29. 訓練するテキストを含む文法を作成する方法
- 30. mySQLからデータを取得する 'select'ボックスのプレースホルダを作成する方法は?
に
:after
label
、"First Name"
からlabel
:before
content
を設定動作していないコードの例を表示する。 StackOverflowは無料のコーディングサービスではありません。 – rockerest