bootstrap: Custom Control Checkbox not working without label
When ommitting the label tag in a custom-control-input, the checkbox is not showing up
<div class="custom-control custom-radio">
<input type="radio" id="customRadio1" name="customRadio" class="custom-control-input">
</div>
Sometimes one would need a styled checkbox without a label, especially when working with selection lists or tables.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 37
- Comments: 22 (4 by maintainers)
Suggesting we reopen this. When hiding label using the “text-hide” method, checkboxes are still off centered due to the padding that exists to offset the label from the checkbox.
This problem starts from Bootstrap v4.1.1 (https://github.com/twbs/bootstrap/pull/25944)
Fix empty custom-control-label alignment issue Before: https://codepen.io/anon/pen/yRdegO After: https://codepen.io/anon/pen/bmPEgX
source: https://github.com/twbs/bootstrap/pull/27566#issue-227128125
This worked 100% for me. Checkbox is there without label:
I have the same problem (v 4.1.1) Using “text-hide” instead of “sr-only” it works!
The problem is, that You have to use label “for” attribute, and id for input, because it triggers the script
My version is 4.0.0 published on npm.
Working with empty labels is working, but thats not a good practice as it results in unneeded code overhead.
@jipexu it doesn’t work either if you add the
sr-onlyclass to the label. An empty label element with the classcustom-control-labelworks but it’s kind of a hack and it’s not what the boostrap documentation recommend to do : https://getbootstrap.com/docs/4.0/components/forms/#without-labels.