Custom style radiobuttons - html

I want to style my radio buttons so that that black dot inside the circle is for example red.
There are several examples available on the internet like this one: JSFIDDLE. The thing with this example is that it does not work in Internet Explorer.
Another point that makes my situation harder is that I can not, due to implementation requirements, add any other html objects to the following code:
<span class="custom-radio">
<input id="id4" type="radio" name="id_test" value="">
<label for="id4">No</label>
</span>
My question is: how can I create a custom radiobutton without adding extra HTML to the code above and still make it work in most browsers (IE, FF, Chrome)

You can hide the input itself with display:none and the use a pseudo-element on the label
input[type='radio'] {
display: none;
}
input[type='radio'] + label {
position: relative;
line-height: 1em;
}
input[type='radio'] + label:before {
content: '';
width: .5em;
height: .5em;
border-radius:100%;
margin-right: .5em;
display: inline-block;
background: red;
vertical-align: middle;
box-shadow: 0 0 0 .1em white, 0 0 0 .2em black;
}
input[type='radio']:checked + label:before {
background: green;
vertical-align: middle;
}
<span class="custom-radio">
<input id="id4" type="radio" name="id_test" value=""/>
<label for="id4">No</label>
</span>
After that it's just a matter of styling the pseudo-element to taste,

for something like changing the colour of the tick/ball you can use ::before:
input:checked ~ label::before{
content: "";
background: #F90 none repeat scroll 0% 0%;
width: 8px;
height: 8px;
position: absolute;
border-radius: 20px;
left: 7px;
top: 5px;
}
here's a fiddle
n.b. You'd be positioning the ::before element, so this would need tweeking to the correct position when used in your application

You cannot do that in IE because it does not allow you to use :before on input elements, at least according to this answer. I think the only thing you can do in your situation is to try adding :before on the label and position it over the checkbox.

Try this link
Styling Radio Buttons with CSS
Update : code (copy/past from above link):
<input id="choice-a" type="radio" name="g" />
<label for='choice-a'>
<span><span></span></span>
Choice A
</label>
input[type="radio"] {
opacity: 0;
position: absolute;
}
/* Matches the direct descendant of a label preceded by a
radio button */
input[type="radio"] + label > span {
position: relative;
border-radius: 14px;
width: 20px;
height: 20px;
background-color: #f0f0f0;
border: 1px solid #bcbcbc;
box-shadow: 0px 1px 3px rgba(0, 0, 0, 0.2);
margin: 0 1em 0 0;
display: inline-block;
vertical-align: middle;
}
/* Matches the direct descendant of a label preceded by a
checked radio button */
input[type="radio"]:checked + label > span {
background: linear-gradient(#a0e5f8, #75c7dc);
background: -webkit-linear-gradient(#a0e5f8, #75c7dc);
border-color: #41a6bf;
box-shadow: 0px 1px 2px rgba(65, 166, 191, 0.9) inset;
}
/* Matches a span contained by the direct descendant
of a label preceded by a checked radio button */
input[type="radio"]:checked + label > span span {
display: inline-block;
width: 8px;
height: 8px;
position: absolute;
left: 6px;
top: 6px;
border-radius: 5px;
border: none;
background: #167c95;
box-shadow: 0px 1px rgba(255, 255, 255, 0.3);
}
input[type="radio"]:focus + label > span {
box-shadow: 0px 0px 6px rgba(63, 165, 190, 1);
}
Fiddle example

Simply use a combination of hidden radio input elements and styled span elements wrapped in label elements, styled accordingly:
input[type=radio] {
display: none;
}
span {
border-radius: 100%;
height: 20px;
width: 20px;
display: inline-block;
border: 1px solid;
position: relative;
}
input[type=radio]:checked + span:before {
content: '';
position: absolute;
height: 50%;
width: 50%;
top: 50%;
left: 50%;
transform: translateY(-50%) translateX(-50%);
background: green;
border-radius: 100%;
}
<label>
<input type="radio" name="myRadio" />
<span></span>Item 1
</label>
<label>
<input type="radio" name="myRadio" />
<span></span>Item 2
</label>
<label>
<input type="radio" name="myRadio" />
<span></span>Item 3
</label>

You cannot change the properties of radio buttons or checkboxes, but you can simulate them. Keep your HTML the same, and add this to your CSS.
.custom-radio input[type=radio] {
display:none;
}
.custom-radio label {
display:inline-block;
}
.custom-radio label:before {
content:"";
display:inline-block;
width:16px;
height:16px;
border-radius:50%;
background:url("http://s17.postimg.org/p1q2imsln/radio.png");
background-position:0% 0%;
}
.custom-radio label:hover:before {
background-position:0% 100%
}
.custom-radio input[type=radio]:checked~label:before {
background-position:100% 0%;
}
.custom-radio input[type=radio]:checked~label:hover:before {
background-position:100% 100%;
}
Simply provide an image that follows the template in the link that has red radio buttons.

Why even use the input[type="radio"] element at all? You can recreate in in html, css, and javascript and offer better browser support than any crazy css :before, :after stuff. Here is the code and a working jsfiddle:
Here is a link to the fiddle: https://jsfiddle.net/www139/ba5jn2e6/19/
Hope this helps anyone else with the issue. I experienced the same dilemma, so I decided to create it from scratch!
window.onload = function(){
var radioButtonGroups = document.getElementsByClassName('radioGroupContainer');
for(var i = 0; i != radioButtonGroups.length; i++)
{
var radioButtons = radioButtonGroups[i].getElementsByClassName('radioButtonContainer');
for(var i = 0; i != radioButtons.length; i++)
{
radioButtons[i].onclick = function(){
var value = this.children[0].getAttribute('name');
for(var i = 0; i != radioButtons.length; i++)
{
radioButtons[i].children[0].setAttribute('class','radioButtonDot');
}
this.children[0].setAttribute('class','radioButtonDotActive');
this.parentNode.setAttribute('name',value);
};
}
}
};
/*
* Created by William Green.
* Questions or comments? Email william.green#protonmail.com
* I would appreciate credit for this code if you use it; but it is not required.
* Last updated July 26, 2015
* Created July 26, 2015
*
*/
.radioButtonContainer {
background-color:#eee;
padding:5px;
-moz-border-radius:3px;
-webkit-border-radius:3px;
border-radius:3px;
display:table;
margin-top:5px;
margin-bottom:5px;
}
.radioButtonContainer .radioButtonDot {
width:16px;
height:16px;
background-color:transparent;
border:1px solid #000;
display:inline-block;
vertical-align:middle;
-moz-border-radius:50%;
-webkit-border-radius:50%;
border-radius:50%;
-o-transition:all .5s ease;
-moz-transition:all .5s ease;
-webkit-transition:all .5s ease;
-ms-transition:all .5s ease;
transition:all .5s ease;
}
.radioButtonContainer .radioButtonDotActive {
width:16px;
height:16px;
background-color:#1396DE;
border:1px solid transparent;
display:inline-block;
vertical-align:middle;
-moz-border-radius:50%;
-webkit-border-radius:50%;
border-radius:50%;
-o-transition:all .5s ease;
-moz-transition:all .5s ease;
-webkit-transition:all .5s ease;
-ms-transition:all .5s ease;
transition:all .5s ease;
}
.radioButtonContainer .radioButtonLabel {
background-color:transparent;
display:inline-block;
vertidal-align:middle;
border:0;
}
<div class="radioGroupContainer" id="radioChoicesOne">
<div class="radioButtonContainer">
<div class="radioButtonDot" name="optionOne"></div>
<input type="button" class="radioButtonLabel" value="Option One">
</div>
<div class="radioButtonContainer">
<div class="radioButtonDot" name="optionTwo"></div>
<input type="button" class="radioButtonLabel" value="Option Two">
</div>
<div class="radioButtonContainer">
<div class="radioButtonDot" name="optionThree"></div>
<input type="button" class="radioButtonLabel" value="Option Three">
</div>
</div>
<div id="radioButtonGroupOneValue"></div>
<input type="button" value="Get radio button value..." onclick="document.getElementById('radioButtonGroupOneValue').innerHTML = document.getElementById('radioChoicesOne').getAttribute('name');">

Related

Input options (radio and checkbox) has buttons with icons

Is there any library available that converts options or radion inputs has selectble buttons with icons? Example of what type of styling looking for is above.
I'm not sure stackoverflow is the right place to ask these kinda questions, but these are useful for you:
1. <http://codepen.io/DavidBradbury/pen/HuCqx>
2. https://gist.github.com/rcotrina94/7828886
3. Use Image instead of radio button
And you possibly duplicating the last one.
This snippet from codepen, here to stay:
.input-hidden {
position: absolute;
left: -9999px;
}
input[type=radio]:checked + label>img {
border: 1px solid #fff;
box-shadow: 0 0 3px 3px #090;
}
/* Stuff after this is only to make things more pretty */
input[type=radio] + label>img {
border: 1px dashed #444;
width: 150px;
height: 150px;
transition: 500ms all;
}
input[type=radio]:checked + label>img {
transform:
rotateZ(-10deg)
rotateX(10deg);
}
/*
| //lea.verou.me/css3patterns
| Because white bgs are boring.
*/
html {
background-color: #fff;
background-size: 100% 1.2em;
background-image:
linear-gradient(
90deg,
transparent 79px,
#abced4 79px,
#abced4 81px,
transparent 81px
),
linear-gradient(
#eee .1em,
transparent .1em
);
}
<input
type="radio" name="emotion"
id="sad" class="input-hidden" />
<label for="sad">
<img
src="//placekitten.com/150/150"
alt="I'm sad" />
</label>
<input
type="radio" name="emotion"
id="happy" class="input-hidden" />
<label for="happy">
<img
src="//placekitten.com/151/151"
alt="I'm happy" />
</label>
You don't need a library to do it.
HTML:
<input type="radio" id="example"/>
<label for="example"><i>youricon</i>Text</label>
CSS:
input[type="radio"] {
display: none;
}
label {
//......button layout
}
You can make this yourself, this easy, do changes background-images
<label class="check">
<input type="checkbox">
<span>Value</span>
</label>
CSS
.check {
position: relative;
padding-left: 40px;
}
.check input {
opacity: 0;
transform: scale(0);
}
.check span:before {
content: '';
display: block;
width: 40px;
height: 40px;
position: absolute;
left: 0;
top: 0;
background:#000;
}
.check input:checked + span:before {
background: red;
}
Live demo JsFiddle - https://jsfiddle.net/grinmax_/7fpbkz9s/

Move placeholder above the input on focus

I'm looking for css code that move the placeholder text above the input on focus. I found this code here. This code is perfect but my input tag is wrapped inside <span> and for that reason general sibling selector is not working. Any ideas how to edit this css?
<div>
<span class='blocking-span'>
<input type="text" class="inputText" />
</span>
<span class="floating-label">Your email address</span>
</div>
You can use the CSS pseudo-selector :placeholder-shown in this case to detect when to move a fake placeholder out of the way. See example below:
label {
margin:20px 0;
position:relative;
display:inline-block;
}
span {
padding:10px;
pointer-events: none;
position:absolute;
left:0;
top:0;
transition: 0.2s;
transition-timing-function: ease;
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
opacity:0.5;
}
input {
padding:10px;
}
input:focus + span, input:not(:placeholder-shown) + span {
opacity:1;
transform: scale(0.75) translateY(-100%) translateX(-30px);
}
/* For IE Browsers*/
input:focus + span, input:not(:-ms-input-placeholder) + span {
opacity:1;
transform: scale(0.75) translateY(-100%) translateX(-30px);
}
<label>
<input placeholder=" ">
<span>Placeholder Text</span>
</label>
With the given links CSS etc, simply move the floating-label inside the blocking-span.
By using position: relative on the div the floating-label will still re-position as if it were outside the blocking-span
div {
position: relative; /* make label relate to div */
padding-top: 10px; /* make space for label */
}
.inputText {
font-size: 14px;
width: 200px;
height: 25px;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 15px;
top: 18px;
transition: 0.2s ease all;
}
input:focus ~ .floating-label,
input:not(:focus):valid ~ .floating-label {
top: -6px;
}
<div>
<span class='blocking-span'>
<input type="text" class="inputText" required/>
<span class="floating-label">Your email address</span>
</span>
</div>
If you change html structure then your reference example is work but if you don't want change html structure then you need to write little jQuery. You can check this.
$(function(){
$('.blocking-span input').on('focus', function(){
$(this).parents('.parents-elm').addClass('foucs-content'); // When focus the input area
});
$(document).mouseup(function(e){
if($(e.target).parents('.blocking-span input').length==0 && !$(e.target).is('.blocking-span input')){
$('.parents-elm').removeClass('foucs-content');
}
});
});
div{
position: relative;
}
.blocking-span{
display: block;
}
.blocking-span input{
border: 1px solid #eaeaea;
height: 80px;
padding-top: 30px;
padding-left: 20px;
padding-right: 20px;
width: 100%;
}
.floating-label{
display: inline-block;
font-size: 15px;
left: 20px;
line-height: 20px;
position: absolute;
top: -webkit-calc(50% - 10px);
top: -moz-calc(50% - 10px);
top: calc(50% - 10px);
transition: top 0.3s ease-in-out 0s;
}
.foucs-content .floating-label{
top: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="parents-elm">
<span class='blocking-span'>
<input type="text" class="inputText" />
</span>
<span class="floating-label">Your email address</span>
</div>
I have used contact form 7 and it gaves me this additional span. But I already found solution how to block this additional span. There is a filter that can remove this contact form 7 span. Here is the link.

Place a label on top of a span for a custom checkbox

I am trying to build a set of custom checkboxes that change label color and background when checked.
Essentially I am trying to synthesize these two ideas:
1) putting a number inside of a circle How to use CSS to surround a number with a circle?
2) creating custom checkboxes using spans and the ":checked" attribute
http://webdesign.tutsplus.com/tutorials/htmlcss-tutorials/quick-tip-easy-css3-checkboxes-and-radio-buttons/
So far, I haven't been able to figure out how to get a label, controlled by the ':checked' state, to sit in the middle of the checkbox.
Here is my progress thus far:
http://jsfiddle.net/Cg9eX/
css
input[type="checkbox"] {
display:none;
}
input[type="checkbox"] + label span {
display:inline-block;
width:30px;
height:30px;
margin: 0 4px 0 0;
vertical-align:middle;
background: none;
cursor:pointer;
line-height: 14px;
text-align: center;
border: solid 1px #000000;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
}
input[type="checkbox"]:checked + label span {
background-color: rgba(153, 153, 153, .7);
border: none;
}
input[type="checkbox"]:checked + label {
color: white;
}
html
<input type="checkbox" id="c1" name="cc" />
<label for="c1"><span></span>4</label>
Is this what you're trying to achieve?
http://jsfiddle.net/Cg9eX/1/
I have placed the number inside the <span> tags.
Placing the number inside the <span> solves most of the problem.
The adjust the line-height to the same as the element height.
JSFiddle Demo
HTML
<input type="checkbox" id="c1" name="cc" />
<label for="c1"><span>4</span></label>
CSS
input[type="checkbox"] {
display:none;
}
input[type="checkbox"] + label span {
display:inline-block;
width:30px;
height:30px;
line-height:30px;
margin: 0 4px 0 0;
vertical-align:middle;
background: none;
cursor:pointer;
text-align: center;
border: solid 1px #000000;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
}
input[type="checkbox"]:checked + label span {
background-color: rgba(153, 153, 153, .7);
border: none;
}
input[type="checkbox"]:checked + label {
color: green;
}

Style a checkbox in firefox — remove check and border

How do I style a checkbox in firefox, and have the checkmark and border disappear?
http://jsfiddle.net/moneylotion/qZvtY/
CSS:
body { background: black; }
#conditions-form { color: white; }
#conditions-form input[type=checkbox] {
display:inline-block;
-webkit-appearance: none;
-moz-appearance: none;
-o-appearance:none;
appearance: none;
width:19px;
height:19px;
background: url('http://demo.somedomain.com/wp-content/themes/themename/images/care-plan-checkbox.gif') no-repeat top left;
cursor:pointer;
}
#conditions-form input[type=checkbox]:checked {
background:url('http://demo.somedomain.com/wp-content/themes/themename/images/care-plan-checkbox-checked.gif') no-repeat top left;
}
HTML:
<form id="conditions-form">
<ul>
<li>
<input id="condition3" type="checkbox" name="conditions[condition3]"></input>
<label class="checkbox" for="condition3">Conditions 3</label>
</li>
</ul>
</form>
There's a quite easy way you can do this via <label> tags. Just place a label around the checkbox, and insert a dummy element that will be used for the custom styled checkbox. For example:
label.checkbox input[type="checkbox"] {display:none;}
label.checkbox span {
display:inline-block;
border:2px solid #BBB;
border-radius:10px;
width:25px;
height:25px;
background:#C33;
vertical-align:middle;
margin:3px;
position: relative;
transition:width 0.1s, height 0.1s, margin 0.1s;
}
label.checkbox :checked + span {
background:#6F6;
width:27px;
height:27px;
margin: 2px;
}
label.checkbox :checked + span:after {
content: '\2714';
font-size: 20px;
position: absolute;
top: -2px;
left: 5px;
color: #99a1a7;
}
<label class="checkbox">
<input type="checkbox"/>
<span></span>
I like cake
</label>
EDIT: Note that some choices of colours might render the state of your checkbox invisible for colourblind people. When making this code I didn't think of that, but the above demo might be invisible for R/G colourblind people. When implementing this, please do keep that in mind (pick bright/dark colours for example, or show some difference in shape)
The styles I used are just arbitrary, and you can change that to anything you want. You can even toggle certain text inside it via the ::before pseudo-element, such as what I've done here.
I wasn't able to open the image url you provided to use in your question, but I think you'll be able to include whatever image you want by simply modifying this code a little. Just change the current background color to the image URL you want to use.
Note: This won't work in some older browsers.
The accepted answer above is great but this slight tweak to the fiddle from Joeytje50 allows the check-boxes to be tabbed to.
Using opacity 0 instead of display none means the checkbox is still tabbable and hence accessible by keyboard.
Position absolute places the input checkbox top left of the drawn box meaning your formatting stays neat.
input[type="checkbox"] {
opacity: 0;
position: absolute;
}
input[type="checkbox"] + label {
text-align:center;
cursor:pointer;
}
input[type="checkbox"]:focus + label {
background-color: #ddd;
}
input[type="checkbox"] + label div {
display:inline-block;
line-height: 16px;
font-size: 12px;
height: 16px;
width: 16px;
margin:-0px 4px 0 0;
border: 1px solid black;
color: transparent;
}
input[type="checkbox"]:checked + label div {
color: black;
}
<input type="checkbox" id="c1" name="cc" />
<label for="c1">
<div>✔</div>Check Box 1<br />
</label>
<input type="checkbox" id="c12" name="cc" />
<label for="c12">
<div>✔</div>Check Box 2<br />
</label>
This tutsplus tutorial solved my question.
input[type="checkbox"] {
display:none;
}
input[type="checkbox"] + label span {
display:inline-block;
width:19px;
height:19px;
margin:-1px 4px 0 0;
vertical-align:middle;
background:url(https://cdn.tutsplus.com/webdesign/uploads/legacy/tuts/391_checkboxes/check_radio_sheet.png) left top no-repeat;
cursor:pointer;
}
input[type="checkbox"]:checked + label span {
background:url(https://cdn.tutsplus.com/webdesign/uploads/legacy/tuts/391_checkboxes/check_radio_sheet.png) -19px top no-repeat;
}
<input type="checkbox" id="c1" name="cc" />
<label for="c1"><span></span>Check Box 1</label>
A cleaner solution IMHO that uses pure css to redraw the elements.
Codepen
input[type="checkbox"] {
opacity: 0;
position: absolute;
}
input[type="checkbox"] ~ label:before {
content: '';
display: inline-block;
cursor: pointer;
...
border: 3px solid #999;
border-radius: 2px;
transition: .3s;
}
input[type="checkbox"]:checked ~ label:before {
background: #333;
}

CSS/HTML: How do I change the color of the check mark within the checkbox input? [duplicate]

This question already has answers here:
How to style a checkbox using CSS
(43 answers)
Closed 1 year ago.
How do I change the color of the check mark within an HTML checkbox input?
Here's a pure CSS solution that shouldn't break screen readers or default user agent actions. Additionally, this is supported in the latest versions of the big 4 browsers (and a few others if you add some additional hacks, but I'll leave that to you to figure out; probably won't get more than IE8+ support since it uses pseudo elements).
The idea is to hide the actual form element (because browsers do a hard replace with internal styles and don't expose all style-ability to css yet) and replace it with one we like. One side effect is that you will want to track change events rather than click events in your JS if you need it (but you were doing that anyway right?).
Because the label is tied to the form element clicking it works like one would expect, so the new, awesome, checkbox (::before) abuses attribute selectors ([checked]) on the original to check if it is checked. When it is checked it will display our awesomer checkmark (::after).
The checkmark (::after) abuses border width for thickness and height/width for making a checkmark like item. Finally, we transform the box 45deg to match the angle up properly.
To change the color of the checkmark, change the border color on the ::after style. Additionally, if you wanted it to always match your text color remove the border color on it altogether. To change the radio, change the radial gradient start color (the one that isn't white).
Also awesome is that its tied to font size, so if your text is bigger, it should shim right in (though rounding errors can happen when using relative font sizes, so be careful)
I've included basic styles for both check-able types (checkbox and radio).
HTML:
<fieldset>
<legend>Checkbox example</legend>
<input id="checkbox" type="checkbox"/>
<label for="checkbox">Some awesome checkbox label</label>
</fieldset>
<fieldset>
<legend>Radio example</legend>
<div>
<input id="radio1" type="radio" name="radio"/>
<label for="radio1">Some awesome radio option #1</label>
<div>
</div>
<input id="radio2" type="radio" name="radio"/>
<label for="radio2">Some awesome radio option #2</label>
</div>
</fieldset>
CSS:
label, input[type="radio"], input[type="checkbox"] {
line-height: 2.1ex;
}
input[type="radio"],
input[type="checkbox"] {
position: absolute;
left: -999em;
}
input[type="radio"] + label,
input[type="checkbox"] + label {
position: relative;
overflow: hidden;
cursor: pointer;
}
input[type="radio"] + label::before,
input[type="checkbox"] + label::before {
content: "";
display: inline-block;
vertical-align: -25%;
height: 2ex;
width: 2ex;
background-color: white;
border: 1px solid rgb(166, 166, 166);
border-radius: 4px;
box-shadow: inset 0 2px 5px rgba(0,0,0,0.25);
margin-right: 0.5em;
}
input[type="radio"]:checked + label::before {
background: radial-gradient(circle at center, #1062a4 .6ex, white .7ex);
}
input[type="radio"] + label::before {
border-radius: 50%;
}
input[type="checkbox"]:checked + label::after {
content: '';
position: absolute;
width: 1.2ex;
height: 0.4ex;
background: rgba(0, 0, 0, 0);
top: 0.9ex;
left: 0.4ex;
border: 3px solid #1062a4;
border-top: none;
border-right: none;
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
transform: rotate(-45deg);
}
Side note: necropost because this was the first question that popped up when I was trying to remember how I pulled this off in the past. ;)
You could create a checkbox image and use that as your checkbox
The following post discusses custom input controls...
http://www.thecssninja.com/css/custom-inputs-using-css
If you need to change tick color from black to white, just try applying filter: invert(1) to the checkbox.
Check this It will Show you how to style a checkbox
How to create a custom checkbox You can do it without JS
/* Customize the label (the container) */
.container {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default checkbox */
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
}
/* On mouse-over, add a grey background color */
.container:hover input ~ .checkmark {
background-color: #ccc;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.container input:checked ~ .checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.container .checkmark:after {
left: 9px;
top: 5px;
width: 5px;
height: 10px;
border: solid white;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
/* When the checkbox is checked, add a blue background */
.container input:checked ~ .checkmark {
background-color: #2196F3;
}
.container input.white:checked ~ .checkmark:after {
border: solid white;
border-width: 0 3px 3px 0;
}
.container input.black:checked ~ .checkmark:after {
border: solid #000;
border-width: 0 3px 3px 0;
}
.container input.red:checked ~ .checkmark:after {
border: solid #cb1a1a;
border-width: 0 3px 3px 0;
}
.container input.green:checked ~ .checkmark:after {
border: solid #1f4f12;
border-width: 0 3px 3px 0;
}
.container input.yellow:checked ~ .checkmark:after {
border: solid #c6c253;
border-width: 0 3px 3px 0;
}
<label class="container">Black
<input type="checkbox" class="black" checked="checked">
<span class="checkmark"></span>
</label>
<label class="container">White
<input type="checkbox" class="white">
<span class="checkmark"></span>
</label>
<label class="container">Yellow
<input type="checkbox" class="yellow">
<span class="checkmark"></span>
</label>
<label class="container">Red
<input type="checkbox" class="red">
<span class="checkmark"></span>
</label>
<label class="container">Green
<input type="checkbox" class="green">
<span class="checkmark"></span>
</label>
You can do like this.
input[type='checkbox']:checked {
background-color: #023047;
}
input[type='checkbox']:checked:after {
content: '\2713';
color:white;
}
input[type='checkbox']{
text-align: center;
display: table-cell;
vertical-align: middle;
width: 20px !important;
height: 20px !important;
appearance:none;
border-radius:10%;
border: 1px solid rgb(191 35 42 / 90%);
box-shadow: none;
font-size: 1em;
}
<input type="checkbox" > checkbox 1
<input type="checkbox" > checkbox 2
You can imitate a check box with another element and set the background color as desired.
<span onclick="this.innerHTML = (this.innerHTML ? '' : 'X')"></span>
<style>
span{
display:inline-block;
width:10px; height:10px;
font:10px/10px 'Sans Serif'; color: green;
border:solid 1px black;
vertical-align:middle;
cursor:pointer;
}
</style>
You can get a little fancier by using ::before or after
<span class='checked' onclick="this.classList.toggle('checked')"></span>
<style>
span{
display:inline-block;
height: 10px; width:10px;
border:solid 1px black;
vertical-align:middle;
cursor:pointer;
}
span.checked::before{
content:'×';
display:block; height: 10px;
font:10px/10px 'Sans Serif';
color:green;
}
</style>
You can extend this, by using background image or a svg sprite in the ::after tag (see https://stackoverflow.com/a/19255455/87520)
I haven't tried to make it perfect, just to demonstrate the concept.
As you can see, the background color is green, no images, no libraries involved; minimal js.
If you use b-form-checkbox and you will find css of mark is svg like that...
.custom-checkbox
.custom-control-input:checked
~ .custom-control-label::after {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath **fill='%23000'** d='M6.564.75l-3.59 3.612-1.538-1.55L0 4.26 2.974 7.25 8 2.193z'/%3e%3c/svg%3e");
It's drawn by svg, so you can change coordinate to modify mark or change fill to change mark color.