I do some code for checkbox to style it. But checkbox mark doesn't hide as default. I expect, mark should hidden as default and when I click to select it, then there should be show a mark as selected this label. Please help me to solve this problem. Thanks in advance for your help.
.checkbox {
width: 38px;
height: 38px;
margin: 10px;
// border: 1px solid #000;
background: #A53692; /*blue purple*/
}
.label {
position: relative;
width: 645px;
margin: 10px;
padding-left: 20px;
line-height: 38px;
text-align: left;
color: #fff;
background: #A53692; /*blue purple*/
cursor: pointer;
}
.checkbox input[type=checkbox] {
content: "";
width: 38px;
height: 38px;
margin: 0;
left: 0;
opacity: 0;
cursor: pointer;
}
.label label::after {
content: "";
height: 6px;
width: 9px;
border-left: 2px solid;
border-bottom: 2px solid;
transform: rotate(-45deg);
position: absolute;
left: -45px;
top: 14px;
cursor: pointer;
}
/*Hide the checkmark by default*/
.checkbox input[type="checkbox"] + .label label::after {
content: none;
}
/*Unhide the checkmark on the checked state*/
.checkbox input[type="checkbox"]:checked + .label label::after {
content: "";
<div class="request-sample-form-items">
<div class="checkbox"><input type="checkbox" id="checkbox"></div>
<div class="label"><label for="checkbox">Select if you want to fill this form automatically next time.</label></div>
</div>
Try this
/* The label-check */
.label-check {
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 */
.label-check 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: #A53692;
}
/* On mouse-over, add a background color */
.label-check:hover input ~ .checkmark {
background-color: #A53692;
}
/* When the checkbox is checked, add a background */
.label-check input:checked ~ .checkmark {
background-color: #A53692;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.label-check input:checked ~ .checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.label-check .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);
}
<label class="label-check">Checkbox One
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
try to remove opacity from the following CSS
.checkbox input[type=checkbox] {
content: "";
width: 38px;
height: 38px;
margin: 0;
left: 0;
opacity: 0; //REMOVE
cursor: pointer;
}
Related
I am creating a multi range slider, using 2 slider and making them go on top of each other.
I have successfully created it and supported it in Chrome and Mozilla, but I cant seem to support Edge.
The styling is in SCSS.
<!DOCTYPE html>
<html lang="en">
<head>
<style lang="scss">
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.item-value {
display: flex;
position: relative;
width: 100%;
height: 20px;
display: flex;
align-items: center;
&::before {
content: '';
height: 5px;
background: #000;
width: 100%;
background: #ddd;
border-radius: 3px;
}
.min-range, .max-range {
height: 25px;
width: 100%;
margin: 0;
padding: 0;
border: 0;
outline: none;
background: transparent;
-webkit-appearance: none;
-moz-appearance: none;
pointer-events: none; // Prevent mouse interaction on the range slider.
position: absolute;
/* For Webkit Browsers (Chrome) */
&::-webkit-slider-runnable-track {
cursor: default;
height: 5px;
outline: 0;
appearance: none;
background: #ddd;
border-radius: 3px;
position: relative;
}
&::-webkit-slider-thumb {
-webkit-appearance: none;
pointer-events: all;
background: $red;
width: 25px;
height: 25px;
border-radius: 50%;
top: -10px;
position: absolute;
z-index: 10;
cursor: pointer;
}
/* For Mozilla Browsers */
&::-moz-range-track {
opacity: 0;
pointer-events: none;
}
&::-moz-range-thumb {
-webkit-appearance: none;
pointer-events: all;
background: $red;
width: 25px;
height: 25px;
border-radius: 50%;
top: -5px;
position: absolute;
z-index: 10;
cursor: pointer;
border: 0;
}
/* For Edge Browsers */
&::-ms-track {
pointer-events: all;
}
&::-ms-thumb {
border: none;
height: 25px;
width: 25px;
border-radius: 50%;
background: $red;
pointer-events: all;
}
&::-ms-tooltip {
display: none;
pointer-events: all;
}
}
}
}
</style>
</head>
<body>
<section class="item-value">
<input type="range" value="10" class="min-range">
<input type="range" value="10" class="max-range">
</section>
</body>
</html>
In the &::-ms-thumb {}, the pointer-events: all; does not work,
I expect it to re-enable pointer events so the handles can be used again, which happens with &::-webkit-slider-thumb {} and &::-moz-range-thumb {}
Adding the same html and css code to make it runnable here
<!DOCTYPE html>
<html lang="en">
<head>
<style lang="scss">
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
.item-value {
display: flex;
position: relative;
width: 100%;
height: 20px;
display: flex;
align-items: center;
&::before {
content: '';
height: 5px;
background: #000;
width: 100%;
background: #ddd;
border-radius: 3px;
}
.min-range, .max-range {
height: 25px;
width: 100%;
margin: 0;
padding: 0;
border: 0;
outline: none;
background: transparent;
-webkit-appearance: none;
-moz-appearance: none;
pointer-events: none; // Prevent mouse interaction on the range slider.
position: absolute;
/* For Webkit Browsers (Chrome) */
&::-webkit-slider-runnable-track {
cursor: default;
height: 5px;
outline: 0;
appearance: none;
background: #ddd;
border-radius: 3px;
position: relative;
}
&::-webkit-slider-thumb {
-webkit-appearance: none;
pointer-events: all;
background: $red;
width: 25px;
height: 25px;
border-radius: 50%;
top: -10px;
position: absolute;
z-index: 10;
cursor: pointer;
}
/* For Mozilla Browsers */
&::-moz-range-track {
opacity: 0;
pointer-events: none;
}
&::-moz-range-thumb {
-webkit-appearance: none;
pointer-events: all;
background: $red;
width: 25px;
height: 25px;
border-radius: 50%;
top: -5px;
position: absolute;
z-index: 10;
cursor: pointer;
border: 0;
}
/* For Edge Browsers */
&::-ms-track {
pointer-events: all;
}
&::-ms-thumb {
border: none;
height: 25px;
width: 25px;
border-radius: 50%;
background: $red;
pointer-events: all;
}
&::-ms-tooltip {
display: none;
pointer-events: all;
}
}
}
}
</style>
</head>
<body>
<section class="item-value">
<input type="range" value="10" class="min-range">
<input type="range" value="10" class="max-range">
</section>
</body>
</html>
I know this question have been answered before, but none of the answers are working for me, so I need help with whatever I'm doing wrong. I want my checkbox to have a green background color and white check mark once it has been clicked. I've added my code below, and in the codepen link you can view a little more detail.
Codepen link: --> https://codepen.io/paulamourad/pen/oPpbEm
/* Customize the label (the container) */
.form-check {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 12px;
cursor: pointer;
font-size: 0.9em;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
/* Hide the browser's default checkbox */
.form-check input {
position: absolute;
opacity: 0;
cursor: pointer;
}
/* Create a custom checkbox */
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 20px;
width: 20px;
border: 2px solid #D6D4D4;
}
/* Create the checkmark/indicator (hidden when not checked) */
.checkmark:after {
content: "";
position: absolute;
display: none;
}
/* Show the checkmark when checked */
.form-check input:checked~.checkmark:after {
display: block;
}
/* Style the checkmark/indicator */
.form-check .checkmark:after {
left: 2px;
top: 3px;
width: 5px;
height: 10px;
border: solid #8ABE57;
border-width: 0 3px 3px 0;
-webkit-transform: rotate(45deg);
-ms-transform: rotate(45deg);
transform: rotate(45deg);
}
<label class="form-check">
<input class="form-check-input" type="checkbox" value="" id="checkPeriodDays">
<span class="checkmark"></span>
<label class="form-check-label ml-2" for="checkPeriodDays">
Días
</label>
</label>
.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;
}
.container input {
position: absolute;
opacity: 0;
cursor: pointer;
}
.checkmark {
position: absolute;
top: 0;
left: 0;
height: 25px;
width: 25px;
background-color: #eee;
}
.container:hover input ~ .checkmark {
background-color: green;
}
.container input:checked ~ .checkmark {
background-color: green;
}
.checkmark:after {
content: "";
position: absolute;
display: none;
}
.container input:checked ~ .checkmark:after {
display: block;
}
.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);
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Checkbox Test</title>
</head>
<body>
<label class="container">Dias One
<input type="checkbox" checked="checked">
<span class="checkmark"></span>
</label>
<label class="container">Dias Two
<input type="checkbox">
<span class="checkmark"></span>
</label>
<label class="container">Dias Three
<input type="checkbox">
<span class="checkmark"></span>
</label>
</body>
</html>
I'm working on modifying an existing project which has some custom CSS styling for checkboxes. Currently the checkbox label is sitting to the right of the checkbox and I would like to move the checkbox to sit above the label. How can I achieve this using the following code?
<input type="checkbox" id="box-<%= tmp %>">
<label for="box-<%= tmp %>"><%= question.choiceAnswer[tmp] %></label>
input[type="checkbox"] { display: none; }
input[type="checkbox"] + label {
display: block;
position: relative;
padding-left: 35px;
margin-bottom: 20px;
text-align: center;
font-weight: 500;
font-size: 0.85em;
color: #232A33;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
input[type="checkbox"] + label:last-child { margin-bottom: 0; }
input[type="checkbox"] + label:before {
content: '';
display: block;
width: 20px;
height: 20px;
border: 1px solid #232A33;
position: absolute;
left: 0;
top: 0;
opacity: .6;
-webkit-transition: all .12s, border-color .08s;
transition: all .12s, border-color .08s;
}
input[type="checkbox"]:checked + label:before {
width: 10px;
top: -5px;
left: 5px;
border-radius: 0;
opacity: 1;
border-top-color: transparent;
border-left-color: transparent;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
From my understanding, the typical checkbox is no hidden and new checkbox is added through CSS, but I'm not sure how to move the label to be below the checkbox since the seem to be a single piece. Can I achieve this by modifying the above code or am I better off starting from scratch?
Thanks in advance!
Remove the left padding for the label and the absolute positioning for the pseudo element :before
input[type="checkbox"] { display: none; }
input[type="checkbox"] + label {
position: relative;
margin-bottom: 20px;
text-align: center;
font-weight: 500;
font-size: 0.85em;
color: #232A33;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
}
input[type="checkbox"] + label:last-child { margin-bottom: 0; }
input[type="checkbox"] + label:before {
content: '';
display: block;
width: 20px;
height: 20px;
border: 1px solid #232A33;
opacity: .6;
-webkit-transition: all .12s, border-color .08s;
transition: all .12s, border-color .08s;
}
input[type="checkbox"]:checked + label:before {
width: 10px;
top: -5px;
left: 5px;
border-radius: 0;
opacity: 1;
border-top-color: transparent;
border-left-color: transparent;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
}
<input type="checkbox" id="box">
<label for="box">Label</label>
I have made a custom on/off checkbox and I am having some trouble figuring out how to center it next to some text. Right now, I am attempting to use inline block to try this. Here is my code :
.for-you-switch .switch {
position: relative;
display: inline-block;
width: 65px;
height: 30px;
}
.for-you-switch input {
display: none;
}
.for-you-switch input:checked+.slider {
background-color: red;
}
.for-you-switch input:checked+.slider:after {
transform: translateX(35px);
}
.for-you-switch input:checked+.slider:before {
content: "on";
right: 36px;
color: #fff;
}
.for-you-switch input:focus+.slider {
box-shadow: 0 0 1px #2196F3;
}
.for-you-switch .slider {
position: absolute;
cursor: pointer;
border-radius: 34px;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
}
.for-you-switch .slider:after {
position: absolute;
content: "";
border-radius: 50%;
height: 26px;
width: 26px;
left: 2px;
bottom: 2px;
background-color: #fff;
transition: .2s;
}
.for-you-switch .slider:before {
position: absolute;
content: "off";
right: 12px;
top: 6px;
transition: .4s;
}
<div class="for-you-switch">
<span>Products for you.</span>
<label class="switch">
<input type="checkbox" />
<div class="slider round"></div>
</label>
</div>
Here is a fiddle with the code to play with - https://jsfiddle.net/qywkdv31/2/
As you can see the button is kind of floating at the top of the wrapping div, I would like to have it centered to the right of the text. Unsure how to accomplish this. Thanks!
You just need to add vertical-align: middle; to .for-you-switch .switch.
.for-you-switch .switch {
position: relative;
display: inline-block;
width: 65px;
height: 30px;
vertical-align: middle;
}
.for-you-switch input {
display: none;
}
.for-you-switch input:checked+.slider {
background-color: red;
}
.for-you-switch input:checked+.slider:after {
transform: translateX(35px);
}
.for-you-switch input:checked+.slider:before {
content: "on";
right: 36px;
color: #fff;
}
.for-you-switch input:focus+.slider {
box-shadow: 0 0 1px #2196F3;
}
.for-you-switch .slider {
position: absolute;
cursor: pointer;
border-radius: 34px;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
transition: .4s;
}
.for-you-switch .slider:after {
position: absolute;
content: "";
border-radius: 50%;
height: 26px;
width: 26px;
left: 2px;
bottom: 2px;
background-color: #fff;
transition: .2s;
}
.for-you-switch .slider:before {
position: absolute;
content: "off";
right: 12px;
top: 6px;
transition: .4s;
}
<div class="for-you-switch">
<span>Products for you.</span>
<label class="switch">
<input type="checkbox" />
<div class="slider round"></div>
</label>
</div>
Try,
.for-you-switch .switch{
display: inline-block;
vertical-align: middle;
}
.for-you-switch span{
display: inline-block;
vertical-align: middle;
}
Hope this help.
.switch {
position: relative;
display: inline-block;
vertical-align:middle;
width: 65px;
height: 30px; }
i'm trying to personalize the appearance of Checkbox but this only works in Google Chrome for mozilla doesn't work i dont know how to fix this here is my code:
Example:
Checkbox on jsfiddle.net
¡Please! before you post any response see example in the 2 browsers in
this case Chrome and Mozilla.
images from google chrome and mozilla
Chrome:
Mozilla
CSS:
#div-tallas .seleccion-talla .btn-default{
padding: 6px 7px;
font-weight: 600;
font-size: 1.2em;
letter-spacing: 0px;
min-width: 40px;
margin-left: 1px !important;
}
#div-tallas input[type="checkbox"] {
/* 1 */
display: inline-block;
height: 36px;
width: 36px;
border: 2px solid #000;
-moz-border: 2px solid #000;
/* 2 */
overflow: hidden;
/* 3 */
margin-top: -4px;
vertical-align: middle;
/* 4 */
-webkit-appearance: none;
-moz-appearance: none;
outline: 0;
/* 5 */
background: #e5e4e4;
-moz-background: #e5e4e4;
}
/*
* Checked
*/
#div-tallas input[type=checkbox]:checked {
/* 1 */
display: inline-block;
height: 36px;
width: 36px;
border: 2px solid #e5e4e4 !important;
-moz-border: 2px solid #e5e4e4 !important;
/* 2 */
overflow: hidden;
/* 3 */
margin-top: -4px;
vertical-align: middle;
/* 4 */
-webkit-appearance: none;
-moz-appearance: none;
outline: 0;
/* 5 */
background: #ff6500 !important;
background-color: #ff6500 !important;
padding: 2px;
transition: background 0.4s linear 0s, color 0.4s linear 0s;
}
/* Checkbox */
#div-tallas input[type=checkbox]:checked:before,
#div-tallas input[type=checkbox]:indeterminate:before {
content: "\f00c";
font-family: FontAwesome;
font-size: 32px;
-webkit-font-smoothing: antialiased;
text-align: center;
line-height: 26px;
color: #e5e4e4;
z-index: 888;
margin-left: -1px;
}
#div-tallas input[type=checkbox]:indeterminate:before {
content: "\f068";
}
How about styling the label?
#div-tallas {
background-color: #e5e4e4 !important;
min-height: 40vh;
}
#div-tallas input[type="checkbox"] {
display: none;
}
#div-tallas input[type="checkbox"] + label {
padding-left: 0;
}
#div-tallas input[type="checkbox"] + label:before {
/* 1 */
font: 32px/32px 'FontAwesome';
text-align: center;
display: inline-block;
height: 36px;
width: 36px;
border: 2px solid #000;
overflow: hidden;
margin-top: -4px;
vertical-align: middle;
background: transparent;
/* to show content */
content: "\00a0";
margin-right: 8px;
}
/*
* Checked
*/
#div-tallas input[type=checkbox]:checked + label:before {
border: 2px solid transparent;
background: #ff6500;
transition: background 0.4s linear 0s, color 0.4s linear 0s;
}
/* Checkbox */
#div-tallas input[type=checkbox]:checked + label:before,
#div-tallas input[type=checkbox]:indeterminate + label:before {
content: "\f00c";
color: #e5e4e4;
}
#div-tallas input[type=checkbox]:indeterminate + label:before {
content: "\f068";
}
jsfiddle
This isn't 100% perfect but it does show you a working example of a pure CSS checkbox that works in both Chrome and Firefox.
JSFiddle
HTML
<div id="div-tallas">
<div class="quiero-este">
<h5>¡Quiero este!</h5>
<div class="checkbox check-primary m-top-40 text-center">
<input type="checkbox" value="1" id="checkbox1" />
<label for="checkbox1"></label>
</div>
</div>
</div>
CSS
#div-tallas {
background-color: #e5e4e4 !important;
min-height: 40vh;
}
#div-tallas input[type=checkbox] {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: transparent;
visibility: hidden;
}
#div-tallas input[type=checkbox],
#div-tallas input[type=checkbox] + label::before {
cursor: pointer;
vertical-align: middle;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
#div-tallas input[type=checkbox] + label::before {
content: '';
text-align: center;
background: #e5e4e4;
display: inline-block;
pointer-events: none;
opacity: 1;
color: black;
border: 3px solid black;
width: 36px;
height: 36px;
}
#div-tallas input[type=checkbox] + label {
line-height: 20px;
margin: 0 15px 0 15px;
}
#div-tallas input[type=checkbox]:hover {
cursor: pointer;
}
#div-tallas input[type=checkbox]:hover + label::before {
content: '';
background: #e5e4e4;
}
#div-tallas input[type=checkbox]:checked + label::before {
background: #ff6500 !important;
background-color: #ff6500 !important;
outline: 0;
content: "\f00c";
font-family: FontAwesome;
font-size: 32px;
-webkit-font-smoothing: antialiased;
text-align: center;
line-height: 26px;
color: #e5e4e4;
z-index: 888;
margin-left: -1px;
}
#div-tallas input[type=checkbox]:checked:hover + label::before {
opacity: 1;
}
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
margin: 0;
padding: 0;
}
Hope this helps.