掃二維碼與項(xiàng)目經(jīng)理溝通
我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流
在本章中,我們將學(xué)習(xí)如何使用 Bootstrap 創(chuàng)建表單。Bootstrap 通過(guò)一些簡(jiǎn)單的 HTML 標(biāo)簽和擴(kuò)展的類(lèi)即可創(chuàng)建出不同樣式的表單。

創(chuàng)新互聯(lián)公司專注于臨川網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供臨川營(yíng)銷(xiāo)型網(wǎng)站建設(shè),臨川網(wǎng)站制作、臨川網(wǎng)頁(yè)設(shè)計(jì)、臨川網(wǎng)站官網(wǎng)定制、成都微信小程序服務(wù),打造臨川網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供臨川網(wǎng)站排名全網(wǎng)營(yíng)銷(xiāo)落地服務(wù)。
表單元素 ,
Bootstrap 提供了兩種類(lèi)型的表單布局:
以下實(shí)例使用兩個(gè)輸入框,一個(gè)復(fù)選框,一個(gè)提交按鈕來(lái)創(chuàng)建堆疊表單:
<
form
>
<
div
class
=
"
mb-3 mt-3
"
>
<
label
for
=
"
email
"
class
=
"
form-label
"
>
Email:
label
>
<
input
type
=
"
email
"
class
=
"
form-control
"
id
=
"
email
"
placeholder
=
"
Enter email
"
name
=
"
email
"
>
div
>
<
div
class
=
"
mb-3
"
>
<
label
for
=
"
pwd
"
class
=
"
form-label
"
>
Password:
label
>
<
input
type
=
"
password
"
class
=
"
form-control
"
id
=
"
pwd
"
placeholder
=
"
Enter password
"
name
=
"
pswd
"
>
div
>
<
div
class
=
"
form-check mb-3
"
>
<
label
class
=
"
form-check-label
"
>
<
input
class
=
"
form-check-input
"
type
=
"
checkbox
"
name
=
"
remember
"
>
Remember me
label
>
div
>
<
button
type
=
"
submit
"
class
=
"
btn btn-primary
"
>
Submit
button
>
form
>
嘗試一下 ?
顯示效果:
實(shí)例中我們使用 .form-label 類(lèi)來(lái)確保標(biāo)簽元素有一定的內(nèi)邊距。
復(fù)選框(checkboxe)使用不同的標(biāo)記。 它們使用 .form-check 包裹在容器元素周?chē)?。?fù)選框和單選按鈕使用 .form-check-input,它的標(biāo)簽可以使用 .form-check-label 類(lèi)。
如果您希望表單元素并排顯示,請(qǐng)使用 .row 和 .col:
以下實(shí)例的兩個(gè)輸入框并排顯示,創(chuàng)建內(nèi)聯(lián)表單:
<
form
>
<
div
class
=
"
row
"
>
<
div
class
=
"
col
"
>
<
input
type
=
"
text
"
class
=
"
form-control
"
placeholder
=
"
Enter email
"
name
=
"
email
"
>
div
>
<
div
class
=
"
col
"
>
<
input
type
=
"
password
"
class
=
"
form-control
"
placeholder
=
"
Enter password
"
name
=
"
pswd
"
>
div
>
div
>
form
>
嘗試一下 ?
顯示效果:
使用 textarea 標(biāo)簽創(chuàng)建文本框提交表單,使用 .form-control 類(lèi)渲染文本框 textareas 標(biāo)簽:
<
label
for
=
"
comment
"
>
請(qǐng)輸入評(píng)論:
label
>
<
textarea
class
=
"
form-control
"
rows
=
"
5
"
id
=
"
comment
"
name
=
"
text
"
>
textarea
>
嘗試一下 ?
顯示效果:
我們可以通過(guò)在 .form-control 輸入框中使用 .form-control-lg 或 .form-control-sm 類(lèi)來(lái)設(shè)置輸入框的大小:
<
input
type
=
"
text
"
class
=
"
form-control form-control-lg
"
placeholder
=
"
大號(hào)輸入框
"
>
<
input
type
=
"
text
"
class
=
"
form-control
"
placeholder
=
"
正常大小輸入框
"
>
<
input
type
=
"
text
"
class
=
"
form-control form-control-sm
"
placeholder
=
"
小號(hào)輸入框
"
>
嘗試一下 ?
顯示效果:
使用 disabled/readonly 屬性設(shè)置輸入框禁用/只讀:
<
input
type
=
"
text
"
class
=
"
form-control
"
placeholder
=
"
Normal input
"
>
<
input
type
=
"
text
"
class
=
"
form-control
"
placeholder
=
"
Disabled input
"
disabled
>
<
input
type
=
"
text
"
class
=
"
form-control
"
placeholder
=
"
Readonly input
"
readonly
>
嘗試一下 ?
使用 .form-control-plaintext 類(lèi)可以刪除輸入框的邊框::
<
input
type
=
"
text
"
class
=
"
form-control-plaintext
"
placeholder
=
"
Plaintext input
"
>
<
input
type
=
"
text
"
class
=
"
form-control
"
placeholder
=
"
Normal input
"
>
嘗試一下 ?
使用 .form-control-color 類(lèi)可以創(chuàng)建一個(gè)取色器:
<
input
type
=
"
color
"
class
=
"
form-control form-control-color
"
value
=
"
#CCCCCC
"
>
嘗試一下 ?
顯示效果:

我們?cè)谖⑿派?4小時(shí)期待你的聲音
解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流