本文介绍了仅使用CSS增加引导程序自定义控件自定义开关的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我试图仅使用CSS来增加自定义控件自定义开关元素的大小,但是它不起作用.
Hello I'm trying to increase the size of a custom-control custom-switch element only with css but it's not working.
我的自定义开关现在是此示例中的默认大小,但我需要更大的大小: https://getbootstrap.com/docs/4.2/components/forms/
My custom-switch now is the default size like in this example but I need it to be bigger in size:https://getbootstrap.com/docs/4.2/components/forms/
我们没有在项目中使用scss,为此找到的每个解决方案都是一个scss解决方案,这就是为什么我要寻找纯香草css解决方案的原因.
We are not using scss in our project and every solution I found for this was a scss solution thats why I'm looking for a pure vanilla css solution.
我的自定义开关代码与此类似:
My code for the custom-switch is similar to this:
<div class="custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch1">
<label class="custom-control-label" for="customSwitch1">Toggle this switch element</label>
</div>
推荐答案
.custom-control-label::before ,.custom-control-label::after{width:20px; height:20px}
.custom-control-label { // added for alignment with the switch
padding-top: 0.5rem;
padding-left: 2rem;
padding-bottom: 0.1rem;
}
.custom-switch .custom-control-label::before {
left: -2.25rem;
height: 2rem;
width: 3.5rem; // it was 1.75rem before. Sliding way is longer than before.
pointer-events: all;
border-radius: 1rem;
}
.custom-switch .custom-control-label::after {
top: calc(0.25rem + 2px);
left: calc(-2.25rem + 2px);
width: calc(2rem - 4px); // it was calc(1rem - 4px) before. Oval is bigger than before.
height: calc(2rem - 4px); // it was calc(1rem - 4px) before. Oval is bigger than before.
background-color: #adb5bd;
border-radius: 2rem; // it was 0.5rem before. Oval is bigger than before.
transition: background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-transform 0.15s ease-in-out;
transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
transition: transform 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out, -webkit-transform 0.15s ease-in-out;
}
@media (prefers-reduced-motion: reduce) {
.custom-switch .custom-control-label::after {
transition: none;
}
}
.custom-switch .custom-control-input:checked ~ .custom-control-label::after {
background-color: #fff;
-webkit-transform: translateX(1.5rem); //translateX(0.75rem);
transform: translateX(1.5rem); //translateX(0.75rem);
}
这篇关于仅使用CSS增加引导程序自定义控件自定义开关的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!