如何在Bootstrap 5中个性化交换机复选框

dwthyt8l  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(1)|浏览(133)

我尝试更改Bootstrap 5.2中的开关复选框

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous" defer></script>
    <link rel="stylesheet" href="style.css">
    <title>switch</title>
</head>
<body>

    <div class="form-check form-switch back">
        <input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault">
        <label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
    </div>
  
    
</body>
</html>

最难的是改变里面的圈子。

ubbxdtey

ubbxdtey1#

里面的圆圈是SVG,所以要更改它,我需要使用新的SVG
这是一个基本的开关复选框Bootstrap代码:

<div class="form-check form-switch back">
        <input class="form-check-input" type="checkbox" role="switch" id="flexSwitchCheckDefault">
        <label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
 </div>

我将图像下载到本地存储库

我用CSS替换了开关复选框中的一个圆圈:我更改了背景图像的url

.form-switch .form-check-input {
  background-image: url(/ball-147676_640.png);
  background-color: yellow;
}

.form-switch .form-check-input:checked {
  background-image: url(/ball-147676_640.png);
  background-color: red;
  border-color: red;
}

.form-switch .form-check-input:focus {
  background-image: url(/ball-147676_640.png);
  box-shadow: 0 0 4px 4px red;
  border-color: red;
}

所以现在切换复选框如下所示:

聚焦:

和活动:

相关问题