Menu
×
   ❮   
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS R TYPESCRIPT ANGULAR GIT POSTGRESQL MONGODB ASP AI GO KOTLIN SASS VUE DSA GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE
     ❯   

Bootstrap 5 表单浮动标签


浮动标签 / 动画标签

默认情况下,使用标签时,它们通常会显示在输入字段的顶部

使用浮动标签,您可以将标签插入输入字段中,并在单击输入字段时使其浮动/动画

示例

<div class="form-floating mb-3 mt-3">
  <input type="text" class="form-control" id="email" placeholder="请输入电子邮件" name="email">
  <label for="email">电子邮件</label>
</div>

<div class="form-floating mt-3 mb-3">
  <input type="text" class="form-control" id="pwd" placeholder="请输入密码" name="pswd">
  <label for="pwd">密码</label>
</div>
亲自尝试 »

浮动标签说明:<label> 元素必须放在 <input> 元素之后,并且每个 <input> 元素都需要 placeholder 属性(即使它没有显示)。


文本区域

它也适用于文本区域

示例

<div class="form-floating">
  <textarea class="form-control" id="comment" name="text" placeholder="在此处添加评论"></textarea>
  <label for="comment">评论</label>
</div>
亲自尝试 »


选择菜单

您也可以在选择菜单上使用“浮动标签”。但是,它们不会浮动/动画。标签将始终显示在选择菜单的左上角

示例

<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">选择列表(选择一个):</label>
</div>
亲自尝试 »

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
[email protected]

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
[email protected]

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2024 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.