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.
Related
I have a customized button/link element that transforms the said element to look like this:
Problem I'm having is that when the button is focused using keyboard the outline is not transformed along the borders of the element. I've also tried using box-shadow, with same results. Is there a proper way to transform outline, like I did with the element itself?
.button {
font-family: $brand-font;
font-weight: 900;
transition: color $transition-duration ease-out;
-webkit-appearance: none;
-moz-appearance: none;
display: inline-block;
text-align: center;
max-width: 320px;
min-width: 200px;
height: 40px;
line-height: 40px;
position: relative;
border: none !important;
font-size: 1.4rem;
z-index: 0;
padding: 0 1.8rem;
background-color: transparent;
color: $primary-blue;
cursor: pointer;
&:visited {
border: none !important;
}
&.skewOnHover {
color: $secondary-blue;
}
& > svg {
vertical-align: middle;
}
&:focus {
outline: 2px solid $primary-blue;
// box-shadow: 0 0 0 2px $primary-blue;
}
&::before {
content: ""; display: block;
display: block;
width: 100%; height: 100%;
top: -2px; left: -2px;
transition-property: border, background-color, transform;
transition-duration: $transition-duration;
transition-timing-function: ease-out;
position: absolute;
z-index: -1;
// regular (cyan background, blue text)
background-color: $secondary-blue;
border: 2px solid $secondary-blue;
transform: skew(-22.5deg);
}
&.skewOnHover {
&::before {
background-color: transparent;
transform: skew(22.5deg);
}
}
Apply the outline to skewed element:
&:focus:before {
outline: 2px solid red;
}
and reset the outline of button:
.button:focus {
outline: none;
}
.button {
font-weight: 900;
transition: color 0.3s ease-out;
-webkit-appearance: none;
-moz-appearance: none;
display: inline-block;
text-align: center;
max-width: 320px;
min-width: 200px;
height: 40px;
line-height: 40px;
position: relative;
border: none !important;
font-size: 1.4rem;
z-index: 0;
padding: 0 1.8rem;
background-color: transparent;
color: blue;
cursor: pointer;
}
.button:visited {
border: none !important;
}
.button.skewOnHover {
color: dodgerblue;
}
.button>svg {
vertical-align: middle;
}
.button:focus {
outline: none;
}
.button:focus:before {
outline: 2px solid red;
}
.button::before {
content: "";
display: block;
display: block;
width: 100%;
height: 100%;
top: -2px;
left: -2px;
transition-property: border, background-color, transform;
transition-duration: 0.3s;
transition-timing-function: ease-out;
position: absolute;
z-index: -1;
background-color: dodgerblue;
border: 2px solid dodgerblue;
transform: skew(-22.5deg);
}
.button.skewOnHover::before {
background-color: transparent;
transform: skew(22.5deg);
}
<button class="button">button</button>
I am trying to customize a range slider according to my need i am almost there except for the orientation of it, currently it's aligned horizontally which should be vertical.
I have tried adding
data-orientation = "vertical"
and Orient="vertical" as well as
.input-range{
writing-mode: bt-lr; /* IE */
-webkit-appearance: slider-vertical;
}
got no luck.
current code base is as follows : Style
.input-range{
writing-mode: bt-lr; /* IE */
-webkit-appearance: slider-vertical;}
* {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.PrixMin {
float: left;
color: #164188;
font-size: 19px;
margin-right: 5px;
}
.selecteurPrix {
padding-top: 15px;
display:block;
position:absolute;
top:90px;
left:0;
z-index: 1200
}
body {
font-family: sans-serif;
padding: 40px;
}
.range-slider {
position: relative;
width: 450px;
float: left;
margin-right: 5px;
}
#media (-webkit-min-device-pixel-ratio:0) {
/* Non-IE styles here*/
.range-slider .input-range {
-webkit-appearance: none;
width: 449px;
height: 5px;
border-radius: 5px;
background: #ccc;
outline: none;
}
}
#media (-ms-high-contrast:none),(-ms-high-contrast:active) {
/* IE styles here*/
.range-slider .input-range {
/*removes default webkit styles*/
-webkit-appearance: none;
/*fix for FF unable to apply focus style bug */
border: 1px solid white;
/*required for proper track sizing in FF*/
width: 450px;
outline: none;
}
}
.range-slider .input-range::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #164188;
cursor: pointer;
-webkit-transition: background .15s ease-in-out;
transition: background .15s ease-in-out;
}
.range-slider .input-range::-webkit-slider-thumb:hover {
background: #164188;
}
.range-slider .input-range:active::-webkit-slider-thumb {
background: #164188;
}
.range-slider .input-range::-moz-range-thumb {
width: 20px;
height: 20px;
border: 0;
border-radius: 50%;
background: #164188;
cursor: pointer;
-webkit-transition: background .15s ease-in-out;
transition: background .15s ease-in-out;
}
.range-slider .input-range::-moz-range-thumb:hover {
background: #164188;
}
.range-slider .input-range:active::-moz-range-thumb {
background: #164188;
}
.range-slider .range-value {
display: inline-block;
position: relative;
width: 100px;
color: #fff;
font-size: 23px;
line-height: 32px;
text-align: center;
border-radius: 3px;
background: #164188;
padding: 5px 10px;
margin-left: 7px;
}
::-moz-range-track {
background: #ccc;
border: 0;
}
input::-moz-focus-inner {
border: 0;
}
input[type=range] {
margin: 2px;
}
input[type=range]::-ms-track {
width: 450px;
height: 5px;
/*remove bg colour from the track, we'll use ms-fill-lower and ms-fill-upper instead */
background: transparent;
/*leave room for the larger thumb to overflow with a transparent border */
border-color: transparent;
border-width: 6px 0;
/*remove default tick marks*/
color: transparent;
}
input[type=range]::-ms-fill-lower {
background: #ccc;
border-radius: 10px;
}
input[type=range]::-ms-fill-upper {
background: #ccc;
border-radius: 10px;
}
Markup
<div class="selecteurPrix">
<div class="PrixMin"> -100</div>
<div class="range-slider">
<input class="input-range" orient="vertical" type="range" value="0" min="-100" max="100" step="25">
</div> <div class="PrixMin"> 100</div>
</div>
Is there something i am missing here? any help would is appreciated. Thanks
2 things
#media (-webkit-min-device-pixel-ratio:0) {
/* Non-IE styles here*/
.range-slider .input-range {
-webkit-appearance: none;
width: 449px;
height: 5px;
}
}
Is overwriting your
.input-range{
writing-mode: bt-lr; /* IE */
-webkit-appearance: slider-vertical;
}
Also you need to flip the width and height to match the vetical design
.input-range{
writing-mode: bt-lr; /* IE */
-webkit-appearance: slider-vertical;
width: 5px;
height: 449px;
}
you're looking for this appearance css property:
.input-range {
appearance: slider-vertical;
-moz-appearance: slider-vertical;
-webkit-appearance: slider-vertical;
}
Add:
input[orient=vertical] {
-webkit-appearance: slider-vertical;
height: 450px;
padding: 0 20px;
width: 20px;
writing-mode: bt-lr;
}
Remove:
.range-slider {
position: relative;
width: 450px;
float: left;
margin-right: 5px;
}
I am trying to launch a Web UI using Flask, however, the radio buttons and check boxes aren't showing. I've tried following online examples, like the ones here: https://www.w3schools.com/bootstrap/bootstrap_forms_inputs.asp
The CSS file has a lot of sections pertaining to checkboxes/radios, but I'm not sure which part is the source of the problem (if that).
Here is the relevant portion of the CSS file:
/* Form */
form {
margin: 0 0 2em 0;
}
label {
display: block;
font-size: 0.9em;
font-weight: 400;
margin: 0 0 1em 0;
}
input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
border-radius: 4px;
border: none;
border: solid 1px;
color: inherit;
display: block;
outline: 0;
padding: 0 1em;
text-decoration: none;
width: 100%;
}
input[type="text"]:invalid,
input[type="password"]:invalid,
input[type="email"]:invalid,
select:invalid,
textarea:invalid {
box-shadow: none;
}
.select-wrapper {
text-decoration: none;
display: block;
position: relative;
}
.select-wrapper:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
}
.select-wrapper:before {
content: '\f078';
display: block;
height: 2.75em;
line-height: 2.75em;
pointer-events: none;
position: absolute;
right: 0;
text-align: center;
top: 0;
width: 2.75em;
}
.select-wrapper select::-ms-expand {
display: none;
}
input[type="text"],
input[type="password"],
input[type="email"],
select {
height: 2.75em;
}
textarea {
padding: 0.75em 1em;
}
input[type="checkbox"],
input[type="radio"] {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
display: block;
float: left;
margin-right: -2em;
opacity: 0;
width: 1em;
z-index: -1;
}
input[type="checkbox"]+label,
input[type="radio"]+label {
text-decoration: none;
cursor: pointer;
display: inline-block;
font-size: 1em;
font-weight: 200;
padding-left: 2.4em;
padding-right: 0.75em;
position: relative;
}
input[type="checkbox"]+label:before,
input[type="radio"]+label:before {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
font-family: FontAwesome;
font-style: normal;
font-weight: normal;
text-transform: none !important;
}
input[type="checkbox"]+label:before,
input[type="radio"]+label:before {
border-radius: 4px;
border: solid 1px;
content: '';
display: inline-block;
height: 1.65em;
left: 0;
line-height: 1.58125em;
position: absolute;
text-align: center;
top: 0;
width: 1.65em;
}
input[type="checkbox"]:checked+label:before,
input[type="radio"]:checked+label:before {
content: '\f00c';
}
input[type="checkbox"]+label:before {
border-radius: 4px;
}
input[type="radio"]+label:before {
border-radius: 100%;
}
::-webkit-input-placeholder {
opacity: 1.0;
}
:-moz-placeholder {
opacity: 1.0;
}
::-moz-placeholder {
opacity: 1.0;
}
:-ms-input-placeholder {
opacity: 1.0;
}
.formerize-placeholder {
opacity: 1.0;
}
label {
color: #444444;
}
input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
background: rgba(144, 144, 144, 0.075);
border-color: #666666;
}
input[type="text"]:focus,
input[type="password"]:focus,
input[type="email"]:focus,
select:focus,
textarea:focus {
border-color: #EF6480;
box-shadow: 0 0 0 1px #EF6480;
}
.select-wrapper:before {
color: #666666;
}
input[type="checkbox"]+label,
input[type="radio"]+label {
color: #666666;
}
input[type="checkbox"]+label:before,
input[type="radio"]+label:before {
background: rgba(144, 144, 144, 0.075);
border-color: #666666;
}
input[type="checkbox"]:checked+label:before,
input[type="radio"]:checked+label:before {
background-color: #EF6480;
border-color: #EF6480;
color: #ffffff;
}
input[type="checkbox"]:focus+label:before,
input[type="radio"]:focus+label:before {
border-color: #EF6480;
box-shadow: 0 0 0 1px #EF6480;
}
::-webkit-input-placeholder {
color: #999999 !important;
}
:-moz-placeholder {
color: #999999 !important;
}
::-moz-placeholder {
color: #999999 !important;
}
:-ms-input-placeholder {
color: #999999 !important;
}
.formerize-placeholder {
color: #999999 !important;
}
Here is the relevant portion of the HTML file:
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" rel="stylesheet"/>
<!-- Wrapper -->
<div id="wrapper">
<!-- Banner -->
<section id="intro" class="main">
<span class="icon fa-diamond major"></span>
<h3>Please upload your authors list below</h3>
<form action="" method=post enctype=multipart/form-data>
<p><input type=file name=file>
<br><br>
<input type="checkbox" name="sep1" value="Separate initials with period"> Separate initials with period<br>
<input type="checkbox" name="sep2" value="Separate initials with space"> Separate initials with space<br>
<input type="radio" name="affiliation" value="Mark affiliations with letter"> Mark affiliations with letter
<input type="radio" name="affiliation" value="Mark affiliations with number" checked> Mark affiliations with number<br><br>
<input type=submit value=Upload></p>
</form>
</section>
</div>
You can Simplify your CSS from :
input[type="checkbox"], input[type="radio"] {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
display: block;
float: left;
margin-right: -2em;
opacity: 0;
width: 1em;
z-index: -1;
}
Into This 1
input[type="checkbox"], input[type="radio"] {
width: 1em;
z-index: -1;
}
Or You can just Delete that part of your CSS
Here is the problematic section of your css:
input[type="checkbox"],
input[type="radio"] {
-moz-appearance: none;
-webkit-appearance: none;
-ms-appearance: none;
appearance: none;
display: block;
float: left;
margin-right: -2em;
opacity: 0;
width: 1em;
z-index: -1;
}
Change opacity to 1
Get rid of the appearance none.
There are other problems with your code but this solves your question about the boxes not appearing.
This should get you closer to what you are looking for:
input[type="checkbox"],
input[type="radio"] {
display: inline-block;
opacity: 1;
width: 1em;
z-index: -1;
}
It can happen because of multiple reasons, however
opacity: 1;
is one of the crucial things if your checkbox is not visible. Secondly, your position should not be absolute, it should be like
position: relative;
Just in case you are not able to click/check your checkbox, it's because you have blocked pointer-events. So change it to
pointer-events: all;
In all, your CSS code will look like this,
input[type="checkbox"]{
width: 1em;
position: relative;
opacity: 1;
pointer-events: all;
}
Note: In case if you still fail to achieve the desired result, try this code
input[type="checkbox"]{
width: 1em;
position: relative !important;
opacity: 1 !important;
pointer-events: all !important;
}
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've got some radio buttons which I'm formatting to look a little prettier than the standard CSS. When the text associated with the radio button is longer it wraps underneath the radio button and you cannot see some of the text. How do I get the text to wrap and align?
CSS:
body {
font-family: sans-serif;
font-weight: normal;
margin: 10px;
color: #999;
background-color: #eee;
}
form {
margin: 40px 0;
}
div {
clear: both;
margin: 0 50px;
}
label {
width: 200px;
border-radius: 3px;
border: 1px solid #D1D3D4
}
/* hide input */
input.radio:empty {
margin-left: -999px;
}
/* style label */
input.radio:empty ~ label {
position: relative;
float: left;
line-height: 2.5em;
text-indent: 3.25em;
margin-top: 2em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
content:'\2714';
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
content:'\2714';
text-indent: .9em;
color: #9CE2AE;
background-color: #4DCB6D;
}
input.radio:checked ~ label {
color: #777;
}
/* radio focus */
input.radio:focus ~ label:before {
box-shadow: 0 0 0 3px #999;
}
line-height: 2.5em;
text-indent: 3.25em;
margin-top: 1em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
content:'✓';
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
content:'✓';
text-indent: .9em;
color: #80ffff;
background-color: #0080c0;
}
input.radio:checked ~ label {
color: #777;
}
/* radio focus */
input.radio:focus ~ label:before {
box-shadow: 0 0 0 3px #999;
}
HTML:
<div>
<input type="radio" name="radio" id="radio1" class="radio" checked/>
<label for="radio1">First Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio2" class="radio"/>
<label for="radio2">Second Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio3" class="radio"/>
<label for="radio3">Third Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio4" class="radio"/>
<label for="radio4">Fourth Option is longer</label>
</div>
Here is a jsfiddle with my CSS and HTML.
change some css like
label {
border: 1px solid #d1d3d4;
border-radius: 3px;
display: block; /* add this property */
padding-left: 50px; /* add this property */
width: 200px;
}
input.radio:empty ~ label {
position: relative;
float: left;
line-height: 2.5em;
/*text-indent: 3.25em; - remove this property*/
margin-top: 2em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
https://jsfiddle.net/gb8snazq/4/
Remove text-indent and use padding-left.
body {
font-family: sans-serif;
font-weight: normal;
margin: 10px;
color: #999;
background-color: #eee;
}
form {
margin: 40px 0;
}
div {
clear: both;
margin: 0 50px;
}
label {
width: 200px;
border-radius: 3px;
border: 1px solid #D1D3D4
}
/* hide input */
input.radio:empty {
margin-left: -999px;
}
/* style label */
input.radio:empty ~ label {
position: relative;
float: left;
line-height: 2.5em;
padding-left: 3em;
margin-top: 2em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
content:'\2714';
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
content:'\2714';
text-indent: .9em;
color: #9CE2AE;
background-color: #4DCB6D;
}
input.radio:checked ~ label {
color: #777;
}
/* radio focus */
input.radio:focus ~ label:before {
box-shadow: 0 0 0 3px #999;
}
line-height: 2.5em;
text-indent: 3.25em;
margin-top: 1em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
content:'✓';
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
content:'✓';
text-indent: .9em;
color: #80ffff;
background-color: #0080c0;
}
input.radio:checked ~ label {
color: #777;
}
/* radio focus */
input.radio:focus ~ label:before {
box-shadow: 0 0 0 3px #999;
}
<div>
<input type="radio" name="radio" id="radio1" class="radio" checked/>
<label for="radio1">First Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio2" class="radio"/>
<label for="radio2">Second Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio3" class="radio"/>
<label for="radio3">Third Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio4" class="radio"/>
<label for="radio4">Fourth Option is longer</label>
</div>
body {
font-family: sans-serif;
font-weight: normal;
margin: 10px;
color: #999;
background-color: #eee;
}
form {
margin: 40px 0;
}
div {
clear: both;
margin: 0 50px;
}
label {
width: 145px;
border-radius: 3px;
border: 1px solid #D1D3D4
}
/* hide input */
input.radio:empty {
margin-left: -999px;
}
/* style label */
input.radio:empty ~ label {
position: relative;
float: left;
margin-top: 2em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
padding: 9px 0 9px 55px;
}
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
line-height: 2.5em;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
content:'\2714';
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
content:'\2714';
text-indent: .9em;
color: #9CE2AE;
background-color: #4DCB6D;
}
input.radio:checked ~ label {
color: #777;
}
/* radio focus */
input.radio:focus ~ label:before {
box-shadow: 0 0 0 3px #999;
}
line-height: 2.5em;
text-indent: 3.25em;
margin-top: 1em;
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input.radio:empty ~ label:before {
position: absolute;
display: block;
top: 0;
bottom: 0;
left: 0;
content: '';
width: 2.5em;
background: #D1D3D4;
border-radius: 3px 0 0 3px;
}
/* toggle hover */
input.radio:hover:not(:checked) ~ label:before {
content:'✓';
text-indent: .9em;
color: #C2C2C2;
}
input.radio:hover:not(:checked) ~ label {
color: #888;
}
/* toggle on */
input.radio:checked ~ label:before {
content:'✓';
text-indent: .9em;
color: #80ffff;
background-color: #0080c0;
}
input.radio:checked ~ label {
color: #777;
}
/* radio focus */
input.radio:focus ~ label:before {
box-shadow: 0 0 0 3px #999;
}
<div>
<input type="radio" name="radio" id="radio1" class="radio" checked/>
<label for="radio1">First Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio2" class="radio"/>
<label for="radio2">Second Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio3" class="radio"/>
<label for="radio3">Third Option</label>
</div>
<div>
<input type="radio" name="radio" id="radio4" class="radio"/>
<label for="radio4">Fourth Option is longer</label>
</div>
Used padding instead of text-indent
line-height added to :before only
https://jsfiddle.net/afelixj/gb8snazq/5/
.input.radio:empty ~ label:before{
content: '✓';
color: #fff;
}
.input.radio:empty ~ label{
text-align:center;
}
<!-- You need to add some css -->
Look like this style