创新互联Bootstrap5教程:Bootstrap5复选框与单选框

Bootstrap5 复选框与单选框

如果您希望用户从预设选项列表中选择任意数量的选项,可以使用复选框:

创新互联建站-专业网站定制、快速模板网站建设、高性价比容城网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式容城网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖容城地区。费用合理售后完善,10年实体公司更值得信赖。

实例

<
div

class
=
"
form-check
"
>

<
input

class
=
"
form-check-input
"

type
=
"
checkbox
"

id
=
"
check1
"

name
=
"
option1
"

value
=
"
something
"

checked
>

<
label

class
=
"
form-check-label
"
>
Option 1
label
>

div
>

尝试一下 »

复选框通过使用 class="form-check" 来确保标签和复选框有适当边距。

.form-check-label 类添加到标签元素,.form-check 容器内添加 .form-check-input 类来设置复选框的样式。

checked 属性用于设置默认选中的选项。

单选框

如果您希望用户从预设选项列表中选择一个选项,可以使用单选框:

实例

<
div

class
=
"
form-check
"
>

<
input

type
=
"
radio
"

class
=
"
form-check-input
"

id
=
"
radio1
"

name
=
"
optradio
"

value
=
"
option1
"

checked
>
Option 1
<
label

class
=
"
form-check-label
"

for
=
"
radio1
"
>
label
>

div
>

<
div

class
=
"
form-check
"
>

<
input

type
=
"
radio
"

class
=
"
form-check-input
"

id
=
"
radio2
"

name
=
"
optradio
"

value
=
"
option2
"
>
Option 2
<
label

class
=
"
form-check-label
"

for
=
"
radio2
"
>
label
>

div
>

<
div

class
=
"
form-check
"
>

<
input

type
=
"
radio
"

class
=
"
form-check-input
"

disabled
>
Option 3
<
label

class
=
"
form-check-label
"
>
label
>

div
>

尝试一下 »

切换开关

如果你想把复选框变成一个可切换的开关,可以在 .form-check 容器内使用 .form-switch 类:

实例

<
div

class
=
"
form-check form-switch
"
>

<
input

class
=
"
form-check-input
"

type
=
"
checkbox
"

id
=
"
mySwitch
"

name
=
"
darkmode
"

value
=
"
yes
"

checked
>

<
label

class
=
"
form-check-label
"

for
=
"
mySwitch
"
>
Dark Mode
label
>

div
>

尝试一下 »

网页名称:创新互联Bootstrap5教程:Bootstrap5复选框与单选框
文章转载:http://www.36103.cn/qtweb/news40/5040.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联