I want to add an input form to an HTML table cell when a checkbox is selected.
When I add some form of text field or number field to the table cell to create a form, the text box doesn't show. only the text of my label shows.
<td>
<label class="collapsible">
<input type="checkbox" />
<span class="collapser">Edit</span>
<span class="arrow">></span>
<div class="collapsed">
<form method="post">
<label for="pwd">Hello World</label><br>
<input type="number" min="1" step="1" class="form-control" id="pwd" name=min_qty>
</form></div></label></td>
My Css code as well:
.collapsible {
display: block;
margin-bottom: 1rem;
}
.collapsible input {
position: absolute;
left: -9999px;
}
.collapsible input:focus ~ .collapser {
border-color: grey;
}
.collapsible .collapser {
cursor: pointer;
border: 1px transparent dotted;
}
.collapsible .arrow {
float: right;
margin-left: 0.5em;
display: inline-block;
transform: rotate(90deg);
transition: transform 0.25s ease-out;
}
.collapsible input:checked ~ .arrow,
.collapsible input:checked ~ .collapser .arrow {
transform: rotate(270deg);
}
.collapsible .collapsed {
font-size: 0;
margin: 0;
opacity: 0;
padding: 0;
/* fade out, then shrink */
transition: opacity 0.25s, margin 0.5s 0.25s, font-size 0.5s 0.25s, padding 0.5s 0.25s;
}
.collapsible input:checked ~ .collapsed {
font-size: 12px;
opacity: 1;
height: auto;
padding: 5px 0;
/* grow, then fade in */
transition: margin 0.25s, padding 0.25s, font-size 0.25s, opacity 0.5s 0.25s;
}
My table output example
I figured it out.
My CSS was affecting all of my inputs, not just my check boxes.
Changed this:
}
.collapsible input {
position: absolute;
left: -9999px;
}
to this:
.collapsible input[type="checkbox"] {
position: absolute;
display: none;
}
Related
I'm trying to make the accordion collapsible dropdown open a little slower, right now it opens instantly. Been trying to find online material on how to accomplish this with the code I already have. Can't seem to find anything online.
Any dropdown slowness, just trying to learn how to implement the code.
.so-accordion-wrapper {
padding-top: 2.5rem;
overflow: visible;
border-bottom: 1px solid #eaeaea;
margin-left: auto;
margin-right: auto;
position: relative;
max-width: 820px;
}
.so-tab {
position: relative;
width: 100%;
border-top: 1px solid #eaeaea;
overflow: hidden;
padding-left: 20px;
padding-right: 20px;
}
.so-tab label {
position: relative;
display: block;
padding: 0 25px 0 0;
margin-bottom: 15px;
margin-top: 15px;
line-height: normal;
cursor: pointer;
letter-spacing: 0.2em;
text-transform: uppercase;
font-size: 12px;
}
.so-tab input {
position: absolute;
opacity: 0;
z-index: -1;
}
.so-tab-content {
max-height: 0;
overflow: hidden;
transition: max-height .35s;
}
/* :checked */
.so-tab input:checked ~ .so-tab-content {
max-height: none;
}
/* Icon */
.so-tab label::after {
position: absolute;
right: 0;
top: -5px;
font-size: 1.5em;
color: #959595;
display: block;
-webkit-transition: all 0.50s ease;
-moz-transition: all 0.50s ease;
-o-transition: all 0.50s ease;
transition: all 0.50s ease;
}
.so-tab input[type=checkbox] + label::after {
content: "+";
}
.so-tab input[type=radio] + label::after {
content: "\25BC";
}
.so-tab input[type=checkbox]:checked + label::after {
transform: rotate(315deg);
}
.so-tab input[type=radio]:checked + label::after {
transform: rotateX(180deg);
}
<div class="so-accordion-wrapper">
<div class="so-tab"><input id="so-tab-1" type="checkbox" name="tabs"> <label for="so-tab-1">INGREDIENTS</label>
<div class="so-tab-content">
<p>Yes</p>
</div>
</div>
<div class="so-tab"><input id="so-tab-2" type="checkbox" name="tabs"> <label for="so-tab-2">PRECAUTION</label>
<div class="so-tab-content">
<p>No</p>
</div>
</div>
</div>
As you asked in a comment, here is what I mean:
Firstly, the only change you need is for to give max-height a value - "none" doesn't work.
You have already addressed the usual problem when doing a slide up/down in CSS - you cannot transition height - by using max-height which can be used for transitions. However it needs a value for the transition to work, unfortunately none won't work because the browser cannot calculate the values needed for the transition with no value.
FYI there is also no need to change the transition-timing-function (e.g. ease, ease-in-out, cubic-bezier) or add a transition to the open div (that doesn't actually do anything in your code).
The issue I mentioned is that the slide down action is happening much more quickly than the time you have specified, i.e. 0.35s - you can see it more clearly if you set it to e.g. 1s. The slide-up action takes longer as if it is taking the correct amount of time. See example:
.so-accordion-wrapper {
padding-top: 2.5rem;
overflow: visible;
border-bottom: 1px solid #eaeaea;
margin-left: auto;
margin-right: auto;
position: relative;
max-width: 820px;
}
.so-tab {
position: relative;
width: 100%;
border-top: 1px solid #eaeaea;
overflow: hidden;
padding-left: 20px;
padding-right: 20px;
}
.so-tab label {
position: relative;
display: block;
padding: 0 25px 0 0;
margin-bottom: 15px;
margin-top: 15px;
line-height: normal;
cursor: pointer;
letter-spacing: 0.2em;
text-transform: uppercase;
font-size: 12px;
}
.so-tab input {
position: absolute;
opacity: 0;
z-index: -1;
}
.so-tab-content {
max-height: 0;
overflow: hidden;
transition: max-height 1s;
}
/* :checked */
.so-tab input:checked ~ .so-tab-content {
max-height: 1000px;
}
/* Icon */
.so-tab label::after {
position: absolute;
right: 0;
top: -5px;
font-size: 1.5em;
color: #959595;
display: block;
-webkit-transition: all 0.50s ease;
-moz-transition: all 0.50s ease;
-o-transition: all 0.50s ease;
transition: all 0.50s ease;
}
.so-tab input[type=checkbox] + label::after {
content: "+";
}
.so-tab input[type=radio] + label::after {
content: "\25BC";
}
.so-tab input[type=checkbox]:checked + label::after {
transform: rotate(315deg);
}
.so-tab input[type=radio]:checked + label::after {
transform: rotateX(180deg);
}
<div class="so-accordion-wrapper">
<div class="so-tab"><input id="so-tab-1" type="checkbox" name="tabs"> <label for="so-tab-1">INGREDIENTS</label>
<div class="so-tab-content">
<p>Yes</p>
</div>
</div>
<div class="so-tab"><input id="so-tab-2" type="checkbox" name="tabs"> <label for="so-tab-2">PRECAUTION</label>
<div class="so-tab-content">
<p>No</p>
</div>
</div>
</div>
The reason for this is that the time to slide down is being calculated on the max-height you have set - e.g. 1000px in the example above. So it is taking the full 1-second to slide down 1000px, but your actual div isn't that big so it appears much more quickly.
FYI the same is happening on the slide-up, but it looks slower because it takes almost the full second to reach the "top" of the 1000px that is being shown.
The ways around this are:
use a more appropriate max-height, e.g. if you know your div is never going to be
bigger than 100px;, then set that to your max height - see the example below.
javascript (which should be avoided unless necessary and the above option is unacceptable to you - the more more processing you add to the client-side the slower the page loads - which is bad for both users and Google).
Example using a more appropriate max-height: max-height: 100px - you can see the slide down is now closer to the 1-second time you specified.
.so-accordion-wrapper {
padding-top: 2.5rem;
overflow: visible;
border-bottom: 1px solid #eaeaea;
margin-left: auto;
margin-right: auto;
position: relative;
max-width: 820px;
}
.so-tab {
position: relative;
width: 100%;
border-top: 1px solid #eaeaea;
overflow: hidden;
padding-left: 20px;
padding-right: 20px;
}
.so-tab label {
position: relative;
display: block;
padding: 0 25px 0 0;
margin-bottom: 15px;
margin-top: 15px;
line-height: normal;
cursor: pointer;
letter-spacing: 0.2em;
text-transform: uppercase;
font-size: 12px;
}
.so-tab input {
position: absolute;
opacity: 0;
z-index: -1;
}
.so-tab-content {
max-height: 0;
overflow: hidden;
transition: max-height 1s;
}
/* :checked */
.so-tab input:checked ~ .so-tab-content {
max-height: 100px;
}
/* Icon */
.so-tab label::after {
position: absolute;
right: 0;
top: -5px;
font-size: 1.5em;
color: #959595;
display: block;
-webkit-transition: all 0.50s ease;
-moz-transition: all 0.50s ease;
-o-transition: all 0.50s ease;
transition: all 0.50s ease;
}
.so-tab input[type=checkbox] + label::after {
content: "+";
}
.so-tab input[type=radio] + label::after {
content: "\25BC";
}
.so-tab input[type=checkbox]:checked + label::after {
transform: rotate(315deg);
}
.so-tab input[type=radio]:checked + label::after {
transform: rotateX(180deg);
}
<div class="so-accordion-wrapper">
<div class="so-tab"><input id="so-tab-1" type="checkbox" name="tabs"> <label for="so-tab-1">INGREDIENTS</label>
<div class="so-tab-content">
<p>Yes</p>
</div>
</div>
<div class="so-tab"><input id="so-tab-2" type="checkbox" name="tabs"> <label for="so-tab-2">PRECAUTION</label>
<div class="so-tab-content">
<p>No</p>
</div>
</div>
</div>
In this case, it might not be a big deal as 0.35s is quite fast anyway, but this is a very important point to remember in general, as it can have a much larger affect in other situations.
Your approach is correct, however css cannot create a transition from max-height: 0 to max-height: none. when using a value using pixels you should be able to pull it off, see my fiddle here with a transition:
.so-accordion-wrapper {
padding-top: 2.5rem;
overflow: visible;
border-bottom: 1px solid #eaeaea;
margin-left: auto;
margin-right: auto;
position: relative;
max-width: 820px;
}
.so-tab {
position: relative;
width: 100%;
border-top: 1px solid #eaeaea;
overflow: hidden;
padding-left: 20px;
padding-right: 20px;
}
.so-tab label {
position: relative;
display: block;
padding: 0 25px 0 0;
margin-bottom: 15px;
margin-top: 15px;
line-height: normal;
cursor: pointer;
letter-spacing: 0.2em;
text-transform: uppercase;
font-size: 12px;
}
.so-tab input {
position: absolute;
opacity: 0;
z-index: -1;
}
.so-tab-content {
max-height: 0;
overflow: hidden;
transition: max-height 0.5s cubic-bezier(0, 1, 0, 1);
}
/* :checked */
.so-tab input:checked ~ .so-tab-content {
max-height: 1000px;
transition: max-height 0.5s ease-in-out;
}
/* Icon */
.so-tab label::after {
position: absolute;
right: 0;
top: -5px;
font-size: 1.5em;
color: #959595;
display: block;
-webkit-transition: all 0.50s ease;
-moz-transition: all 0.50s ease;
-o-transition: all 0.50s ease;
transition: all 0.50s ease;
}
.so-tab input[type=checkbox] + label::after {
content: "+";
}
.so-tab input[type=radio] + label::after {
content: "\25BC";
}
.so-tab input[type=checkbox]:checked + label::after {
transform: rotate(315deg);
}
.so-tab input[type=radio]:checked + label::after {
transform: rotateX(180deg);
}
<div class="so-accordion-wrapper">
<div class="so-tab"><input id="so-tab-1" type="checkbox" name="tabs"> <label for="so-tab-1">INGREDIENTS</label>
<div class="so-tab-content">
<p>Yes</p>
</div>
</div>
<div class="so-tab"><input id="so-tab-2" type="checkbox" name="tabs"> <label for="so-tab-2">PRECAUTION</label>
<div class="so-tab-content">
<p>No</p>
</div>
</div>
</div>
Max-height to none is the issue here, you should give a value in pixels and play with the transition seconds.
Nothing else should change.Check my solution.
.so-accordion-wrapper {
padding-top: 2.5rem;
overflow: visible;
border-bottom: 1px solid #eaeaea;
margin-left: auto;
margin-right: auto;
position: relative;
max-width: 820px;
}
.so-tab {
position: relative;
width: 100%;
border-top: 1px solid #eaeaea;
overflow: hidden;
padding-left: 20px;
padding-right: 20px;
}
.so-tab label {
position: relative;
display: block;
padding: 0 25px 0 0;
margin-bottom: 15px;
margin-top: 15px;
line-height: normal;
cursor: pointer;
letter-spacing: 0.2em;
text-transform: uppercase;
font-size: 12px;
}
.so-tab input {
position: absolute;
opacity: 0;
}
.so-tab-content {
max-height:0px;
overflow: hidden;
transition: max-height .75s; //increase the seconds for more delay
}
/* :checked */
.so-tab input:checked ~ .so-tab-content {
max-height:100px;
}
/* Icon */
.so-tab label::after {
position: absolute;
right: 0;
top: -5px;
font-size: 1.5em;
color: #959595;
display: block;
-webkit-transition: all 0.50s ease;
-moz-transition: all 0.50s ease;
-o-transition: all 0.50s ease;
transition: all 0.50s ease;
}
.so-tab input[type=checkbox] + label::after {
content: "+";
}
.so-tab input[type=radio] + label::after {
content: "\25BC";
}
.so-tab input[type=checkbox]:checked + label::after {
transform: rotate(315deg);
}
.so-tab input[type=radio]:checked + label::after {
transform: rotateX(180deg);
}
<div class="so-accordion-wrapper">
<div class="so-tab"><input id="so-tab-1" type="checkbox" name="tabs"> <label for="so-tab-1">INGREDIENTS</label>
<div class="so-tab-content">
<p>Yes</p>
</div>
</div>
<div class="so-tab">
<input id="so-tab-2" type="checkbox" name="tabs">
<label for="so-tab-2">PRECAUTION</label>
<div class="so-tab-content">
<p>No</p>
</div>
</div>
</div>
i have a login form. The password label not floating when the browser using password manager auto completion. Here's the preview. Thanks (input floating label not floating on login form auto completion)and please find the attached image above. (Hello i have a login form. The password label not floating when the browser using password manager auto completion. Here's the preview. Thanks, i really love this project!)
/* login form stylings ------------------------------- */
.group {
position: relative;
margin-bottom: 30px;
}
input {
font-size: 1rem;
padding: 8px 5px 4px 5px;
display: block;
width: 100%;
border: none;
border-bottom: 1px solid #ced4da;
}
input:focus {
outline: none;
}
/* LABEL ======================================= */
.labe {
color: #999;
font-size: 1rem;
font-weight: normal;
position: absolute;
pointer-events: none;
left: 5px;
top: 10px;
transition: 0.2s ease all;
-moz-transition: 0.2s ease all;
-webkit-transition: 0.2s ease all;
}
/* active state */
input:focus ~ .labe, input:valid ~ .labe {
top: -20px;
font-size: 14px;
color: #fb9f18;
}
/* BOTTOM BARS ================================= */
.bar {
position: relative;
display: block;
width: 100%;
}
.bar:before, .bar:after {
content: '';
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: #fb9f18;
transition: 0.2s ease all;
-moz-transition: 0.2s ease all;
-webkit-transition: 0.2s ease all;
}
.bar:before {
left: 50%;
}
.bar:after {
right: 50%;
}
/* active state */
input:focus ~ .bar:before, input:focus ~ .bar:after {
width: 50%;
}
/* HIGHLIGHTER ================================== */
.highlight {
position: absolute;
height: 60%;
width: 100px;
top: 25%;
left: 0;
pointer-events: none;
opacity: 0.5;
}
/* active state */
input:focus ~ .highlight {
-webkit-animation: inputHighlighter 0.3s ease;
-moz-animation: inputHighlighter 0.3s ease;
animation: inputHighlighter 0.3s ease;
}
/* ANIMATIONS ================ */
#-webkit-keyframes inputHighlighter {
from {
background: #fb9f18;
}
to {
width: 0;
background: transparent;
}
}
#-moz-keyframes inputHighlighter {
from {
background: #fb9f18;
}
to {
width: 0;
background: transparent;
}
}
#keyframes inputHighlighter {
from {
background: #fb9f18;
}
to {
width: 0;
background: transparent;
}
}
<form class="text-center">
<div class="group">
<input type="text" id="eMail" [(ngModel)]="loginEmail" #eMail="ngModel" name="loginEmail"
autocomplete="off" required >
<span class="bar"></span>
<label class="labe " for="eMail"><i class="far fa-user mr-2"></i> Email or Username</label>
</div>
<div class="group">
<input [type]="view ? 'text' : 'password'" type="password" id="password" [(ngModel)]="loginPassword"
autocomplete="off"
#password="ngModel" name="loginpwd" required>
<span class="bar"></span>
<label class="labe" for="password"><i class="fa fa-key mr-2"></i> Password</label>
<a class="hiddenPass" (click)='view = !view'><i class="far"
[ngClass]="{'fa-eye': view, 'fa-eye-slash':!view}"></i></a>
</div>
<div *ngIf="error" class=" alert alert-danger alert-dismissible" style="font-size: .8rem;"><i
class="fas fa-exclamation-triangle mx-1"></i>{{error}}</div>
<div class="d-flex justify-content-around">
<div class="boxes">
<input type="checkbox" class="asi" id="box-1">
<label for="box-1">Remember me</label>
</div>
<div>
<a class="fpwd" routerLink="/recoverpwd"> Forgot password?</a>
</div>
</div>
<div class=" mt-0 mb-0">
<button class="login-button" type="submit btn"
(click)="Login(loginEmail,loginPassword)">Sign in
</button>
<i *ngIf="loading" class="fas fa-spinner fa-pulse" style="color: #f1bf18; font-size: 20px;"></i>
</div>
<p class="awd">Don't have an Account?
<a class="fpwd" routerLink="/register">Register</a>
</p>
</form>
This might help you for Chrome (-webkit-autofill)
input:focus ~ .labe,
input:valid ~ .labe,
input:-webkit-autofill ~ .labe {
top: -20px;
font-size: 14px;
color: #fb9f18;
}
However, I think the idea here would be that once the browser has auto filled your fields, you'd fire an onChange event, which would update your model, in turn applying a class to say the field has a value.
I don't know enough about Angular to show example code of how that'd work.
I have a Mobile menu that should be forming X when clicked, however it would not respond and is stuck on its shape. I don't know why it acted that why, but as far as I have analyzed, this code should animate the Menu to form X when clicked. I am attaching the code for reference.
These are the CSS and HTML
/* Checkbox Hack */
input[type=checkbox] {
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0;
z-index: 2;
-webkit-touch-callout: none;
}
/* Default State */
.divko {
background: green;
width: 400px;
height: 100px;
line-height: 100px;
color: white;
text-align: center;
}
/* Toggled State */
.myspan {
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 0px;
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), opacity 0.55s ease;
}
.myspan:first-child {
transform-origin: 0% 0%;
}
.myspan:nth-last-child(2) {
transform-origin: 0% 100%;
}
input[type=checkbox]:checked ~ .myspan {
opacity: 1;
transform: rotate(45deg) translate(-2px, -1px);
background: #232323;
}
input[type=checkbox]:checked ~ .divko {
background: red;
}
<div for="toggle-1"> <span class="myspan"></span>
<span class="myspan"></span>
<span class="myspan"></span></div>
<input type="checkbox" id="toggle-1">
<div class="divko">I'm controlled by toggle. No JavaScript!</div>
Here is the dabblet
http://dabblet.com/gist/5b4667ecc7255c228cd488c080140d95
Put the checkbox before the div I've give the .menu class to, and apply the rule on input[type=checkbox]:checked ~ .menu > .myspan.
/* Checkbox Hack */
input[type=checkbox] {
display: block;
width: 40px;
height: 32px;
position: absolute;
top: -7px;
left: -5px;
cursor: pointer;
opacity: 0;
z-index: 2;
-webkit-touch-callout: none;
}
/* Default State */
.divko {
background: green;
width: 400px;
height: 100px;
line-height: 100px;
color: white;
text-align: center;
}
/* Toggled State */
.myspan {
display: block;
width: 33px;
height: 4px;
margin-bottom: 5px;
position: relative;
background: #cdcdcd;
border-radius: 3px;
z-index: 1;
transform-origin: 4px 2px;
transition: transform 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), background 0.5s cubic-bezier(0.77, 0.2, 0.05, 1.0), opacity 0.55s ease;
}
input[type=checkbox]:checked ~ .menu > .myspan {
opacity: 1;
background: #232323;
}
input[type=checkbox]:checked ~ .menu > .myspan:first-child {
transform: rotate(45deg);
}
input[type=checkbox]:checked ~ .menu > .myspan:nth-child(2) {
transform: translate(-100px);
}
input[type=checkbox]:checked ~ .menu > .myspan:last-child {
transform: rotate(-45deg);
}
input[type=checkbox]:checked ~ .divko {
background: red;
}
<input type="checkbox" id="toggle-1">
<div for="toggle-1" class="menu">
<span class="myspan"></span>
<span class="myspan"></span>
<span class="myspan"></span>
</div>
<div class="divko">I'm controlled by toggle. No JavaScript!</div>
I'm trying to understand where the problem in my CSS is, but I really don't have any clue what is wrong.
Basically, I'm styling the default checkbox style with CSS. It works well until you try to check the checkbox.
The idea behind my code is when you check the checkbox, it should increase the size and change the background colour to red. In addition, it should keep the style till you unchecked the box (manually).
Do you have any idea where the problem is? In my opinion the problem is where the "input[type="checkbox"]:checked .check-box-effect {" begins.
Please find the code below
label {
display: inline-block;
color: #fff;
cursor: pointer;
position: relative;
}
label .check-box-effect {
display: inline-block;
position: relative;
background-color: transparent;
width: 25px;
height: 25px;
border: 2px solid #dcdcdc;
border-radius: 10%;
}
label .check-box-effect:before {
content: "";
width: 0px;
height: 2px;
border-radius: 2px;
background: #626262;
position: absolute;
transform: rotate(45deg);
top: 13px;
left: 9px;
transition: width 50ms ease 50ms;
transform-origin: 0% 0%;
}
label .check-box-effect:after {
content: "";
width: 0;
height: 2px;
border-radius: 2px;
background: #626262;
position: absolute;
transform: rotate(305deg);
top: 16px;
left: 10px;
transition: width 50ms ease;
transform-origin: 0% 0%;
}
label:hover .check-box-effect:before {
width: 5px;
transition: width 100ms ease;
}
label:hover .check-box-effect:after {
width: 10px;
transition: width 150ms ease 100ms;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]:checked .check-box-effect {
background-color: red !important;
transform: scale(1.25);
}
input[type="checkbox"]:checked .check-box-effect:after {
width: 10px;
background: #333;
transition: width 150ms ease 100ms;
}
input[type="checkbox"]:checked .check-box-effect:before {
width: 5px;
background: #333;
transition: width 150ms ease 100ms;
}
input[type="checkbox"]:checked:hover .check-box-effect {
background-color: #dcdcdc;
transform: scale(1.25);
}
input[type="checkbox"]:checked:hover .check-box-effect:after {
width: 10px;
background: #333;
transition: width 150ms ease 100ms;
}
input[type="checkbox"]:checked:hover .check-box-effect:before {
width: 5px;
background: #333;
transition: width 150ms ease 100ms;
}
<label>
<input type="checkbox" id="chkProdTomove" />
<span class="check-box-effect"></span>
</label>
You need to change all checked selectors to this:
input[type="checkbox"]:checked + .check-box-effect:before
label {
display: inline-block;
color: #fff;
cursor: pointer;
position: relative;
}
label .check-box-effect {
display: inline-block;
position: relative;
background-color: transparent;
width: 25px;
height: 25px;
border: 2px solid #dcdcdc;
border-radius: 10%;
}
label .check-box-effect:before {
content: "";
width: 0px;
height: 2px;
border-radius: 2px;
background: #626262;
position: absolute;
transform: rotate(45deg);
top: 13px;
left: 9px;
transition: width 50ms ease 50ms;
transform-origin: 0% 0%;
}
label .check-box-effect:after {
content: "";
width: 0;
height: 2px;
border-radius: 2px;
background: #626262;
position: absolute;
transform: rotate(305deg);
top: 16px;
left: 10px;
transition: width 50ms ease;
transform-origin: 0% 0%;
}
label:hover .check-box-effect:before {
width: 5px;
transition: width 100ms ease;
}
label:hover .check-box-effect:after {
width: 10px;
transition: width 150ms ease 100ms;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]:checked + .check-box-effect {
background-color: red !important;
transform: scale(1.25);
}
input[type="checkbox"]:checked + .check-box-effect:after {
width: 10px;
background: #333;
transition: width 150ms ease 100ms;
}
input[type="checkbox"]:checked + .check-box-effect:before {
width: 5px;
background: #333;
transition: width 150ms ease 100ms;
}
input[type="checkbox"]:checked:hover + .check-box-effect {
background-color: #dcdcdc;
transform: scale(1.25);
}
input[type="checkbox"]:checked:hover + .check-box-effect:after {
width: 10px;
background: #333;
transition: width 150ms ease 100ms;
}
input[type="checkbox"]:checked:hover + .check-box-effect:before {
width: 5px;
background: #333;
transition: width 150ms ease 100ms;
}
<label>
<input type="checkbox" id="chkProdTomove" />
<span class="check-box-effect"></span>
</label>
You need to target the next element when the checkbox is checked:
input[type="checkbox"]:checked + .check-box-effect {
background-color: red !important;
transform: scale(1.25);
}
Your current code is trying to target the .check-box-effect if it would be a child of the checkbox.
So I've styled my radio input using the css below. However in Firefox, a completely different radio appears and I am unable to style it at all.
It works perfectly in safari and chrome yet I cannot seem to figure out why it isn't working in Firefox.
input[type=checkbox] {
border: 0px;
cursor: pointer;
height: 20px;
margin: 0px 10px 0px 0px;
position: relative;
overflow: hidden;
vertical-align: -5px;
width: 20px;
}
input[type=checkbox]:before {
background-color: transparent;
border: 2px solid #E0E0E0;
content: '';
display: block;
height: 20px;
left: 0px;
opacity: 1;
position: absolute;
transition: opacity .15s linear;
top: 0px;
width: 20px;
}
input[type=checkbox]:after {
border: 2px solid #EC407A;
content: '';
display: block;
height: 23px;
left: -5px;
opacity: 0;
position: absolute;
top: -9px;
transform: rotate(-45deg);
-webkit-transform: rotate(-45deg);
transition: opacity .15s linear;
width: 27px;
}
input[type=checkbox]:checked:before {
opacity: 0;
}
input[type=checkbox]:checked:after {
opacity: 1;
}
input[type=checkbox]:focus {
box-shadow: none;
outline: 0px;
}
.radio-wrapper {
position: relative;
}
input[type='radio'] {
-webkit-appearance: none;
-moz-appearance: none;
-ms-appearance: none;
-o-appearance: none;
appearance: none;
position: relative;
right: 0;
bottom: 0;
left: 0;
height: 20px;
width: 20px;
-webkit-transition: all 0.15s ease-out 0s;
-moz-transition: all 0.15s ease-out 0s;
transition: all 0.15s ease-out 0s;
background: #cbd1d8;
border: none;
color: #fff;
cursor: pointer;
display: inline-block;
outline: none;
position: relative;
border-radius: 50%;
}
#-webkit-keyframes click-wave {
0% {
height: 40px;
width: 40px;
opacity: 0.35;
position: relative;
}
100% {
height: 200px;
width: 200px;
margin-left: -80px;
margin-top: -80px;
opacity: 0.0;
}
}
#-moz-keyframes click-wave {
0% {
height: 40px;
width: 40px;
opacity: 0.35;
position: relative;
}
100% {
height: 200px;
width: 200px;
margin-left: -80px;
margin-top: -80px;
opacity: 0.0;
}
}
#keyframes click-wave {
0% {
height: 40px;
width: 40px;
opacity: 0.35;
position: relative;
}
100% {
height: 200px;
width: 200px;
margin-left: -80px;
margin-top: -80px;
opacity: 0.0;
}
}
.option-input {
-webkit-transition: all 0.15s ease-out 0s;
-moz-transition: all 0.15s ease-out 0s;
transition: all 0.15s ease-out 0s;
background: #7CE1C9;
border: none;
color: #fff;
cursor: pointer;
display: inline-block;
outline: none;
position: relative;
margin-right: 0.5rem;
}
.option-input:hover {
background: #9faab7;
}
.option-input:checked {
background: #7CE1C9;
}
.option-input:checked::before {
height: 20px;
width: 20px;
position: relative;
content: '\2716';
display: inline-block;
font-size: 14.66667px;
text-align: center;
line-height: 20px;
}
.option-input:checked::after {
-webkit-animation: click-wave 0.65s;
-moz-animation: click-wave 0.65s;
animation: click-wave 0.65s;
background: #7CE1C9;
content: '';
display: block;
position: relative;
}
.option-input.radio {
border-radius: 50%;
}
.option-input.radio::after {
border-radius: 50%;
}
input[type='radio'] + label {
user-select: none;
cursor: pointer;
padding-left: 30px;
}
input[type='radio'] + label:before,
input[type='radio'] + label:after {
background: #fff;
background-clip: padding-box;
border: 2px solid #EC407A;
border-radius: 50%;
bottom: 3px;
content: '';
display: block;
height: 16px;
left: 3px;
margin-top: -8px;
position: absolute;
top: 50%;
transition: all 0.3s ease;
width: 16px;
}
input[type='radio'] + label:after {
background: #7CE1C9;
border: 2px solid #fff;
transform: scale(0);
-wekbit-transform: scale(0);
transition: all 0.3s ease;
}
input[type='radio']:focus + label:before {
box-shadow: 0 0 5px #EC407A;
}
input[type='radio']:checked + label:before {
border-color: #EC407A;
}
input[type='radio']:checked + label:after {
transform: scale(0.75, 0.75);
-webkit-transform: scale(0.75, 0.75);
}
`
<form>
<li class='initialForm'><span class='optionText'>$option1</span><strong><input type='radio' class='option-input radio option1' id='$id' value='1' name='option'></strong>
</li>
<li class='initialForm'><span class='optionText'>$option2</span><strong><input type='radio' class='option-input radio option2' id='$id' value='2' name='option'></strong>
</li>
</form>
You are using -webkit CSS prefixes, which is specifically for Chrome and Safari (or webkit based browsers).
You should ALSO use -moz CSS prefixes, specifically for Firefox. And, of course, if you want to support IE, they may have additionally or different stylings for certain methods.
Specifically for your transform method, in Firefox it is considered experimental, and perhaps -moz-transform is more appropriate.
Source: https://clarknikdelpowell.com/blog/styling-radio-buttons-select-boxes-in-firefox/
Even though it’s a part of Chrome, Safari and Firefox (-webkit-appearance, -moz-appearance), isn’t actually CSS. A lot of people use -webkit-appearance:none to reset the appearance of everything from buttons, inputs, you name it. However, there are a couple of Firefox bugs that make -moz-appearance:none a dangerous proposition.
Since appearance does not work completely on both checkboxes and radio buttons. You can still style radio buttons, you’re just going to have to use a bit of trickery in order to pull it off. Here’s how you’d do it.
Set the radio input to display: none.
Style a span adjacent to the radio button the way you’d like to style the radio button.
Toggle its appearance using the :checked attribute.
For Browser compatibility and further info see source
Toggle its appearance using the :checked attribute.
I found this blog post online and it tackles the problem you are having: https://clarknikdelpowell.com/blog/styling-radio-buttons-select-boxes-in-firefox/
edit:
In general, it's considered bad practice to style radio buttons directly. The reason you are having an issue is because -webkit-appearance, -moz-appearance is not actually CSS. Since you can't style the radio buttons directly, you have to use a bit of a work around.
Set the radio input to display: none.
Style a span adjacent to the radio button the way you’d like to style the radio button.
Toggle its appearance using the :checked attribute.
I sketched up a basic example on jsFiddle using some of the code you specified: https://jsfiddle.net/o3nurghw/2/
HTML:
<form>
<li class='initialForm'>
<span class='optionText'>$option1</span>
<input type='radio' class='option-input radio option1' id='$id' value='1' name='option' />
<span class="overlay"></span> <!-- the adjacent span -->
</li>
<li class='initialForm'>
<span class='optionText'>$option2</span>
<input type='radio' class='option-input radio option2' id='$id' value='2' name='option' />
<span class="overlay"></span> <!-- the adjacent span -->
</li>
</form>
CSS:
.initialForm {
margin-bottom: .5em;
display: block;
cursor: pointer;
font-size: 16px;
line-height: 1em;
}
.overlay {
position: relative;
right: 0;
bottom: 0;
left: 0;
height: 20px;
width: 20px;
-webkit-transition: all 0.15s ease-out 0s;
-moz-transition: all 0.15s ease-out 0s;
transition: all 0.15s ease-out 0s;
background: #cbd1d8;
border: none;
color: #fff;
cursor: pointer;
display: inline-block;
outline: none;
position: relative;
border-radius: 50%;
}
.radio {
display: none;
}
.radio:checked + span:before {
width: .75em;
height: .75em;
margin: .125em;
display: block;
content: " ";
background-color: #666;
border-radius: 100%;
}