CSS3 radio button customization - html

My task is to make a toggle range (ascendent or descendent). First radio selection is Ascendent and the second - Descendent. I use sprite file for active, hover or selected case.
How can I remove the Input circles?
If I put for .sort-toggle input[type="radio"] - display:none; I can not see the toggle.
.sort-toggle {
margin: 0 0 0 50px;
}
.sort-toggle label {
display: none;
}
.sort-toggle input[type="radio"] {
position: relative;
cursor: pointer;
}
.sort-toggle-up:before {
content: "";
position: absolute;
height: 13px;
width: 13px;
background: transparent url("../img/sprite.png") no-repeat;
background-position: -77px -461px;
top: -3px;
left: 0;
}
.sort-toggle-up:checked:before {
background-position: -1px -461px;
}
.sort-toggle-up:hover:before {
background-position: -40px -461px;
}
.sort-toggle-down::before {
content: "";
position: absolute;
height: 13px;
width: 13px;
background: transparent url("../img/sprite.png") no-repeat;
background-position: -77px -429px;
top: 0;
left: 0;
}
.sort-toggle-down:checked:before {
background-position: -1px -429px;
}
.sort-toggle-down:hover:before {
background-position: -40px -429px;
}
<div class="sort-toggle">
<input class="sort-toggle-up" id="sort-up" type="radio" name="radio-sort" checked>
<label for="sort-up">Сортировка по возрастанию</label>
<input class="sort-toggle-down" id="sort-down" type="radio" name="radio-sort">
<label for="sort-down">Сортировка по убыванию</label>
</div>

Make necessary changes in the following, replace the background, etc
.sort-toggle {
margin: 0 0 0 50px;
}
.sort-toggle label {
position: relative;
display: inline-block;
border: 1px solid black;
}
.sort-toggle input[type="radio"] {
position: relative;
cursor: pointer;
visibility: hidden;
}
.sort-toggle input[type="radio"]:checked + .dummy-radio {
position: absolute;
height: 13px;
width: 13px;
background: red;
background-position: -77px -461px;
top: 0px;
right: 3px;
z-index: 9;
}
.sort-toggle-up:checked:before {
background-position: -1px -461px;
}
.sort-toggle-up:hover:before {
background-position: -40px -461px;
}
.sort-toggle-down:checked:before {
background-position: -1px -429px;
}
.sort-toggle-down:hover:before {
background-position: -40px -429px;
}
<div class="sort-toggle">
<label for="sort-up">Сортировка по возрастанию
<input class="sort-toggle-up" id="sort-up" type="radio" name="radio-sort" checked>
<span class="dummy-radio"></span>
</label>
<label for="sort-down">Сортировка по убыванию
<input class="sort-toggle-down" id="sort-down" type="radio" name="radio-sort">
<span class="dummy-radio"></span>
</label>
</div>

i would personally suggest to use available custom codes so you have not to spent more time on it.
Here is an example of a form structure:
<form class="ac-custom ac-checkbox ac-cross">
<h2>How do you collaboratively administrate empowered markets via plug-and-play networks?</h2>
<ul>
<li><input id="cb1" name="cb1" type="checkbox"><label for="cb1">Efficiently unleash information</label></li>
<li><input id="cb2" name="cb2" type="checkbox"><label for="cb2">Quickly maximize timely deliverables</label></li>
<li><input id="cb3" name="cb3" type="checkbox"><label for="cb3">Dramatically maintain solutions</label></li>
<li><input id="cb4" name="cb4" type="checkbox"><label for="cb4">Completely synergize relationships</label></li>
<li><input id="cb5" name="cb5" type="checkbox"><label for="cb5">Professionally cultivate customer service</label></li>
</ul>
</form>
The core styles for making the input invisible and creating the box out of the pseudo-element is the following:
.ac-custom label {
display: inline-block;
position: relative;
font-size: 2em;
padding: 0 0 0 80px;
vertical-align: top;
color: rgba(0,0,0,0.2);
cursor: pointer;
transition: color 0.3s;
}
.ac-custom input[type="checkbox"],
.ac-custom input[type="radio"],
.ac-custom label::before {
width: 50px;
height: 50px;
top: 50%;
left: 0;
margin-top: -25px;
position: absolute;
cursor: pointer;
}
.ac-custom input[type="checkbox"],
.ac-custom input[type="radio"] {
opacity: 0;
display: inline-block;
vertical-align: middle;
z-index: 100;
}
.ac-custom label::before {
content: '';
border: 4px solid #fff;
transition: opacity 0.3s;
}
.ac-custom input[type="checkbox"]:checked + label,
.ac-custom input[type="radio"]:checked + label {
color: #fff;
}
.ac-custom input[type="checkbox"]:checked + label::before,
.ac-custom input[type="radio"]:checked + label::before {
opacity: 0.8;
}
You can get custom codes from Source
https://tympanus.net/codrops/2013/10/15/animated-checkboxes-and-radio-buttons-with-svg/

Thanks for Your interest of my problem. At last I finished by my self.
.visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
border: 0;
padding: 0;
clip: rect(0 0 0 0);
overflow: hidden;
}
.sort-toggle input[type="radio"] {
display: none;
}
.sort-toggle label {
display: inline-block;
cursor: pointer;
}
.sort-toggle input[type="radio"] + label.sort-toggle-up svg,
.sort-toggle input[type="radio"] + label.sort-toggle-down svg {
width: 11px;
height: 10px;
fill: #c5c5c5;
}
.sort-toggle input[type="radio"]:checked + label.sort-toggle-up svg,
.sort-toggle input[type="radio"]:checked + label.sort-toggle-down svg {
fill: red;
}
.sort-toggle input[type="radio"]:hover + label.sort-toggle-up svg,
.sort-toggle input[type="radio"]:hover + label.sort-toggle-down svg {
fill: black;
}
<div class="sort-toggle">
<input type="radio" checked="checked" id="sort-up" name="radio-sort">
<label for="sort-up" class="sort-toggle-up">
<span class="visually-hidden">Сортировка по возрастанию</span>
<svg><polygon points="5.5,0 0,10 11,10 " /></svg>
</label>
<input type="radio" id="sort-down" name="radio-sort">
<label for="sort-down" class="sort-toggle-down">
<span class="visually-hidden">Сортировка по убыванию</span>
<svg>
<polyline points="5.5,10 0,0 11,0 " />
</svg>
</label>
</div>

Related

Using image for checkbox input

First, please do not mark this as duplicate, cause I want to ask a little modification from this QnA, here. I'm using this answer to achieve what I want, but it almost meets what I need. Here is his demo.
I am trying to achieve what he did, this is what I've made so far. But, when I click the image, because of the border, it makes the images a little get bigger. What I want is, when the image (checkbox) checked, there are checkboxes icon on the top left (its done) and the image surrounds with a border without making the image get bigger. Here is the code in my snippet:
here is the HTML:
<ul>
<li><input type="checkbox" id="cb1" />
<label for="cb1"><img src="http://lorempixel.com/103/103" /></label>
</li>
<li><input type="checkbox" id="cb2" />
<label for="cb2"><img src="http://lorempixel.com/102/102" /></label>
</li>
</ul>
this is the CSS:
ul {
list-style-type: none;
}
li {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
display: block;
position: relative;
cursor: pointer;
width: 100%;
height: 100%;
}
label:before {
background-color: red;
color: white;
display: block;
border: 1px solid red;
position: absolute;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
-webkit-transition-duration: 0.4s;
-moz-transition-duration: 0.4s;
-ms-transition-duration: 0.4s;
}
label img {
height: 100%;
width: 100%;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
border: 1px solid red;
z-index: 99;
}
:checked + label img {
z-index: -1;
border: 1px solid red;
}
Thank you!
Add Border for img with transparent
label img {
height: 100%;
width: 100%;
border: 1px solid transparent;
}
https://codepen.io/anon/pen/PVRxRM
I gave fixed height and width to li and when the checkbox is checked i am changing the height and width of an image and aligning it in the center. hope this is what you are looking for. thanks.
ul {
list-style-type: none;
}
li {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
display: block;
position: relative;
cursor: pointer;
height: 120px;
border: 1px solid;
width: 120px;
}
label:before {
background-color: red;
color: white;
display: block;
position: absolute;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
}
label img {
height: 100%;
width: 100%;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
border: 1px solid red;
z-index: 99;
}
:checked + label img {
z-index: -1;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
height: 100px;
width: 100px;
}
<ul>
<li><input type="checkbox" id="cb1" />
<label for="cb1"><img src="http://lorempixel.com/100/100" /></label>
</li>
<li><input type="checkbox" id="cb2" />
<label for="cb2"><img src="http://lorempixel.com/101/101" /></label>
</li>
<li><input type="checkbox" id="cb3" />
<label for="cb3"><img src="http://lorempixel.com/102/102" /></label>
</li>
<li><input type="checkbox" id="cb4" />
<label for="cb4"><img src="http://lorempixel.com/103/103" /></label>
</li>
</ul>
Try This:
ul {
list-style-type: none;
}
li {
display: inline-block;
}
input[type="checkbox"][id^="cb"] {
display: none;
}
label {
border: 1px solid #fff;
display: block;
position: relative;
cursor: pointer;
}
label:before {
background-color: red;
color: white;
content: "";
display: block;
border: 1px solid red;
position: absolute;
width: 20px;
height: 20px;
text-align: center;
line-height: 20px;
transition-duration: 0.4s;
transform: scale(0);
}
label img {
height: 100%;
width: 100%;
transition-duration: 0.2s;
transform-origin: 50% 50%;
}
:checked + label {
border-color: red;
}
:checked + label:before {
content: "✓";
background-color: red;
z-index: 99;
transform: scale(1);
}
:checked + label img {
z-index: -1;
transform: scale(0.9);
}
<ul>
<li><input type="checkbox" id="cb1" />
<label for="cb1"><img src="http://lorempixel.com/103/103" /></label>
</li>
<li><input type="checkbox" id="cb2" />
<label for="cb2"><img src="http://lorempixel.com/102/102" /></label>
</li>
</ul>
So if requirement is when you click on image, you need to show ✓ on left top corner of image, and you also want to show some border around image, then what you have done is absolutely right.
If you are concerned about image moving by n pixel, then keep in mind that border occupy some space unlike outline which doesnt need any space. Outline takes n pixel around object and apply border type effect.
So there are 2 solution -
what #lalji suggested above. when you load page, apply border on image with color as transparent so it will reserve the space for your border and actually you will not see any border around it, and on clicking (selecting image) just change the color of border.
Fiddle for border transparent
label img {
height: 100%;
width: 100%;
border: 1px solid transparent;
}
another will be when you click it, apply the outline instead of border.
Fiddle for outline
:checked + label img {
z-index: -1;
outline: 1px solid red;
}
UPADTE if we want to show some image/text also when image selected. if you see here I have added another node saying details that will be shown only when image selected and will be aligned in centre of the image.
Fiddle
This below css rule to hide the details initially and making them in centre etc.
label img + .details
{
color:white;
position:absolute;
top:0px;
width:100%;
display:none;
margin-top:50%;
transform: translatey(-50%);
text-align:center;
}
Now, we will show the details section if image selected.
:checked + label img + .details
{
display:block;
}
You can use a "label" tag that contains an "img" tag inside.
Here's an example of using an image as a checkbox and radio.
* {
font-family: Lato;
margin: 0;
padding: 0;
--transition: 0.15s;
--border-radius: 0.5rem;
--background: #ffc107;
--box-shadow: #ffc107;
}
.cont-bg {
min-height: 100vh;
background-image: radial-gradient(
circle farthest-corner at 7.2% 13.6%,
rgba(37, 249, 245, 1) 0%,
rgba(8, 70, 218, 1) 90%
);
padding: 1rem;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.cont-title {
color: white;
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
}
.cont-main {
display: flex;
flex-wrap: wrap;
align-content: center;
justify-content: center;
}
.cont-checkbox {
width: 150px;
height: 100px;
border-radius: var(--border-radius);
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
background: white;
transition: transform var(--transition);
}
.cont-checkbox:first-of-type {
margin-bottom: 0.75rem;
margin-right: 0.75rem;
}
.cont-checkbox:active {
transform: scale(0.9);
}
input {
display: none;
}
input:checked + label {
opacity: 1;
box-shadow: 0 0 0 3px var(--background);
}
input:checked + label img {
-webkit-filter: none; /* Safari 6.0 - 9.0 */
filter: none;
}
input:checked + label .cover-checkbox {
opacity: 1;
transform: scale(1);
}
input:checked + label .cover-checkbox svg {
stroke-dashoffset: 0;
}
label {
display: inline-block;
cursor: pointer;
border-radius: var(--border-radius);
overflow: hidden;
width: 100%;
height: 100%;
position: relative;
opacity: 0.6;
}
label img {
width: 100%;
height: 70%;
object-fit: cover;
clip-path: polygon(0% 0%, 100% 0, 100% 81%, 50% 100%, 0 81%);
-webkit-filter: grayscale(100%); /* Safari 6.0 - 9.0 */
filter: grayscale(100%);
}
label .cover-checkbox {
position: absolute;
right: 5px;
top: 3px;
z-index: 1;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--box-shadow);
border: 2px solid #fff;
transition: transform var(--transition),
opacity calc(var(--transition) * 1.2) linear;
opacity: 0;
transform: scale(0);
}
label .cover-checkbox svg {
width: 13px;
height: 11px;
display: inline-block;
vertical-align: top;
fill: none;
margin: 5px 0 0 3px;
stroke: #fff;
stroke-width: 2;
stroke-linecap: round;
stroke-linejoin: round;
stroke-dasharray: 16px;
transition: stroke-dashoffset 0.4s ease var(--transition);
stroke-dashoffset: 16px;
}
label .info {
text-align: center;
margin-top: 0.2rem;
font-weight: 600;
font-size: 0.8rem;
}
<div class="cont-bg">
<div class="cont-title">Checkbox</div>
<div class="cont-main">
<div class="cont-checkbox">
<input type="checkbox" id="myCheckbox-1" />
<label for="myCheckbox-1">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2021-mazda-mx-5-miata-mmp-1-1593459650.jpg?crop=0.781xw:0.739xh;0.109xw,0.0968xh&resize=480:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Mazda MX-5 Miata</div>
</label>
</div>
<div class="cont-checkbox">
<input type="checkbox" id="myCheckbox-2" />
<label for="myCheckbox-2">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2020-chevrolet-corvette-c8-102-1571146873.jpg?crop=0.548xw:0.411xh;0.255xw,0.321xh&resize=980:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Toyota Supra</div>
</label>
</div>
</div>
<div class="cont-title">Radio</div>
<div class="cont-main">
<div class="cont-checkbox">
<input type="radio" name="myRadio" id="myRadio-1" />
<label for="myRadio-1">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2021-mazda-mx-5-miata-mmp-1-1593459650.jpg?crop=0.781xw:0.739xh;0.109xw,0.0968xh&resize=480:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Mazda MX-5 Miata</div>
</label>
</div>
<div class="cont-checkbox">
<input type="radio" name="myRadio" id="myRadio-2" />
<label for="myRadio-2">
<img
src="https://hips.hearstapps.com/hmg-prod.s3.amazonaws.com/images/2020-chevrolet-corvette-c8-102-1571146873.jpg?crop=0.548xw:0.411xh;0.255xw,0.321xh&resize=980:*"
/>
<span class="cover-checkbox">
<svg viewBox="0 0 12 10">
<polyline points="1.5 6 4.5 9 10.5 1"></polyline>
</svg>
</span>
<div class="info">Toyota Supra</div>
</label>
</div>
</div>
</div>

How to create a tick mark in a custom checkbox?

I want to make a custom checkbox with CSS, but not sure how do it.
.custom-checkbox {
border: 3px solid #7e8a94;
float: right;
height: 20px;
width: 20px;
border-radius: 5px;
cursor: pointer;
display: inline-block;
}
.custom-checkbox.hover {
border: 3px solid #43D8B0;
}
.custom-checkbox.active {
border: 3px solid #43D8B0;
}
.custom-checkbox.active.checkmark {}
<input type='checkbox' class='checkbox'>
<div class="custom-checkbox">
<div class="checkmark"></div>
</div>
I added active class to custom-checkbox on checking, but not sure how to create a tick inside a box then?
You have to manually customize your input & add a label in a way using pseudo elements to get the desired effect in the checkbox you want here.
Also, you can use content: '✔'; in your css to provide a tick on click.
I built you a demo to refer to, check the following code:
[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: -5px;
width: 40px;
height: 40px;
background: #fff;
border-radius: 3px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, .1);
border-radius: 50%;
background-color: #5cf1b3;
outline: none;
}
[type="checkbox"]:not(:checked)+label:after,
[type="checkbox"]:checked+label:after {
content: '✔';
position: absolute;
top: 8px;
left: 10px;
font-size: 24px;
line-height: 0.8;
color: #fff;
transition: all .2s;
}
[type="checkbox"]:not(:checked)+label:after {
opacity: 0;
transform: scale(0);
}
[type="checkbox"]:checked+label:after {
opacity: 1;
transform: scale(1);
}
<p>
<input type="checkbox" id="test1" />
<label for="test1"></label>
</p>
You will need to use :checked pseudo class for it. In the following example it's using a span tag to create the custom checkbox style, and using a pseudo element :before with a special character ✔ inside for the tick.
.custom-checkbox input {
display: none;
}
.custom-checkbox span {
border: 3px solid #7e8a94;
float: right;
height: 20px;
width: 20px;
border-radius: 5px;
cursor: pointer;
display: flex;
justify-content: center;
align-items: center;
}
.custom-checkbox:hover span,
.custom-checkbox input:checked + span {
border: 3px solid #43D8B0;
}
.custom-checkbox input:checked + span:before {
content: "✔";
}
<label class="custom-checkbox">
<input type="checkbox">
<span></span>
</label>
You can check custom checkbox in different-different states below snippet
/* Base for label styling */
[type="checkbox"]:not(:checked),
[type="checkbox"]:checked {
position: absolute;
left: -9999px;
}
[type="checkbox"]:not(:checked) + label,
[type="checkbox"]:checked + label {
position: relative;
padding-left: 1.95em;
cursor: pointer;
}
/* checkbox aspect */
[type="checkbox"]:not(:checked) + label:before,
[type="checkbox"]:checked + label:before {
content: '';
position: absolute;
left: 0; top: 0;
width: 1.25em; height: 1.25em;
border: 2px solid #ccc;
background: #fff;
border-radius: 4px;
box-shadow: inset 0 1px 3px rgba(0,0,0,.1);
}
/* checked mark aspect */
[type="checkbox"]:not(:checked) + label:after,
[type="checkbox"]:checked + label:after {
content: '✔';
position: absolute;
top: .1em; left: .3em;
font-size: 1.3em;
line-height: 0.8;
color: #09ad7e;
transition: all .2s;
}
/* checked mark aspect changes */
[type="checkbox"]:not(:checked) + label:after {
opacity: 0;
transform: scale(0);
}
[type="checkbox"]:checked + label:after {
opacity: 1;
transform: scale(1);
}
/* disabled checkbox */
[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;
}
/* accessibility */
[type="checkbox"]:checked:focus + label:before,
[type="checkbox"]:not(:checked):focus + label:before {
border: 2px dotted blue;
}
/* hover style just for information */
label:hover:before {
border: 2px solid #4778d9!important;
}
<p>
<input type="checkbox" id="test1" />
<label for="test1">Red</label>
</p>
<p>
<input type="checkbox" id="test2" checked="checked" />
<label for="test2">Yellow</label>
</p>
<p>
<input type="checkbox" id="test3" checked="checked" disabled="disabled" />
<label for="test3">Green</label>
</p>
<p>
<input type="checkbox" id="test4" disabled="disabled" />
<label for="test4">Brown</label>
</p>

How do I customize checkboxes so that it looks similar to the image attached?

How do I style multiple checkboxes in an html form so that the appearance of the checkboxes is similar to as shown in the attached image?
You have to manually customize your input & label in a way using pseudo elements to get the effect in the checkbox you want here.
I built you a demo to refer to, check the following code:
[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: -5px;
width: 40px;
height: 40px;
background: #fff;
border-radius: 3px;
box-shadow: inset 0 1px 3px rgba(0, 0, 0, .1);
border-radius: 50%;
background-color: #5cf1b3;
outline: none;
}
[type="checkbox"]:not(:checked) + label:after,
[type="checkbox"]:checked + label:after {
content: '✔';
position: absolute;
top: 8px;
left: 10px;
font-size: 24px;
line-height: 0.8;
color: #fff;
transition: all .2s;
}
[type="checkbox"]:not(:checked) + label:after {
opacity: 0;
transform: scale(0);
}
[type="checkbox"]:checked + label:after {
opacity: 1;
transform: scale(1);
}
<p>
<input type="checkbox" id="test1" />
<label for="test1"></label>
</p>
This is how you can do it with no javascript. You can customize the appearence however you want.
li {
width:200px;
list-style:none;
position:relative;
height: 30px;
line-height:30px;
margin:10px 0;
}
label{
cursor:pointer;
width:100%;
float:left;
}
input[type=checkbox] {
appearance:none;
-webkit-appearance:none;
-moz-appearance:none;
}
input[type=checkbox]:after {
content: "";
width: 30px;
height: 30px;
background:url("http://www.clker.com/cliparts/c/C/o/E/v/d/check-no-md.png") no-repeat;
background-size:contain;
top: 0px;
right: 0px;
position: absolute;
display: inline-block;
}
input[type=checkbox]:checked:after {
content: "";
width: 30px;
height: 30px;
background:url("http://www.clker.com/cliparts/u/3/i/2/t/D/check-yes-md.png") no-repeat;
background-size:contain;
top: 0px;
right: 0px;
position: absolute;
display: inline-block;
}
<ul>
<li>
<label>dededede<input name="checkbox1" type="checkbox" /></label>
</li>
<li>
<label>Checkbox1 <input name="checkbox2" type="checkbox" /></label>
</li>
</ul>

Is it possible to customize with pure css radio button input without label?

<input id="whateveryoulike" class="whateveryoulike" name="test" type="radio" checked="checked">
<input id="whateveryoulike2" class="whateveryoulike2" name="test2" type="radio">
Is this possible to customize this two elements without targeting the label of each one of them and using only css(with html and imgs)?
I tried to use input[type=radio]::after, but it doesn't seem to work. But here's a nice little trick that works in all modern browsers:
Put a <span> after every radio button, with no whitespace between. This span is above the input, but the input is still clickable because of pointer-events: none (this is not supported in older IE Versions).
Now you can style the buttons however you want:
span.customRadio {
display: none;
}
input[type="radio"] {
width: 16px;
height: 16px;
margin: 0;
cursor: default;
}
input[type="radio"] + span.customRadio {
display: inline-block;
width: 16px;
height: 16px;
background-color: white;
margin: 0 0 0 -16px;
border-radius: 50%;
box-shadow: 0 0 3px -1px rgba(0, 0, 0, 0.8);
pointer-events: none;
}
input[type="radio"] + span.customRadio::after {
content: '.';
color: transparent;
position: absolute;
display: block;
width: 2px;
height: 2px;
margin: 7px 0 0 7px;
opacity: 0.6;
border-radius: 50%;
transition: .2s;
}
input[type="radio"]:checked + span.customRadio::after {
width: 10px;
height: 10px;
margin: 3px 0 0 3px;
opacity: 1;
background-color: #3388ff;
box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.2);
}
<input name="test" type="radio" checked="checked"><span class="customRadio"></span>
<input name="test2" type="radio"><span class="customRadio"></span><br><br>
In action:<br>
<input name="test3" type="radio"><span class="customRadio"></span>
<input name="test3" type="radio"><span class="customRadio"></span>
<input name="test3" type="radio"><span class="customRadio"></span>
JSFiddle
You may style it this way:
input[type='radio'] {
background: none;
opacity: 0;
}
.checkbox_outer {
position: relative;
float: left;
margin-right: 5px;
}
input[type='radio'] + span {
position: absolute; top:0; left:0; right:0; bottom:0; background-image: url('http://s28.postimg.org/oggskkn6x/controls.png'); background-repeat: no-repeat;}
input[type='radio'], .checkbox_outer {
height: 16px;
width: 16px;
position: relative;
z-index: 10;
}
/*Radiobutton*/
input[type='radio']+span {
background-position: -32px 0;
}
input[type='radio']:checked + span {
background-position: -48px 0;
}
input[type='radio']:hover:checked + span,
input[type='radio']:focus:checked + span {
background-position: -48px -16px;
}
input[type='radio']:hover + span,
input[type='radio']:focus + span {
background-position: -32px -16px;
}
input[type='radio']:disabled + span {
background-position: -32px -32px;
}
input[type='radio']:disabled:checked + span {
background-position: -48px -32px;
}
input[type='radio']:hover:disabled + span,
input[type='radio']:focus:disabled + span {
background-position: -32px -32px;
}
input[type='radio']:hover:disabled:checked + span,
input[type='radio']:focus:disabled:checked + span {
background-position: -48px -32px;
}
input[type='radio']:active + span {
background-position: -32px -48px;
}
input[type='radio']:active:checked + span {
background-position: -48px -48px;
}
<strong>Radio buttons </strong>
<br />
<div class="checkbox_outer">
<input id="ID5" type="radio" name="NAME5" checked><span></span>
</div>Checked
<br />
<div class="checkbox_outer">
<input id="ID5" type="radio" name="NAME5"><span></span>
</div>Not checked
<br />
<div class="checkbox_outer">
<input id="ID6" type="radio" name="NAME6" checked disabled><span> </span>
</div>Checked & disabled
<br />
<div class="checkbox_outer">
<input id="ID6" type="radio" name="NAME6" disabled><span></span>
</div>Not checked & disabled
<br />
Use labels, its makes styling & customization easy.
check this
image for radio
custom radios
try this one
input[type=radio]:not(old) {
width: 23px;
height: 23px;
display: inline-block;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance: none;
appearance: none;
border-radius: 1em;
border: 2px solid #01a982;
outline: none !important;}
input[type=radio]:not(old):checked{
background-image: radial-gradient(circle at center, #fff, #fff 37.5%, #01a982 40%, #01a982 100%);
outline: none;}

Can I change the checkbox size using CSS?

Is it possible to set the size of a checkbox using CSS or HTML across browsers?
width and size work in IE6+, but not with Firefox, where the checkbox stays 16x16 even if I set a smaller size.
It's a little ugly (due to the scaling up), but it works on most newer browsers:
input[type=checkbox]
{
/* Double-sized Checkboxes */
-ms-transform: scale(2); /* IE */
-moz-transform: scale(2); /* FF */
-webkit-transform: scale(2); /* Safari and Chrome */
-o-transform: scale(2); /* Opera */
transform: scale(2);
padding: 10px;
}
/* Might want to wrap a span around your checkbox text */
.checkboxtext
{
/* Checkbox text */
font-size: 110%;
display: inline;
}
<input type="checkbox" name="optiona" id="opta" checked />
<span class="checkboxtext">
Option A
</span>
<input type="checkbox" name="optionb" id="optb" />
<span class="checkboxtext">
Option B
</span>
<input type="checkbox" name="optionc" id="optc" />
<span class="checkboxtext">
Option C
</span>
Working solution for all modern browsers.
input[type=checkbox] {
transform: scale(1.5);
}
<label><input type="checkbox"> Test</label>
Compatibility:
IE: 10+
FF: 16+
Chrome: 36+
Safari: 9+
Opera: 23+
iOS Safari: 9.2+
Chrome for Android: 51+
Appearance:
Chrome 58 (May 2017), Windows 10
An easy solution is use the property zoom:
input[type="checkbox"] {
zoom: 1.5;
}
<input type="checkbox" />
2020 version - using pseudo-elements, size depends on font size.
Default checkbox/radio is rendered outside of screen, but CSS creates virtual elements very similar to default elements. Supports all browsers, no blur. Size depends on font size. Keyboard actions (space, tabs) are also supported.
https://jsfiddle.net/ohf7nmzy/2/
body{
padding:0 20px;
}
.big{
font-size: 50px;
}
/* CSS below will force radio/checkbox size be same as font size */
label{
position: relative;
line-height: 1.4;
}
/* radio */
input[type=radio]{
width: 1em;
font-size: inherit;
margin: 0;
transform: translateX(-9999px);
}
input[type=radio] + label:before{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border:none;
border-radius: 50%;
background-color: #bbbbbb;
}
input[type=radio] + label:after{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: white;
border-radius: 50%;
transform: scale(0.8);
}
/*checked*/
input[type=radio]:checked + label:before{
position:absolute;
content:'';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: #3b88fd;
}
input[type=radio]:checked + label:after{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: white;
border-radius: 50%;
transform: scale(0.3);
}
/*focused*/
input[type=radio]:focus + label:before{
border: 0.2em solid #8eb9fb;
margin-top: -0.2em;
margin-left: -0.2em;
box-shadow: 0 0 0.3em #3b88fd;
}
/*checkbox/*/
input[type=checkbox]{
width: 1em;
font-size: inherit;
margin: 0;
transform: translateX(-9999px);
}
input[type=checkbox] + label:before{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border:none;
border-radius: 10%;
background-color: #bbbbbb;
}
input[type=checkbox] + label:after{
position: absolute;
content: '';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: white;
border-radius: 10%;
transform: scale(0.8);
}
/*checked*/
input[type=checkbox]:checked + label:before{
position:absolute;
content:'';
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: #3b88fd;
}
input[type=checkbox]:checked + label:after{
position: absolute;
content: "\2713";
left: -1.3em;
top: 0;
width: 1em;
height: 1em;
margin: 0;
border: none;
background-color: #3b88fd;
border-radius: 10%;
color: white;
text-align: center;
line-height: 1;
}
/*focused*/
input[type=checkbox]:focus + label:before{
border: 0.1em solid #8eb9fb;
margin-top: -0.1em;
margin-left: -0.1em;
box-shadow: 0 0 0.2em #3b88fd;
}
<input type="checkbox" name="checkbox_1" id="ee" checked />
<label for="ee">Checkbox small</label>
<br />
<input type="checkbox" name="checkbox_2" id="ff" />
<label for="ff">Checkbox small</label>
<hr />
<div class="big">
<input type="checkbox" name="checkbox_3" id="gg" checked />
<label for="gg">Checkbox big</label>
<br />
<input type="checkbox" name="checkbox_4" id="hh" />
<label for="hh">Checkbox big</label>
</div>
<hr />
<input type="radio" name="radio_1" id="aa" value="1" checked />
<label for="aa">Radio small</label>
<br />
<input type="radio" name="radio_1" id="bb" value="2" />
<label for="bb">Radio small</label>
<hr />
<div class="big">
<input type="radio" name="radio_2" id="cc" value="1" checked />
<label for="cc">Radio big</label>
<br />
<input type="radio" name="radio_2" id="dd" value="2" />
<label for="dd">Radio big</label>
</div>
2017 version - using zoom or scale
Browser will use non-standard zoom feature if it is supported (nice quality) or standard transform: scale (blurry on Safari) as fallback.
https://jsfiddle.net/ksvx2txb/11/
#supports (zoom:2) {
input[type="radio"], input[type=checkbox]{
zoom: 2;
}
}
#supports not (zoom:2) {
input[type="radio"], input[type=checkbox]{
transform: scale(2);
margin: 15px;
}
}
label{
/* fix vertical align issues */
display: inline-block;
vertical-align: top;
margin-top: 10px;
}
<input type="radio" name="aa" value="1" id="aa" checked />
<label for="aa">Radio 1</label>
<br />
<input type="radio" name="aa" value="2" id="bb" />
<label for="bb">Radio 2</label>
<br /><br />
<input type="checkbox" name="optiona" id="cc" checked />
<label for="cc">Checkbox 1</label>
<br />
<input type="checkbox" name="optiona" id="dd" />
<label for="dd">Checkbox 1</label>
I just came out with this:
input[type="checkbox"] {display:none;}
input[type="checkbox"] + label:before {content:"☐";}
input:checked + label:before {content:"☑";}
label:hover {color:blue;}
<input id="check" type="checkbox" /><label for="check">Checkbox</label>
Of course, thanks to this, you can change the value of content to your needs and use an image if you wish or use another font...
The main interest here is that:
The checkbox size stays proportional to the text size
You can control the aspect, the color, the size of the checkbox
No extra HTML needed !
Only 3 lines of CSS needed (the last one is just to give you ideas)
Edit:
As pointed out in the comment, the checkbox won't be accessible by key navigation. You should probably add tabindex=0 as a property for your label to make it focusable.
Preview:
http://jsfiddle.net/h4qka9td/
*,*:after,*:before {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 0;
margin: 0;
}
.switch {
margin: 50px auto;
position: relative;
}
.switch label {
width: 100%;
height: 100%;
position: relative;
display: block;
}
.switch input {
top: 0;
right: 0;
bottom: 0;
left: 0;
opacity: 0;
z-index: 100;
position: absolute;
width: 100%;
height: 100%;
cursor: pointer;
}
/* DEMO 3 */
.switch.demo3 {
width: 180px;
height: 50px;
}
.switch.demo3 label {
display: block;
width: 100%;
height: 100%;
background: #a5a39d;
border-radius: 40px;
box-shadow:
inset 0 3px 8px 1px rgba(0,0,0,0.2),
0 1px 0 rgba(255,255,255,0.5);
}
.switch.demo3 label:after {
content: "";
position: absolute;
z-index: -1;
top: -8px; right: -8px; bottom: -8px; left: -8px;
border-radius: inherit;
background: #ababab;
background: -moz-linear-gradient(#f2f2f2, #ababab);
background: -ms-linear-gradient(#f2f2f2, #ababab);
background: -o-linear-gradient(#f2f2f2, #ababab);
background: -webkit-gradient(linear, 0 0, 0 100%, from(#f2f2f2), to(#ababab));
background: -webkit-linear-gradient(#f2f2f2, #ababab);
background: linear-gradient(#f2f2f2, #ababab);
box-shadow: 0 0 10px rgba(0,0,0,0.3),
0 1px 1px rgba(0,0,0,0.25);
}
.switch.demo3 label:before {
content: "";
position: absolute;
z-index: -1;
top: -18px; right: -18px; bottom: -18px; left: -18px;
border-radius: inherit;
background: #eee;
background: -moz-linear-gradient(#e5e7e6, #eee);
background: -ms-linear-gradient(#e5e7e6, #eee);
background: -o-linear-gradient(#e5e7e6, #eee);
background: -webkit-gradient(linear, 0 0, 0 100%, from(#e5e7e6), to(#eee));
background: -webkit-linear-gradient(#e5e7e6, #eee);
background: linear-gradient(#e5e7e6, #eee);
box-shadow:
0 1px 0 rgba(255,255,255,0.5);
-webkit-filter: blur(1px);
-moz-filter: blur(1px);
-ms-filter: blur(1px);
-o-filter: blur(1px);
filter: blur(1px);
}
.switch.demo3 label i {
display: block;
height: 100%;
width: 60%;
border-radius: inherit;
background: silver;
position: absolute;
z-index: 2;
right: 40%;
top: 0;
background: #b2ac9e;
background: -moz-linear-gradient(#f7f2f6, #b2ac9e);
background: -ms-linear-gradient(#f7f2f6, #b2ac9e);
background: -o-linear-gradient(#f7f2f6, #b2ac9e);
background: -webkit-gradient(linear, 0 0, 0 100%, from(#f7f2f6), to(#b2ac9e));
background: -webkit-linear-gradient(#f7f2f6, #b2ac9e);
background: linear-gradient(#f7f2f6, #b2ac9e);
box-shadow:
inset 0 1px 0 white,
0 0 8px rgba(0,0,0,0.3),
0 5px 5px rgba(0,0,0,0.2);
}
.switch.demo3 label i:after {
content: "";
position: absolute;
left: 15%;
top: 25%;
width: 70%;
height: 50%;
background: #d2cbc3;
background: -moz-linear-gradient(#cbc7bc, #d2cbc3);
background: -ms-linear-gradient(#cbc7bc, #d2cbc3);
background: -o-linear-gradient(#cbc7bc, #d2cbc3);
background: -webkit-gradient(linear, 0 0, 0 100%, from(#cbc7bc), to(#d2cbc3));
background: -webkit-linear-gradient(#cbc7bc, #d2cbc3);
background: linear-gradient(#cbc7bc, #d2cbc3);
border-radius: inherit;
}
.switch.demo3 label i:before {
content: "off";
text-transform: uppercase;
font-style: normal;
font-weight: bold;
color: rgba(0,0,0,0.4);
text-shadow: 0 1px 0 #bcb8ae, 0 -1px 0 #97958e;
font-family: Helvetica, Arial, sans-serif;
font-size: 24px;
position: absolute;
top: 50%;
margin-top: -12px;
right: -50%;
}
.switch.demo3 input:checked ~ label {
background: #9abb82;
}
.switch.demo3 input:checked ~ label i {
right: -1%;
}
.switch.demo3 input:checked ~ label i:before {
content: "on";
right: 115%;
color: #82a06a;
text-shadow:
0 1px 0 #afcb9b,
0 -1px 0 #6b8659;
}
<div class="switch demo3">
<input type="checkbox">
<label><i></i>
</label>
</div>
<div class="switch demo3">
<input type="checkbox" checked>
<label><i></i>
</label>
</div>
The appearance of checkboxes seems to be fixed by default. But as pointed out by Worthy7 this can be remedied using CSS appearance property. It will make checkboxes completely empty, so you can define your own appearance. What is nice about this: You can use your existing HTML code. Downside: It is experimental technology. Edge (legacy) and IE do not use the custom style.
Here are the needed CSS styles:
input[type=checkbox] {
width: 14mm;
-webkit-appearance: none;
-moz-appearance: none;
height: 14mm;
border: 0.1mm solid black;
}
input[type=checkbox]:checked {
background-color: lightblue;
}
input[type=checkbox]:checked:after {
margin-left: 4.3mm;
margin-top: -0.4mm;
width: 3mm;
height: 10mm;
border: solid white;
border-width: 0 2mm 2mm 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
content: "";
display: inline-block;
}
<label><input type="checkbox"> Test</label>
Screenshots:
Chrome:
Firefox:
Edge:
Edge (legacy):
IE:
I think the simplest solution is re-style the checkbox as some users suggest. The CSS below is working for me, only requires a few lines of CSS, and answers the OP question:
input[type=checkbox] {
-webkit-appearance: none;
-moz-appearance: none;
vertical-align: middle;
width: 14px;
height: 14px;
font-size: 14px;
background-color: #eee;
}
input[type=checkbox]:checked:after {
position: relative;
bottom: 3px;
left: 1px;
color: blue;
content: "\2713"; /* check mark */
}
As mentioned in this post, the zoom property seems not to work on Firefox, and transforms may cause undesired effects.
Tested on Chrome and Firefox, should work for all modern browsers. Just change the properties (colors, size, bottom, left, etc.) to your needs. Hope it helps!
This should work
input {
width: 25px;
height: 25px;
}
It worked for me for Firefox and Chrome and iPhone's Firefox, Chrome and Safari at least.
I was looking to make a checkbox that was just a little bit larger and looked at the source code for 37Signals Basecamp to find the following solution-
You can change the font size to make the checkbox slightly larger:
font-size: x-large;
Then, you can align the checkbox properly by doing:
vertical-align: top;
margin-top: 3px; /* change to center it */
You can make checkboxes larger in Safari — which is generally resistant to the usual approaches — with this attribute: -webkit-transform: scale(1.3, 1.3);
Source
My reputation is slightly too low to post comments, but I made a modification to Jack Miller's code above in order to get it to not change size when you check and uncheck it. This was causing text alignment problems for me.
input[type=checkbox] {
width: 17px;
-webkit-appearance: none;
-moz-appearance: none;
height: 17px;
border: 1px solid black;
}
input[type=checkbox]:checked {
background-color: #F58027;
}
input[type=checkbox]:checked:after {
margin-left: 4px;
margin-top: -1px;
width: 4px;
height: 12px;
border: solid white;
border-width: 0 2px 2px 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
content: "";
display: inline-block;
}
input[type=checkbox]:after {
margin-left: 4px;
margin-top: -1px;
width: 4px;
height: 12px;
border: solid white;
border-width: 0;
-webkit-transform: rotate(45deg);
-moz-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
content: "";
display: inline-block;
}
<label><input type="checkbox"> Test</label>
My understanding is that this isn't easy at all to do cross-browser. Instead of trying to manipulate the checkbox control, you could always build your own implementation using images, javascript, and hidden input fields. I'm assuming this is similar to what niceforms is (from Staicu lonut's answer above), but wouldn't be particularly difficult to implement. I believe jQuery has a plugin to allow for this custom behavior as well (will look for the link and post here if I can find it).
I found this CSS-only library to be very helpful:
https://lokesh-coder.github.io/pretty-checkbox/
Or, you could roll your own with this same basic concept, similar to what #Sharcoux posted. It's basically:
Hide the normal checkbox (opacity 0 and placed where it would go)
Add a css-based fake checkbox
Use input:checked~div label for the checked style
make sure your <label> is clickable using for=yourinputID
.pretty {
position: relative;
margin: 1em;
}
.pretty input {
position: absolute;
left: 0;
top: 0;
min-width: 1em;
width: 100%;
height: 100%;
z-index: 2;
opacity: 0;
margin: 0;
padding: 0;
cursor: pointer;
}
.pretty-inner {
box-sizing: border-box;
position: relative;
}
.pretty-inner label {
position: initial;
display: inline-block;
font-weight: 400;
margin: 0;
text-indent: 1.5em;
min-width: calc(1em + 2px);
}
.pretty-inner label:after,
.pretty-inner label:before {
content: '';
width: calc(1em + 2px);
height: calc(1em + 2px);
display: block;
box-sizing: border-box;
border-radius: 0;
border: 1px solid transparent;
z-index: 0;
position: absolute;
left: 0;
top: 0;
background-color: transparent;
}
.pretty-inner label:before {
border-color: #bdc3c7;
}
.pretty input:checked~.pretty-inner label:after {
background-color: #00bb82;
width: calc(1em - 6px);
height: calc(1em - 6px);
top: 4px;
left: 4px;
}
/* Add checkmark character style */
.pretty input:checked~.pretty-inner.checkmark:after {
content: '\2713';
color: #fff;
position: absolute;
font-size: 0.65em;
left: 6px;
top: 3px;
}
body {
font-size: 20px;
font-family: sans-serif;
}
<div class="pretty">
<input type="checkbox" id="demo" name="demo">
<div class="pretty-inner"><label for="demo">I agree.</label></div>
</div>
<div class="pretty">
<input type="checkbox" id="demo" name="demo">
<div class="pretty-inner checkmark"><label for="demo">Please check the box.</label></div>
</div>
use this css code
input[type=checkbox]
{
/* Double-sized Checkboxes */
-ms-transform: scale(1.5); /* IE */
-moz-transform: scale(1.5); /* FF */
-webkit-transform: scale(1.5); /* Safari and Chrome */
-o-transform: scale(1.5); /* Opera */
transform: scale(1.5);
padding: 10px;
}
The problem is Firefox doesn't listen to width and height. Disable that and your good to go.
input[type=checkbox] {
width: 25px;
height: 25px;
-moz-appearance: none;
}
<label><input type="checkbox"> Test</label>
The other answers showed a pixelated checkbox, while I wanted something beautiful.
The result looks like this:
Even though this version is more complicated I think it's worth giving it a try.
.checkbox-list__item {
position: relative;
padding: 10px 0;
display: block;
cursor: pointer;
margin: 0 0 0 34px;
border-bottom: 1px solid #b4bcc2;
}
.checkbox-list__item:last-of-type {
border-bottom: 0;
}
.checkbox-list__check {
width: 18px;
height: 18px;
border: 3px solid #b4bcc2;
position: absolute;
left: -34px;
top: 50%;
margin-top: -12px;
transition: border .3s ease;
border-radius: 5px;
}
.checkbox-list__check:before {
position: absolute;
display: block;
width: 18px;
height: 22px;
top: -2px;
left: 0px;
padding-left: 2px;
background-color: transparent;
transition: background-color .3s ease;
content: '\2713';
font-family: initial;
font-size: 19px;
color: white;
}
input[type="checkbox"]:checked ~ .checkbox-list__check {
border-color: #5bc0de;
}
input[type="checkbox"]:checked ~ .checkbox-list__check:before {
background-color: #5bc0de;
}
<label class="checkbox-list__item">
<input class="checkbox_buttons" type="checkbox" checked="checked" style="display: none;">
<div class="checkbox-list__check"></div>
</label>
JSFiddle: https://jsfiddle.net/asbd4hpr/
You can change the height and width in the code below
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 20px;
width: 20px;
border-radius:5px;
border:1px solid #ff7e02;
}
<div class="check">
<label class="container1">Architecture/Landscape
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
</div>
Put the checkbox inside a parent with display:grid and make sure it doesn't have margin:auto
https://codepen.io/sneffel/pen/oNPYvBx
body{
text-align:center;
}
.grid{
display:grid;
}
input{
height:25px;
}
<div class="container grid">
<input type="checkbox" id="first">
</div>
<form class="container">
<input type="checkbox" id="second">
</form>