Reputation: 4603
I am trying to a style a checkbox in bootstrap. Which includes increasing height and width and changing the border. But with hard luck I found that the only way was using -webkit. Here is the code
input.largerCheckbox {
width: 30px;
height: 30px;
-webkit-transform: scale(1.3, 1.3);
}
<input type="checkbox" class="largerCheckbox" name="checkBox">
In the above snippet, even the scale is zooming the checkbox the bigger size I wanted. It is simply distorted or out of shape. Is there any better way, Also border does not work. Any suggestions?
Note: I meant out of shape in mobile phones like iPhone or Android
Upvotes: 2
Views: 4279
Reputation: 9
<p>
<input type="checkbox" id="test1" />
<label for="test1">Red</label>
</p>
<style>
[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
position: absolute;
left: -9999px;
}
[type="checkbox"]:not(:checked) + label,
[type="checkbox"]:checked + label {
position: relative;
padding-left: 25px;
cursor: pointer;
}
[type="checkbox"]:not(:checked) + label:before,
[type="checkbox"]:checked + label:before {
content: '';
position: absolute;
left:0; top: 2px;
width: 17px; height: 17px;
border: 1px solid #aaa;
background: #f8f8f8;
border-radius: 3px;
box-shadow: inset 0 1px 3px rgba(0,0,0,.3)
}
[type="checkbox"]:not(:checked) + label:after,
[type="checkbox"]:checked + label:after {
content: '✔';
position: absolute;
top: 3px; left: 4px;
font-size: 18px;
line-height: 0.8;
color: #09ad7e;
transition: all .2s;
}
[type="checkbox"]:not(:checked) + label:after {
opacity: 0;
transform: scale(0);
}
[type="checkbox"]:checked + label:after {
opacity: 1;
transform: scale(1);
}
[type="checkbox"]:disabled:not(:checked) + label:before,
[type="checkbox"]:disabled:checked + label:before {
box-shadow: none;
border-color: #bbb;
background-color: #ddd;
}
[type="checkbox"]:disabled:checked + label:after {
color: #999;
}
[type="checkbox"]:disabled + label {
color: #aaa;
}
[type="checkbox"]:checked:focus + label:before,
[type="checkbox"]:not(:checked):focus + label:before {
border: 1px dotted blue;
}
label:hover:before {
border: 1px solid #4778d9!important;
}
</style>
Upvotes: 0
Reputation: 1398
Basically you have to hide the default style and define your own. I don't know what size you want but this should do it. Just change the size to your needs.
input.checkbox[type=checkbox] {
width: 18px;
height: 18px;
text-indent: 2.5px;
display:none !important;
}
input.checkbox[type=checkbox] + *:before {
content: '\0020';
display: inline-block;
width: 18px;
height: 18px;
vertical-align: middle;
text-align: center;
color: #0088EE;
margin-right: 5px;
background-color: #FFFFFF;
border: 1px solid #C0C0C0;
}
input.checkbox[type=checkbox]:checked + *:before {
content: '\2713';
font-size: 1.0625em;
}
<input type='checkbox' class='checkbox' id='mycheckbox'/>
<label for='mycheckbox'>Some Checkbox</label>
Upvotes: 2
Reputation: 2118
The classic way to style a checkbox is:
1- Wrap your checkbox in a label element.
2 -Hide your checkbox
3 - Add a new element after the checkbox which you will style accordingly.
I have create a fiddle with an example of checkbox with height and width larger than default. https://jsfiddle.net/vz3pgsbq/1/
You can define the state unselected with this code:
[type="checkbox"]:not(:checked) + label::before, [type="checkbox"]:checked + label::before {
background: white none repeat scroll 0 0;
border: 1px solid #aaa;
content: "";
height: 28px;
left: 0;
position: absolute;
top: 2px;
width: 28px;
}
and the checked state:
[type="checkbox"]:not(:checked) + label::after, [type="checkbox"]:checked + label::after {
color: #09ad7e;
content: "✔";
font-size: 32px;
left: 4px;
line-height: 0.8;
position: absolute;
top: 3px;
transition: all 0.2s ease 0s;
}
More examples and tools for generate your checkbox can be find in this question:
How to style checkbox using CSS?
Upvotes: 1