The standard checkboxes rendered in most browsers are quite small and don’t increase in size even when a larger font is used. What is the best, browser-independent way to display larger checkboxes?
In case this can help anyone, here's simple CSS as a jumping off point. Turns it into a basic rounded square big enough for thumbs with a toggled background color.
input[type='checkbox'] {
-webkit-appearance:none;
width:30px;
height:30px;
background:white;
border-radius:5px;
border:2px solid #555;
}
input[type='checkbox']:checked {
background: #abd;
}
<input type="checkbox" />
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 {
zoom: 2;
transform: scale(2);
-ms-transform: scale(2);
-webkit-transform: scale(2);
-o-transform: scale(2);
-moz-transform: scale(2);
transform-origin: 0 0;
-ms-transform-origin: 0 0;
-webkit-transform-origin: 0 0;
-o-transform-origin: 0 0;
-moz-transform-origin: 0 0;
}
<div class="double">
<input type="checkbox" name="hello" value="1">
</div>
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.
Try this CSS
input[type=checkbox] {width:100px; height:100px;}
<input type="checkbox" />
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);
}
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-size and it will grow with text!
input[type='checkbox'] {
-moz-appearance: none;
-webkit-appearance: none;
appearance: none;
vertical-align: middle;
outline: none;
font-size: inherit;
cursor: pointer;
width: 1.0em;
height: 1.0em;
background: white;
border-radius: 0.25em;
border: 0.125em solid #555;
position: relative;
}
input[type='checkbox']:checked {
background: #adf;
}
input[type='checkbox']:checked:after {
content: "✔";
position: absolute;
font-size: 90%;
left: 0.0625em;
top: -0.25em;
}
<label for="check1"><input type="checkbox" id="check1" checked="checked" /> checkbox one</label>
<label for="check2"><input type="checkbox" id="check2" /> another checkbox</label>
<label for="check3" style="font-size:150%"><input type="checkbox" id="check3" checked="checked" /> bigger checkbox </label>
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'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!
Related
Hi there I try to make it possible that you first need to click on the element and after that it should chang the background everytime you hover over it. Important is that No JavaScript or JQuery should be used. It's not a link so :visited and href is not an option
*Pseudocode*
*if* .lst-c:active *than* .lst-c:hover {
background: blue;
border-radius: 20px 20px 0px 0px !important;
}
You can try the Checkbox Hack
http://timpietrusky.com/advanced-checkbox-hack
input[type=checkbox] {
position: absolute;
top: -9999px;
left: -9999px;
}
div {
background: green;
}
input[type=checkbox]:checked ~ div:hover {
background: red;
}
<label for="toggle-1">Do Something</label>
<input type="checkbox" id="toggle-1">
<div>Control me</div>
Checkbox
/* Hide */
.is { display: none }
/* Is checked */
.is:checked + label .content:hover { background: blue; }
/* Not checked */
.content:hover { background: red; }
<input type="checkbox" class="is" id="clicker">
<label for="clicker">
<div class="content">Hello</div>
</label>
HTML:
<input type="checkbox" id="checkentire"> PLAY ENTIRE LESSON
<br>
<input type="checkbox" id="checkloop"> LOOP
CSS:
input[type=checkbox] {
width:45px;
margin:5px 0;
cursor:pointer;
vertical-align:middle;
}
input[type=checkbox]:hover {
background:lightgreen;
}
Problems:
1. input[type=checkbox]:hover - doesn't work at all.
2. cursor:pointer - works only on graphic symbol, not on text.
3. width:45px - increases graphic margins instead of graphic itself.
4. vertical-align:middle - graphic and text are not aligned.
5. turning on and off works only by clicking on graphic, instead on graphic and text.
You can wrap your checkbox element inside a wrapper element and work with relative and absolute positioning. That makes it easy to control the width and vertical alignment as well as the hovering state and the fact that you can click on the label text to check the checkbox.
Here is an example. This is actually kind of what bootstrap does.
.checkbox-wrapper {
position: relative;
display: inline-block;
width: auto;
margin-top: 10px;
margin-bottom: 10px;
background:tomato;
padding: 0 20px;
}
.checkbox-wrapper label {
display: inline-block;
max-width: 100%;
min-height: 40px;
line-height: 40px;
vertical-align: middle;
padding-left: 20px;
cursor: pointer;
}
.checkbox-wrapper input[type=checkbox] {
position: absolute;
margin: 0 0 0 -20px;
top: 50%;
transform: translate(0,-50%);
}
.checkbox-wrapper:hover {
background:lightgreen;
}
<div class="checkbox-wrapper">
<label for="checkentire">
<input type="checkbox" id="checkentire">
PLAY ENTIRE LESSON
</label>
</div>
You may try this to get your checkbox:hover working.
https://jsfiddle.net/k7hcgjk5/1/
In fact, you can not directly customize your checkbox. Instead, simply create a custom checkbox styled span which does that for you.
EDIT: Well, I forgot. Obviously, to handle your checked state, you need to add a customization for that as well. I updated the fiddle accordingly.
In many times to control the look and size of the checkbox you need to use "custom checkboxes", benefits are having consistent look on browsers (*), also you can have circles instead of squares, or blue instead of red, and you can have :hover for the label itself too, possibilities are many, just like this:
JS Fiddle -updated 2
#test-checkbox{
display:none;
}
#test-checkbox + label{
color:black;
cursor:pointer;
}
#test-checkbox:checked + label{
color:#0A0;
cursor:pointer;
}
#test-checkbox + label:hover{
outline:1px dotted blue;
outline-offset:4px;
}
#test-checkbox + label::before{
content:'';
width:12px;
height:12px;
display:inline-block;
border:2px solid #AAA;
border-radius:3px;
margin-right:5px;
cursor:pointer;
position:relative;
top:2px;
}
#test-checkbox:checked + label::after{
width:5px;
height:12px;
content:'';
display:inline-block;
border-right:4px solid #0A0;
border-bottom:4px solid #0A0;
position:absolute;
left:14px;
top:6px;
-ms-transform: rotate(45deg); /* IE 9 */
-webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
transform: rotate(45deg);
}
<input id="test-checkbox" type="checkbox">
<label for="test-checkbox">Check Me</label>
--------------------------------------------------------------------------------
(*) IE8 doesn't support the pseudo elements ::before and ::after which are the correct syntax, it supports :before and :after which are also supported by other browsers, for more information check ::before and ::after
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have several html checkboxes I'd like to style like a paper form:
Is there any way to do this with CSS?
Is there any way to build a control that looks like this but acts like a checkbox?
When the box is checked, there should be an X in it:
Update
For those of you looking for a similar question: Make checkbox in chrome look like one in IE
This one has some pretty good answers also.
Here is a solution based on your mockups:
body {
font-family: Arial, sans-serif;
}
/* Hide default checkbox */
input[type=checkbox] {
display: none;
}
/* Style custom checkbox (indicated by <span>) that corresponds to its hidden version */
input[type=checkbox] + label span {
border: 1px solid #000;
display: inline-block;
width: 15px;
height: 15px;
margin: 0 4px 0 8px;
padding: 2px;
text-align: center;
vertical-align: middle;
cursor: pointer;
}
/* 'Checked' state */
input[type=checkbox]:checked + label span::after {
content: "X";
}
<form>
Occupant
<input type="checkbox" id="owner" name="occ" value="Owner"/>
<label for="owner"><span></span>Owner</label>
<input type="checkbox" id="tenant" name="occ" value="Tenant"/>
<label for="tenant"><span></span>Tenant</label>
<input type="checkbox" id="vacant" name="occ" value="Vacant"/>
<label for="vacant"><span></span>Vacant</label>
</form>
You could try something like this but you need to create your checkbox images, to use it.
input[type=checkbox] {
position: relative;
visibility: hidden;
cursor: pointer;
}
input[type=checkbox]:after {
display: block;
content: "";
position: absolute;
top: 0;
right: -30px;
visibility: visible;
height: 50px;
width: 50px;
text-align: center;
border-radius: 4px;
background:url(http://www.clipartbest.com/cliparts/yTo/gj4/yTogj4zEc.png);
background-size:100%;
color: #fff;
font-weight: 600;
cursor: pointer;
}
input[type=checkbox]:checked:after {
content: "";
background: url(http://www.clipartbest.com/cliparts/ncX/jL6/ncXjL6rcB.png);
background-size:100%;
}
<input type="checkbox" />
JSFiddle
Mozilla FireFox UPDATE
Using just some dummy elements, for here using label and using it by applying CSS to it.
label.checkbox input[type="checkbox"] {display:none;}
label.checkbox span {
display:inline-block;
width:25px; /* This must be depend on image resolution */
height:25px; /* This must be depend on image resolution */
background:url(http://www.clipartbest.com/cliparts/yTo/gj4/yTogj4zEc.png);
background-size:100%;
-moz-background-size:100%;
background-repeat:no-repeat;
vertical-align:middle;
margin:3px;
}
label.checkbox :checked + span {
background:url(http://www.clipartbest.com/cliparts/ncX/jL6/ncXjL6rcB.png);
background-size:100%;
-moz-background-size:100%;
}
<label class="checkbox"><input type="checkbox"/><span></span> Whatever you wanna say here... </label>
Note : But still will not work in old browsers
HTML
< span onclick="this.innerHTML = (this.innerHTML ? '' : 'X')">
CSS
span{
display:inline-block;
width:15px;
height:15px;
font:14px verdana;
border:solid 1px black;
color:green;
vertical-align:baseline;
cursor:pointer;}
http://jsfiddle.net/ApHME/59/
It's possible to hide the real input[type=checkbox] and use an :after pseudo-element to create anything you want in front of the checkbox. Here's a question with a similar problem: css only checkbox (with content attribute). Then just use CSS the way you want to stylize it.
This question already has answers here:
Styling input radio with css [duplicate]
(5 answers)
Closed 4 years ago.
I have a website where I'm trying to change the background color of the dot of a radio button. Right now it seems to be transparent so it gets the color of whatever the background is. I tried using CSS and setting "background: white;" for example, however this has no effect in the browser. Any ideas of cool tricks to use to achieve this?
Same question stands for checkbox as well.
jsBin demo
This technique uses the label element bound to hidden input elements, that receiving a :checked state will change the apperance of the :before pseudo element:
/* COMMON RADIO AND CHECKBOX STYLES */
input[type=radio],
input[type=checkbox]{
/* Hide original inputs */
visibility: hidden;
position: absolute;
}
input[type=radio] + label:before,
input[type=checkbox] + label:before{
height:12px;
width:12px;
margin-right: 2px;
content: " ";
display:inline-block;
vertical-align: baseline;
border:1px solid #777;
}
input[type=radio]:checked + label:before,
input[type=checkbox]:checked + label:before{
background:gold;
}
/* CUSTOM RADIO AND CHECKBOX STYLES */
input[type=radio] + label:before{
border-radius:50%;
}
input[type=checkbox] + label:before{
border-radius:2px;
}
<input type="radio" name="r" id="r1"><label for="r1">Radio 1</label>
<input type="radio" name="r" id="r2"><label for="r2">Radio 2</label>
<input type="checkbox" name="c1" id="c1"><label for="c1">Check 1</label>
<input type="checkbox" name="c2" id="c2"><label for="c2">check 2</label>
It's been well stablished that you cannot change every detail on browser generated controls. For example the color of the arrow on a select dropdown, or the dot of a radio, etc...
You can create your custom controls, use some library like JQuery UI, or.... maybe play around a little with css.
Here's an experiment to fake a colored dot on a radio, using :before pseudo element:
http://jsfiddle.net/bvtngh57/
input[type="radio"]:checked:before {
content: "";
display: block;
position: relative;
top: 3px;
left: 3px;
width: 6px;
height: 6px;
border-radius: 50%;
background: red;
}
Result:
The preferred method for styling the non-label elements of checkboxes and radio buttons with CSS is to essentially replace them with images that represent their current state (unchecked, checked, etc).
See this article by Ryan Seddon: http://www.thecssninja.com/css/custom-inputs-using-css
The browser itself handles the look of radio buttons and checkboxes, as well as dropdown/selects. You can however hide the radio buttons, replace them with images, and then modify your radio/check value using jQuery. Font Awesome (http://fortawesome.github.io/Font-Awesome/icons/) has some cool icons that you can use for this.
Here is a demo
<div>
Radio 1 -
<input type="radio" name="radio" class="radio" value="1" />
<span class="red fa fa-circle-o"></span>
</div>
<div>
Radio 2 -
<input type="radio" name="radio" class="radio" value="2" />
<span class="blue fa fa-circle-o"></span>
</div>
$('span.fa').on('click', function() {
$('span.fa').removeClass('fa fa-dot-circle-o').addClass('fa fa-circle-o');
$(this).removeClass('fa-circle-o').addClass('fa-dot-circle-o');
//Check corresponding hidden radio
$(this).prev('input.radio').prop('checked', true);
});
There are many ways to do this, all of them involve to get rid of the DOM styles since it's impossible to do it without these "tricks". Here's a sample by Chris Coyier (just read the page, skip step 1 and simply prepare teh images and CSS)
/*
Hide the original radios and checkboxes
(but still accessible)
:not(#foo) > is a rule filter to block browsers
that don't support that selector from
applying rules they shouldn't
*/
li:not(#foo) > fieldset > div > span > input[type='radio'],
li:not(#foo) > fieldset > div > span > input[type='checkbox'] {
/* Hide the input, but have it still be clickable */
opacity: 0;
float: left;
width: 18px;
}
li:not(#foo) > fieldset > div > span > input[type='radio'] + label,
li:not(#foo) > fieldset > div > span > input[type='checkbox'] + label {
margin: 0;
clear: none;
/* Left padding makes room for image */
padding: 5px 0 4px 24px;
/* Make look clickable because they are */
cursor: pointer;
background: url(off.png) left center no-repeat;
}
/*
Change from unchecked to checked graphic
*/
li:not(#foo) > fieldset > div > span > input[type='radio']:checked + label {
background-image: url(radio.png);
}
li:not(#foo) > fieldset > div > span > input[type='checkbox']:checked + label {
background-image: url(check.png);
}
You can style ionic radio buttons using css alone. Check the fiddle:
https://jsfiddle.net/sreekanthjayan/0d9vj86k/
<div>
<ion-radio class="radio radio-inline radio-gray" ng-model="choice" ng-value="'A'">iOS</ion-radio>
<ion-radio class="radio radio-inline radio-teal" ng-model="choice" ng-value="'B'">Android</ion-radio>
<ion-radio class="radio radio-inline radio-blue" ng-model="choice" ng-value="'C'">Windows Phone</ion-radio>
</div>
.radio .radio-icon {
visibility: visible !important;
}
.radio .radio-icon:before {
content: "" !important;
border: 2px solid black !important;
width: 24px !important;
height: 24px !important;
border-radius: 50% !important;
overflow: hidden !important;
}
.radio .radio-icon:after {
content: "" !important;
position: absolute !important;
right: 20px !important;
top: 22px !important;
background: black !important;
width: 12px !important;
height: 12px !important;
border-radius: 50% !important;
overflow: hidden !important;
transition: -webkit-transform .28s cubic-bezier(0.420, 0.000, 0.000, 1.650);
transition: transform .28s cubic-bezier(0.420, 0.000, 0.000, 1.650);
-webkit-transform: scale(0);
transform: scale(0);
}
.radio.item-radio > input[type=radio]:checked ~ .radio-icon:after {
-webkit-transform: scale(1);
transform: scale(1);
}
.radio .item-content {
background-color: #fff;
margin: 0;
padding-right: 50px;
padding-left: 0px;
}
.radio.item-radio > input[type=radio]:checked ~ .item-content {
background-color: #fff;
}
.radio-inline.item {
display: inline-block;
border: none;
margin: 0;
height: 50px;
}
.radio-blue .radio-icon:after {
background: #2196F3 !important;
}
.radio-blue .radio-icon:before {
border-color: #2196F3 !important;
}
.radio-teal .radio-icon:after {
background: #009688 !important;
}
.radio-teal .radio-icon:before {
border-color: #009688 !important;
}
.radio-gray .radio-icon:after {
background: #B6B6B6 !important;
}
.radio-gray .radio-icon:before {
border-color: #B6B6B6 !important;
}
I am using the check box for an image; it is working fine in Chrome but not in the Firefox so i try so many times to solve this problem but not yet i find it.
This check box i am using in the mailpoet newsletter plugin and connected with my style.css
Html code
<p class="wysija-checkbox-paragraph"><label><input class="wysija-checkbox validate[required]" name="wysija[user_list][list_id][]" type="checkbox" value="3" checked="checked" /> Monthly Printed</label>
</p>
<p> <label class="wysija-checkbox-label"><input class="wysija-checkbox " type="checkbox" name="wysija[field][cf_2]" value="1" />Anboli Daily Email Edition</label></p>
style.css
.checkbox /*before checked the check box*/
{
display: inline-block;
width: 35px;
height: 35px;
margin: -10px 5px 0 0;
vertical-align: middle;
background: url (http://example.com/uploads/2014/04/chk.jpg) left -35px no-repeat;
cursor: pointer;
}
.checkbox:checked /*after checked*/
{
background: url(http://example.com/uploads/2014/04/chk.jpg) left 0px no-repeat;
}
help me to solve this problem.
I made a generic sample below, using almost the same structure as you. What I did was I put the label after the checkbox, and hid the check box by giving it a width and height of 0. Then I used the css '+' selector to select the label directly after a checked checkbox and change the background of that label. Of course, the label will now act as a checkbox because clicking on a label still checks the hidden checkbox!
HTML:
<input type="checkbox" name="checkbox" id="check1"/>
<label for="check1"></label>
CSS:
/*before check*/
label{
display: inline-block;
margin: -10px 5px 0 0;
width: 35px;
height: 35px;
background: url (http://example.com/uploads/2014/04/chk.jpg) left -35px no-repeat;
cursor: pointer;
}
/*after check*/
input[type=checkbox]:checked + label{
background: url(http://example.com/uploads/2014/04/chk.jpg) left 0px no-repeat;
}
/*hide the checkbox*/
input[type=checkbox]{
height: 0em;
width: 0em;
background: none;
}