Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Bootstrap 4 checkbox size

Tags:

bootstrap-4

Is there a way to change Bootstraps 4 beta checkbox size to a bigger one?

I almost tried altering styles but this didn't work.

Thanks!

like image 678
Bezelinjah Avatar asked Jan 17 '18 05:01

Bezelinjah


People also ask

How do I increase the size of a checkbox?

Method 1: The checkbox size can be set by using height and width property. The height property sets the height of checkbox and width property sets the width of the checkbox.

How do I change the color of a checkbox in bootstrap?

input[type=checkbox] does not not have a background-color property. You can use other ways to get your desirable result: You can use the checkbox inside a div and then style the div according to your needs.

How to create a custom checkbox in Bootstrap forms?

Answer: The classes used to create a custom checkbox are the .custom-control class, the .custom-checkbox class, the .custom-control-input class and the .custom-control-label class. Inputs are the key features of Bootstrap forms. There is a wide range of form inputs such as text inputs, textareas, select dropdowns, radio buttons, checkboxes, etc.

How to set the checkbox size using CSS?

You can set the checkbox size by using the CSS width and height properties. Use the height property to set the height of the checkbox and the width property to set the width of the checkbox. Now let’s see an example to understand how to do it.

How to set input size in Bootstrap?

Bootstrap Input Sizing 1 Input Sizing in Forms. Set the heights of input elements using classes like .input-lg and .input-sm. Set the widths of elements using grid column classes like .col-lg-* and .col-sm-*. 2 Height Sizing 3 Column Sizing 4 Help Text

How to convert checkboxes to toggles in Bootstrap?

Simply add data-toggle="toggle" to a convert checkboxes into toggles. Simply add data-toggle="toggle" to convert checkboxes into toggles. Simply call the bootstrapToggle method to convert checkboxes into toggles.


3 Answers

There is currently an issue with this and I reported it to Bootstrap. Until that's fixed do the following:

First of all, use the form-control-lg class. Once the issue is fixed using that class will be all you need.

Until the issue is fixed add the following css:

.custom-control-label::before, 
.custom-control-label::after {
    top: .8rem;
    width: 1.25rem;
    height: 1.25rem;
}

Here's a complete working code example:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css" integrity="sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy" crossorigin="anonymous">

<style>
.custom-control-label::before, 
.custom-control-label::after {
top: .8rem;
width: 1.25rem;
height: 1.25rem;
}
</style>


<div class="custom-control form-control-lg custom-checkbox">
    <input type="checkbox" class="custom-control-input" id="customCheck1">
    <label class="custom-control-label" for="customCheck1">Check this custom checkbox</label>
</div>
like image 155
WebDevBooster Avatar answered Oct 07 '22 10:10

WebDevBooster


I've approached this a bit differently. Add the following to custom CSS.

.checkbox-1x {
    transform: scale(1.5);
    -webkit-transform: scale(1.5);
}
.checkbox-2x {
    transform: scale(2);
    -webkit-transform: scale(2);
}

Then write the input like this: input type="checkbox" class="checkbox-1x"

like image 40
iknownothing Avatar answered Oct 07 '22 11:10

iknownothing


For Bootstrap 4.2.1 users this is how I got it to work.

I have introduced a new class custom-control-lg to handle it.

.custom-control-lg .custom-control-label::before,
.custom-control-lg .custom-control-label::after {
    top: 0.1rem !important;
    left: -2rem !important;
    width: 1.25rem !important;
    height: 1.25rem !important;
}

.custom-control-lg .custom-control-label {
    margin-left: 0.5rem !important;
    font-size: 1rem !important;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" rel="stylesheet"/>

<div class="card m-3">
<div class="card-body">
    <div class="custom-control-lg custom-control custom-checkbox">
        <input class="custom-control-input" id="checkbox-large" type="checkbox"/>
        <label class="custom-control-label" for="checkbox-large">
            Checkbox label for large input!
        </label>
    </div>
    <div class="custom-control custom-checkbox">
        <input class="custom-control-input" id="checkbox-small" type="checkbox"/>
        <label class="custom-control-label" for="checkbox-small">
            Checkbox label for small input!
        </label>
    </div>
</div>
</div>
like image 17
matthew.kempson Avatar answered Oct 07 '22 11:10

matthew.kempson