javascript - 增加引导复选框的大小
问题描述
我正在使用官方引导文档中的代码创建一个简单的复选框:
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" id="customCheck" name="example1">
<label class="custom-control-label" for="customCheck">Check this custom checkbox</label>
</div>
我想知道如何使复选框比现在大?我尝试编辑 csscustomCheck
并更改 height 和 width 属性,但这不会增加框的大小。
解决方案
我添加了诸如引导开关之类*-sm, *-md, *-lg, *-xl
的类。
在这里,我使用一个 @mixin切换了所有分辨率(@mixin 与 JS 函数非常相似,但它不返回任何内容)。
对于引导程序 4
custom-switch-sm, custom-switch-md, custom-switch-lg, custom-switch-xl
SCSS: https ://codepen.io/nisharg/pen/VwLbYvv
CSS: https ://codepen.io/nisharg/pen/mdJmywW
实时片段 (CSS)
/* for sm */
.custom-switch.custom-switch-sm .custom-control-label {
padding-left: 1rem;
padding-bottom: 1rem;
}
.custom-switch.custom-switch-sm .custom-control-label::before {
height: 1rem;
width: calc(1rem + 0.75rem);
border-radius: 2rem;
}
.custom-switch.custom-switch-sm .custom-control-label::after {
width: calc(1rem - 4px);
height: calc(1rem - 4px);
border-radius: calc(1rem - (1rem / 2));
}
.custom-switch.custom-switch-sm .custom-control-input:checked ~ .custom-control-label::after {
transform: translateX(calc(1rem - 0.25rem));
}
/* for md */
.custom-switch.custom-switch-md .custom-control-label {
padding-left: 2rem;
padding-bottom: 1.5rem;
}
.custom-switch.custom-switch-md .custom-control-label::before {
height: 1.5rem;
width: calc(2rem + 0.75rem);
border-radius: 3rem;
}
.custom-switch.custom-switch-md .custom-control-label::after {
width: calc(1.5rem - 4px);
height: calc(1.5rem - 4px);
border-radius: calc(2rem - (1.5rem / 2));
}
.custom-switch.custom-switch-md .custom-control-input:checked ~ .custom-control-label::after {
transform: translateX(calc(1.5rem - 0.25rem));
}
/* for lg */
.custom-switch.custom-switch-lg .custom-control-label {
padding-left: 3rem;
padding-bottom: 2rem;
}
.custom-switch.custom-switch-lg .custom-control-label::before {
height: 2rem;
width: calc(3rem + 0.75rem);
border-radius: 4rem;
}
.custom-switch.custom-switch-lg .custom-control-label::after {
width: calc(2rem - 4px);
height: calc(2rem - 4px);
border-radius: calc(3rem - (2rem / 2));
}
.custom-switch.custom-switch-lg .custom-control-input:checked ~ .custom-control-label::after {
transform: translateX(calc(2rem - 0.25rem));
}
/* for xl */
.custom-switch.custom-switch-xl .custom-control-label {
padding-left: 4rem;
padding-bottom: 2.5rem;
}
.custom-switch.custom-switch-xl .custom-control-label::before {
height: 2.5rem;
width: calc(4rem + 0.75rem);
border-radius: 5rem;
}
.custom-switch.custom-switch-xl .custom-control-label::after {
width: calc(2.5rem - 4px);
height: calc(2.5rem - 4px);
border-radius: calc(4rem - (2.5rem / 2));
}
.custom-switch.custom-switch-xl .custom-control-input:checked ~ .custom-control-label::after {
transform: translateX(calc(2.5rem - 0.25rem));
}
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
<div class="custom-control custom-switch custom-switch-sm">
<input type="checkbox" class="custom-control-input" id="customSwitch1">
<label class="custom-control-label" for="customSwitch1">Default Unchcked Switch</label>
</div>
<div class="custom-control custom-switch custom-switch-sm">
<input type="checkbox" class="custom-control-input" id="customSwitch2" checked>
<label class="custom-control-label" for="customSwitch2">Default Checked Switch</label>
</div>
<div class="custom-control custom-switch custom-switch-md">
<input type="checkbox" class="custom-control-input" id="customSwitch3">
<label class="custom-control-label" for="customSwitch3">Default Unchcked Switch</label>
</div>
<div class="custom-control custom-switch custom-switch-md">
<input type="checkbox" class="custom-control-input" id="customSwitch4" checked>
<label class="custom-control-label" for="customSwitch4">Default Checked Switch</label>
</div>
<div class="custom-control custom-switch custom-switch-lg">
<input type="checkbox" class="custom-control-input" id="customSwitch5">
<label class="custom-control-label" for="customSwitch5">Default Unchcked Switch</label>
</div>
<div class="custom-control custom-switch custom-switch-lg">
<input type="checkbox" class="custom-control-input" id="customSwitch6" checked>
<label class="custom-control-label" for="customSwitch6">Default Checked Switch</label>
</div>
<div class="custom-control custom-switch custom-switch-xl">
<input type="checkbox" class="custom-control-input" id="customSwitch7">
<label class="custom-control-label" for="customSwitch7">Default Unchcked Switch</label>
</div>
<div class="custom-control custom-switch custom-switch-xl">
<input type="checkbox" class="custom-control-input" id="customSwitch8" checked>
<label class="custom-control-label" for="customSwitch8">Default Checked Switch</label>
</div>
对于引导程序 5
form-switch-sm, form-switch-md, form-switch-lg, form-switch-xl
SCSS:https ://codepen.io/nisharg/pen/gOPLOYY
CSS:https ://codepen.io/nisharg/pen/ExPNxYE
实时片段 (CSS)
.form-check-input {
clear: left;
}
.form-switch.form-switch-sm {
margin-bottom: 0.5rem; /* JUST FOR STYLING PURPOSE */
}
.form-switch.form-switch-sm .form-check-input {
height: 1rem;
width: calc(1rem + 0.75rem);
border-radius: 2rem;
}
.form-switch.form-switch-md {
margin-bottom: 1rem; /* JUST FOR STYLING PURPOSE */
}
.form-switch.form-switch-md .form-check-input {
height: 1.5rem;
width: calc(2rem + 0.75rem);
border-radius: 3rem;
}
.form-switch.form-switch-lg {
margin-bottom: 1.5rem; /* JUST FOR STYLING PURPOSE */
}
.form-switch.form-switch-lg .form-check-input {
height: 2rem;
width: calc(3rem + 0.75rem);
border-radius: 4rem;
}
.form-switch.form-switch-xl {
margin-bottom: 2rem; /* JUST FOR STYLING PURPOSE */
}
.form-switch.form-switch-xl .form-check-input {
height: 2.5rem;
width: calc(4rem + 0.75rem);
border-radius: 5rem;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.0-alpha1/css/bootstrap.min.css">
<div class="form-check form-switch form-switch-sm">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault">
<label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
</div>
<div class="form-check form-switch form-switch-sm">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Checked switch checkbox input</label>
</div>
<div class="form-check form-switch form-switch-md">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault">
<label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
</div>
<div class="form-check form-switch form-switch-md">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Checked switch checkbox input</label>
</div>
<div class="form-check form-switch form-switch-lg">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault">
<label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
</div>
<div class="form-check form-switch form-switch-lg">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Checked switch checkbox input</label>
</div>
<div class="form-check form-switch form-switch-xl">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckDefault">
<label class="form-check-label" for="flexSwitchCheckDefault">Default switch checkbox input</label>
</div>
<div class="form-check form-switch form-switch-xl">
<input class="form-check-input" type="checkbox" id="flexSwitchCheckChecked" checked>
<label class="form-check-label" for="flexSwitchCheckChecked">Checked switch checkbox input</label>
</div>
推荐阅读
- omnet++ - 在omnet++中计算丢包率
- r - 关于 LaTeX 的 Pandoc 规则未遵循 R blogdown hugo 主题
- r - 在每次更改值时添加数据框/行
- spring-boot - Springboot BindingResult 不返回任何错误
- mongodb - 嵌套数组中的 $lookup foreignField
- java - 在 Tomcat 9 上运行时获取 java.lang.ClassNotFoundException:Maven/Jersey Web 服务上的 jakarta.servlet.Filter
- elasticsearch - ElasticSearch/Kibana:如何聚合相似类型的页面
- asp.net-core - asp.net core 下拉列表未设置所选值
- javascript - 如何使用柏树在输入字段中仅键入随机字母
- javascript - 使用 jQuery .keydown() 插入字符后继续输入