Basic checkbox css
input[type=”checkbox”] is for the actual checkbox, excluding its label
.MyFormClass input[type="checkbox"] {
display: inline-block;
margin-right: 4px; /*Gap between checkbox and its label*/
margin-left: 8px; /*Gap between checkbox and previous label*/
}
Style a checkbox and its label
Put it within a div
<div class="MyCheckboxStyle"><input type="checkbox" name="MyCheckbox" value="1" />My Checkbox Label</div>
Checkbox + Label on line with space added under
<input type="checkbox" name="CheckboxSetting1" $CheckboxSetting1_Checked value="Yes" /><label>Checkbox Setting 1</label>
input[type="checkbox"] {
display: inline-block;
}
input[type="checkbox"] + label {
display: inline-block;
margin-bottom: 10px;
}
Checkbox as an attractive tick box
CSS
/*-------------------------*/
/*----- TICK CHECKBOX -----*/
/*------------------- -----*/
/* Customize the label (the container) */
.odac_tick_checkbox .container {
display: block;
position: relative;
width: 180px;
height: 40px;
margin-bottom: 14px;
cursor: pointer;
font-size: 14px;
line-height: 16px;
text-align: left;
padding-top: 0px;
padding-bottom: 0px;
padding-left: 37px;
padding-right: 6px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
background-color: #EBEBEB;
border-radius: 4px;
}
.odac_tick_checkbox .container .vert_align_middle {
position: absolute;
top: 50%;
transform: translateY(-54%);
}
/* Hide the browser's default checkbox */
.odac_tick_checkbox .container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
/* Create a custom checkbox */
.odac_tick_checkbox .checkmark {
position: absolute;
top: 7px;
left: 6px;
height: 25px;
width: 25px;
background-color: #D3D3D3;
}
/* On mouse-over, add a grey background color */
.odac_tick_checkbox .container:hover input ~ .checkmark {
background-color: #ccc;
}
/* When the checkbox is checked, add a teal background */
.odac_tick_checkbox .container input:checked ~ .checkmark {
background-color: var(--odac-color-main1);
}
/* Create the checkmark/indicator (hidden when not checked) */
.odac_tick_checkbox .checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.odac_tick_checkbox .container input:checked ~ .checkmark:after {
display: block;
}
/* Create the checkmark/indicator symbol (this shape is the tick!)*/
.odac_tick_checkbox .container .checkmark:after {
left: 9px;
top: 5px;
width: 7px;
height: 14px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
HTML
<div class="odac_tick_checkbox">
<label class="container"><div class="vert_align_middle">My Option</div>
<input type="checkbox" name="MyOption" value="1" >
<span class="checkmark"></span>
</label>
</div>
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.