首頁 >web前端 >Bootstrap教程 >bootstrap輸入框組有哪些
推薦教學:Bootstrap教學
1、Bootstrap4 輸入框組
# 我們可以使用 .input-group
類別來新增表單輸入方塊中更多的樣式,如圖示、文字或按鈕。使用 .input-group-prepend
類別可以在輸入框的前面新增文字訊息, .input-group-append
類別新增在輸入方塊的後面。最後,我們還需要使用 .input-group-text
類別來設定文字的樣式。
<form> <div class="input-group mb-3"> <div class="input-group-prepend"> <span class="input-group-text">@</span> </div> <input type="text" class="form-control" placeholder="Username"> </div> <div class="input-group mb-3"> <input type="text" class="form-control" placeholder="Your Email"> <div class="input-group-append"> <span class="input-group-text">@runoob.com</span> </div> </div></form>
效果圖:
2、輸入框大小
# 使用 .input-group-sm
類別來設定小型的輸入框,.input-group-lg 類別設定大的輸入框:
<form> <div class="input-group mb-3 input-group-sm"> <div class="input-group-prepend"> <span class="input-group-text">Small</span> </div> <input type="text" class="form-control"> </div></form><form> <div class="input-group mb-3"> <div class="input-group-prepend"> <span class="input-group-text">Default</span> </div> <input type="text" class="form-control"> </div></form><form> <div class="input-group mb-3 input-group-lg"> <div class="input-group-prepend"> <span class="input-group-text">Large</span> </div> <input type="text" class="form-control"> </div></form>
3、多個輸入方塊與文字
<!-- 多个输入框 --><form> <div class="input-group mb-3"> <div class="input-group-prepend"> <span class="input-group-text">Person</span> </div> <input type="text" class="form-control" placeholder="First Name"> <input type="text" class="form-control" placeholder="Last Name"> </div></form> <!-- 多个文本信息 --><form> <div class="input-group mb-3"> <div class="input-group-prepend"> <span class="input-group-text">One</span> <span class="input-group-text">Two</span> <span class="input-group-text">Three</span> </div> <input type="text" class="form-control"> </div></form>
4、複選框與單選方塊
<div class="input-group mb-3"> <div class="input-group-prepend"> <div class="input-group-text"> <input type="checkbox"> </div> </div> <input type="text" class="form-control" placeholder="RUNOOB"></div> <div class="input-group mb-3"> <div class="input-group-prepend"> <div class="input-group-text"> <input type="radio"> </div> </div> <input type="text" class="form-control" placeholder="GOOGLE"></div>
效果圖:
5、輸入框加按鈕群組<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary" type="button">Basic Button</button>
</div>
<input type="text" class="form-control" placeholder="Some text"></div>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Search">
<div class="input-group-append">
<button class="btn btn-success" type="submit">Go</button>
</div></div>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="Something clever..">
<div class="input-group-append">
<button class="btn btn-primary" type="button">OK</button>
<button class="btn btn-danger" type="button">Cancel</button>
</div></div>
6、設定下拉式選單
<div class="input-group mt-3 mb-3"> <div class="input-group-prepend"> <button type="button" class="btn btn-outline-secondary dropdown-toggle" data-toggle="dropdown"> 选择网站 </button> <div class="dropdown-menu"> <a class="dropdown-item" href="https://www.google.com">GOOGLE</a> <a class="dropdown-item" href="https://www.runoob.com">RUNOOB</a> <a class="dropdown-item" href="https://www.taobao.com">TAOBAO</a> </div> </div> <input type="text" class="form-control" placeholder="网站地址"></div>
效果圖:
#########################7、輸入框組標籤###################################################################################################################################################### ######## 在輸入框組透過在輸入框組外圍的label 來設定標籤,標籤的for 屬性需要與輸入框組的id 對應,點選標籤後可以聚焦輸入框:##### #<label for="demo">Write your email here:</label><div class="input-group mb-3"> <input type="text" class="form-control" placeholder="Email" id="demo" name="email"> <div class="input-group-append"> <span class="input-group-text">@runoob.com</span> </div></div>### ###效果圖:################
以上是bootstrap輸入框組有哪些的詳細內容。更多資訊請關注PHP中文網其他相關文章!