Bootstrap5 フォームのフローティングラベル

デフォルトでは、ラベルの内容は通常 input 入力ボックスの上に表示されます:

フローティングラベルを使用すると、ラベルを input 入力ボックス内に挿入でき、input 入力ボックスをクリックするとラベルが上にフロートします。

Bootstrap 例

<div class="form-floating mb-3 mt-3"> <input type="text" class="form-control" id="email" placeholder="Enter email" name="email"> <label for="email">Email</label> </div> <div class="form-floating mt-3 mb-3"> <input type="text" class="form-control" id="pwd" placeholder="Enter password" name="pswd"> <label for="pwd">Password</label> </div>

試してみる »

注意事項:<label> 要素は <input> 要素の後に置く必要があり、各 <input> 要素には placeholder 属性が必要です。

テキストボックス

テキストエリア (textarea) にもフローティング効果を適用できます:

Bootstrap 例

<div class="form-floating"> <textarea class="form-control" id="comment" name="text" placeholder="Comment goes here"></textarea> <label for="comment">Comments</label> </div>

試してみる »

セレクトボックス

セレクトメニューにはフローティングラベルを使用できます。ラベルは常にセレクトメニューの左上に表示され、クリックによるフローティング効果はありません:

Bootstrap 例

<div class="form-floating"> <select class="form-select" id="sel1" name="sellist"> <option>1</option> <option>2</option> <option>3</option> <option>4</option> </select> <label for="sel1" class="form-label">Select list (select one):</label> </div>

試してみる »
その他の拡張