Bootstrap5 复选框、单选按钮、滑块

https://getbootstrap.com/docs/5.3/forms/checks-radios/

复选框有不同的标记,它们被设置了.form-check 类的容器元素包围。label设置.form-check-label类,而复选框和单选按钮使用.form-check-input。希望默认选中复选框,可以使用checked属性。

复选框

使用.form-check 类包装元素,来确保标签和复选框有适当的外边距。

例如:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="bootstrap5/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>

<body>
  <div class="container">
    <form action="">
      <div class="form-check">
        <input type="checkbox" class="form-check-input">
        <label for="" class="form-check-label">选项1</label>
      </div>
      <div class="form-check">
        <input type="checkbox" class="form-check-input">
        <label for="" class="form-check-label">选项2</label>
      </div>
      <div class="form-check">
        <input type="checkbox" class="form-check-input">
        <label for="" class="form-check-label">选项3</label>
      </div>
    </form>
  </div>

  <script src="bootstrap5/js/bootstrap.bundle.min.js"></script>
</body>

</html>

在这里插入图片描述

单选按钮

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="bootstrap5/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>

<body>
  <div class="container">
    <form action="">
      <div class="form-check">
        <input type="radio" name="gender" checked class="form-check-input">
        <label for="" class="form-check-label"></label>
      </div>
      <div class="form-check">
        <input type="radio" name="gender" class="form-check-input">
        <label for="" class="form-check-label"></label>
      </div>
    </form>
  </div>

  <script src="bootstrap5/js/bootstrap.bundle.min.js"></script>
</body>

</html>

在这里插入图片描述

拨动开关

https://getbootstrap.com/docs/5.3/forms/checks-radios/#switches

将复选框设置为切换开关的样式,可以将.form-switch 类和 .form-check类一起使用。

例如:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="bootstrap5/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>

<body>
  <div class="container">
    <form action="">
      <div class="form-check form-switch">
        <input type="checkbox" class="form-check-input" checked>
        <label for="" class="form-check-label">开关</label>
      </div>
    </form>
  </div>

  <script src="bootstrap5/js/bootstrap.bundle.min.js"></script>
</body>

</html>

在这里插入图片描述

在这里插入图片描述

滑块

https://getbootstrap.com/docs/5.3/forms/range/

.form-range 类添加到type="range"的input元素,可以设置范围菜单的样式。

例如:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="bootstrap5/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
</head>

<body>
  <div class="container">
    <form action="">
      <input type="range" class="form-range">
    </form>
  </div>

  <script src="bootstrap5/js/bootstrap.bundle.min.js"></script>
</body>

</html>

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值