Bootstrap Checkbox is not working properly
Asked Answered
J

7

10

I'm using the following mark up and styles (Bootstrap). It shows my checkbox but it is paralysed, that is, it cannot be checked. here is my mark up: I want something more Bootstrap-ish. I know there are other options to make the checkbox look fancy but that do not solve the problem.

<div class="form-group">
  <div class="checkbox">
    1.
    <input type="checkbox" name="options" id="chk2" />
    <label class="checkbox-label">Option 2</label>
  </div>
</div>

Here is how it looks.

checkbox not working

What exactly is the issue? If I put the input element inside label I get this ugly thing:

enter image description here

Journal answered 20/2, 2015 at 14:35 Comment(8)
Not sure but its look like an outline, it's not recommend to remove him cause of accessibility property but you can try on css : outline: 0;Damson
If that is only an outline, I want to have that working as check box. the working check box in 2nd example looks so ugly. (dfc-e.com/metiers/multimedia/opensource/jqtransform)Journal
Can you add CSS styles you are using?Mycobacterium
they are standard bootstrap styles, aren't they?Journal
plnkr.co/edit/nhbdZzvX6eZffDXoIAB5?p=preview doesn't look like your example.Mycobacterium
this is all i could find for you after digging in the source: github.com/TalksLab/metro-bootstrapJournal
Here's some nice styles if they help: cssdeck.com/labs/css-checkbox-stylesPotation
I want something bootstrap-ishJournal
B
8
<input type="checkbox" name="options" id="chk2" />
<label class="checkbox-label">Option 2</label>

The problem is with your label. The for attribute must match with the name attribute of your label

Bakunin answered 5/10, 2017 at 19:46 Comment(0)
S
5

Looks need to tweak bootstrap styling for custom checkbox.

Check this

HTML

<div class="form-group">
    <div class="checkbox">
        <label for="check">
            <input type="checkbox" id="check"/>
            <span class="fake-input"></span>
            <span class="fake-label">Option 2</span>
        </label>
    </div>
</div

CSS

.fake-input {
    float: left;
    width: 20px;
    height: 20px;
    border: 1px solid #9f9f9f;
    background: #fff;
    vertical-align: middle;
    position: relative;
    margin-right: 10px;
    border-radius: 4px;
}
input[type="checkbox"] {
    position: fixed;
    top: -9999px;
    left: -9999px;
}
input[type="checkbox"]:checked + .fake-input:before {
    content:"\2713";
    position: absolute;
    color: #000;
    text-align: center;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

Check in Fiddle

Sarcomatosis answered 20/2, 2015 at 15:16 Comment(0)
P
4

Reading around it looks like you have to style the checked version and the unchecked version.

input[type=checkbox]:checked {

}

Styling with this tag should solve your problems.

Potation answered 20/2, 2015 at 14:50 Comment(0)
U
1

Use "for" attribute to solve this issue.

<div class="form-group">
  <div class="checkbox">
    1.
    <input type="checkbox" name="options" id="chk2" />
    <label for="chk2" class="checkbox-label">Option 2</label>
  </div>
</div>
Unanimous answered 22/10, 2020 at 13:31 Comment(0)
T
1

The user experience is greatly improved if the checkbox is included within the label

<div class="checkbox">
    <label class="checkbox-label">
        1.-<input type="checkbox" class="form-check-input"/>
        Option 2
    </label>
</div>
Triplicate answered 25/8, 2024 at 18:30 Comment(0)
W
0
  <div class="col-md-3">
            <input class="form-check-input" type="checkbox" id="" asp-for="">
            <label class="form-check-label" for="" asp-for="">
            </label>
        </div>
Widely answered 20/1, 2021 at 13:52 Comment(1)
Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.Alti
R
0

It's not due to Bootstrap but to Wordpress. The checkboxes became visible after I added "display:block;" to the css of the checkbox input tag.

<input class="form-check-input" type="checkbox" id="">

input.form-check-input {
display:block;
}
Reflexion answered 8/3, 2022 at 9:39 Comment(1)
why wordpress, i don't use wordprpessJournal

© 2022 - 2025 — McMap. All rights reserved.