Here's a trick that works in most recent browsers (IE9+) as a CSS only solution that can be improved with javascript to support IE8 and below.
<div>
<input type="checkbox" id="checkboxID" name="checkboxName" value="whatever" />
<label for="checkboxID"> </label>
</div>
Style the label
with what you want the checkbox to look like
#checkboxID
{
position: absolute fixed;
margin-right: 2000px;
right: 100%;
}
#checkboxID + label
{
/* unchecked state */
}
#checkboxID:checked + label
{
/* checked state */
}
For javascript, you'll be able to add classes to the label to show the state. Also, it would be wise to use the following function:
$('label[for]').live('click', function(e){
$('#' + $(this).attr('for') ).click();
return false;
});
EDIT to modify #checkboxID
styles
I tried changing the padding
and margin
and well as the width
and height
, and then finally found that if you just increase the scale it'll work:
input[type=checkbox] {
transform: scale(1.5);
}
Try this CSS
input[type=checkbox] {width:100px; height:100px;}
Pure modern 2020 CSS only decision, without blurry scaling or non-handy transforming. And with tick! =)
Works nice in Firefox and Chromium-based browsers.
So, you can rule your checkboxes purely ADAPTIVE, just by setting parent block's font-height
and it will grow with text!
input[type='checkbox'] {_x000D_
-moz-appearance: none;_x000D_
-webkit-appearance: none;_x000D_
appearance: none;_x000D_
vertical-align: middle;_x000D_
outline: none;_x000D_
font-size: inherit;_x000D_
cursor: pointer;_x000D_
width: 1.0em;_x000D_
height: 1.0em;_x000D_
background: white;_x000D_
border-radius: 0.25em;_x000D_
border: 0.125em solid #555;_x000D_
position: relative;_x000D_
}_x000D_
_x000D_
input[type='checkbox']:checked {_x000D_
background: #adf;_x000D_
}_x000D_
_x000D_
input[type='checkbox']:checked:after {_x000D_
content: "?";_x000D_
position: absolute;_x000D_
font-size: 90%;_x000D_
left: 0.0625em;_x000D_
top: -0.25em;_x000D_
}
_x000D_
<label for="check1"><input type="checkbox" id="check1" checked="checked" /> checkbox one</label>_x000D_
<label for="check2"><input type="checkbox" id="check2" /> another checkbox</label>
_x000D_
Actually there is a way to make them bigger, checkboxes just like anything else (even an iframe like a facebook button).
Wrap them in a "zoomed" element:
.double {_x000D_
zoom: 2;_x000D_
transform: scale(2);_x000D_
-ms-transform: scale(2);_x000D_
-webkit-transform: scale(2);_x000D_
-o-transform: scale(2);_x000D_
-moz-transform: scale(2);_x000D_
transform-origin: 0 0;_x000D_
-ms-transform-origin: 0 0;_x000D_
-webkit-transform-origin: 0 0;_x000D_
-o-transform-origin: 0 0;_x000D_
-moz-transform-origin: 0 0;_x000D_
}
_x000D_
<div class="double">_x000D_
<input type="checkbox" name="hello" value="1">_x000D_
</div>
_x000D_
It might look a little bit "rescaled" but it works.
Of course you can make that div float:left and put your label besides it, float:left too.
I'm writtinga phonegap app, and checkboxes vary in size, look, etc. So I made my own simple checkbox:
First the HTML code:
<span role="checkbox"/>
Then the CSS:
[role=checkbox]{
background-image: url(../img/checkbox_nc.png);
height: 15px;
width: 15px;
display: inline-block;
margin: 0 5px 0 5px;
cursor: pointer;
}
.checked[role=checkbox]{
background-image: url(../img/checkbox_c.png);
}
To toggle checkbox state, I used JQuery:
CLICKEVENT='touchend';
function createCheckboxes()
{
$('[role=checkbox]').bind(CLICKEVENT,function()
{
$(this).toggleClass('checked');
});
}
But It can easily be done without it...
Hope it can help!
Source: Stackoverflow.com