Button rounded border on hover not working - html

I have a button and I used animation to show borders when hovering over that button. But borders work perfectly on top and bottom but on left and right there are not showing properly.
I want borders to be rounded as here:
My Outcome:
button {
position: relative;
border-radius: 100px;
overflow: hidden;
}
button::before,
button::after {
content: "";
width: 0;
height: 2px;
position: absolute;
transition: all 0.2s linear;
background: #fff;
}
span::before,
span::after {
content: "";
width: 2px;
height: 0;
position: absolute;
transition: all 0.2s linear;
background: #fff;
}
button:hover::before,
button:hover::after {
width: 100%;
}
button:hover span::before,
button:hover span::after {
height: 100%;
}
.btn-3::after {
left: 0;
bottom: 0;
transition-delay: 0.6s;
}
.btn-3 span::after {
transition-delay: 0.4s;
right: 0;
bottom: 0;
}
.btn-3::before {
right: 0;
top: 0;
transition-delay: 0.2s;
}
.btn-3 span::before {
transition-delay: 0s;
left: 0;
top: 0;
}
.btn-3:hover::after {
transition-delay: 0s;
}
.btn-3:hover span::after {
transition-delay: 0.2s;
}
.btn-3:hover::before {
transition-delay: 0.4s;
}
.btn-3:hover span::before {
transition-delay: 0.6s;
}
<button (click)="openDialog()"
class="extended-fab-button btn-3"
mat-fab color="primary">
<span class="extended-fab-button__text">Test File</span>
</button>

If you remove your border-radius: 100px; rule, then your button will have the shape you described as desirable in your question.
button {
position: relative;
overflow: hidden;
}
button::before,
button::after {
content: "";
width: 0;
height: 2px;
position: absolute;
transition: all 0.2s linear;
background: #fff;
}
span::before,
span::after {
content: "";
width: 2px;
height: 0;
position: absolute;
transition: all 0.2s linear;
background: #fff;
}
button:hover::before,
button:hover::after {
width: 100%;
}
button:hover span::before,
button:hover span::after {
height: 100%;
}
.btn-3::after {
left: 0;
bottom: 0;
transition-delay: 0.6s;
}
.btn-3 span::after {
transition-delay: 0.4s;
right: 0;
bottom: 0;
}
.btn-3::before {
right: 0;
top: 0;
transition-delay: 0.2s;
}
.btn-3 span::before {
transition-delay: 0s;
left: 0;
top: 0;
}
.btn-3:hover::after {
transition-delay: 0s;
}
.btn-3:hover span::after {
transition-delay: 0.2s;
}
.btn-3:hover::before {
transition-delay: 0.4s;
}
.btn-3:hover span::before {
transition-delay: 0.6s;
}
<button (click)="openDialog()"
class="extended-fab-button btn-3"
mat-fab color="primary">
<span class="extended-fab-button__text">Test File</span>
</button>

Related

Is it possible to prevent a CSS transition reversing off hover?

I have a hover animation that I have created with CSS. When the user hovers over the link the underline transitions from left to right changing the colour from black to grey. Currently as you would expect when the user moves their mouse off the link the transition reverses to start state.
I wondered if it is possible to prevent this reverse transition and instead fade the underline back to the colour black (the original start state)?
Here is a jsfiddle to work with.
Any suggestions/advise would be most welcome.
a.btn--tertiary {
padding-left: 0;
padding-right: 0;
background-color: transparent;
color: #000;
border: 0;
position: relative;
padding-bottom: 5px;
text-transform: uppercase;
text-decoration: none;
font-size: 40px;
}
.btn--tertiary:before {
content: '';
height: 2px;
right: 0;
width: 100%;
background: #000;
position: absolute;
bottom: 0;
opacity: 1;
transition: width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
z-index: 2;
border-left: 10px solid transparent;
}
.btn--tertiary:after {
content: '';
height: 2px;
left: 0;
right: auto;
width: 0%;
background: grey;
position: absolute;
bottom: 0;
transition: width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0.1s;
z-index: 3;
}
.btn--tertiary:hover:before,
.btn--tertiary:focus:before {
width: 0%;
border-left: 20px solid $white;
}
.btn--tertiary:hover::after,
.btn--tertiary:focus::after {
right: 0;
width: 100%;
}
Yes, it is indeed. The trick is to make the width transition out take 0s with a delay of 1s.
html,
body {
margin: 0;
padding: 0;
}
a.btn--tertiary {
padding-left: 0;
padding-right: 0;
background-color: transparent;
color: #000;
border: 0;
position: relative;
padding-bottom: 5px;
text-transform: uppercase;
text-decoration: none;
font-size: 40px;
}
.btn--tertiary::before {
content: '';
height: 2px;
right: 0;
width: 100%;
background: #000;
position: absolute;
bottom: 0;
transition: width 0s;
z-index: 2;
border-left: 10px solid transparent;
}
.btn--tertiary::after {
content: '';
height: 2px;
left: 0;
right: auto;
width: 0%;
background: grey;
position: absolute;
bottom: 0;
opacity: 0;
transition: opacity .5s, width 0s .5s;
z-index: 3;
}
.btn--tertiary:hover:before,
.btn--tertiary:focus:before {
width: 0%;
border-left: 20px solid $white;
transition: width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
}
.btn--tertiary:hover::after,
.btn--tertiary:focus::after {
right: 0;
width: 100%;
opacity: 1;
transition: opacity 0s, width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0.1s;
}
Button
Fiddle.
You can try like below. Check the comments for the details:
a.btn--tertiary {
color: #000;
position: relative;
padding-bottom: 5px;
display:inline-block;
text-decoration:none;
overflow:hidden;
font-size: 40px;
}
.btn--tertiary:before,
.btn--tertiary:after {
content: '';
height: 2px;
position: absolute;
bottom: 0;
}
.btn--tertiary:before {
right: 0;
width: 100%;
background: #000;
border-left: 20px solid #fff;
transition:
background 2s cubic-bezier(0.100, 0.600, 0.350, 1.000); /* transition the background on mouseout*/
}
.btn--tertiary:after {
left: 0;
width: 0%;
background: red;
}
.btn--tertiary:hover:before,
.btn--tertiary:focus:before {
width: 0%;
background: red;
transition:
width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s, /* visible transition of width on hover */
background 0s 1s; /* no transition but a background change after 1s */
}
.btn--tertiary:hover::after,
.btn--tertiary:focus::after {
right: 0;
width: 100%;
transition:
width 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0.1s; /* visible transition of width on hover */
}
Button
I hope this would help, please see the example below.
div {
text-align: center;
margin-top: 20px;
}
.btn--tertiary {
text-decoration: none;
font-family: sans-serif;
text-transform: uppercase;
display: inline-block;
position: relative;
overflow: hidden;
font-size: 45px;
color: black;
}
.btn--tertiary::before {
position: absolute;
content: '';
width: 100%;
height: 3px;
bottom: 0;
left: 0;
background: gray;
transform: scale(0, 1);
transform-origin: right;
transition: transform 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
}
.btn--tertiary:hover::before {
transform: scale(1, 1);
transform-origin: left;
transition: transform 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) .1s;
}
.btn--tertiary::after {
position: absolute;
content: '';
width: 100%;
height: 3px;
bottom: 0;
right: 0;
background: black;
transform: scale(1, 1);
transform-origin: left;
transition: transform 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) .1s;
}
.btn--tertiary:hover::after {
transform: scale(0, 1);
transform-origin: right;
transition: transform 1s cubic-bezier(0.100, 0.600, 0.350, 1.000) 0s;
}
<div>
Button
</div>

Changing hovering behavior in scss

How can I make the "Menu" Button remain in hover as long as the mouse/pointer remains in the menu? When the pointer points on Twitter for example I want the menu button to show Home.
Like this:
And not like this:
This is the Codepen example: https://codepen.io/fotios_tragopoulos/pen/YzWyZJj
This is the code:
body {
background-color: #010101;
color: rgba(255, 255, 255, 0.7);
font-family: 'Lato', sans-serif;
margin: 20px;
}
.menu {
text-transform: uppercase;
color: rgba(255, 255, 255, 0.8);
display: inline-block;
cursor: pointer;
pointer-events: none;
position: absolute;
bottom: 20px;
left: 20px;
&:hover {
pointer-events: all;
.spacer {
&:before {
width: 100%;
transition-delay: 0s;
}
}
.item {
opacity: 1;
top: 0px;
&:nth-child(1) {
transition-delay: 0.25s;
}
&:nth-child(2) {
transition-delay: 0.3s;
}
&:nth-child(3) {
transition-delay: 0.35s;
}
&:nth-child(4) {
transition-delay: 0.4s;
}
&:nth-child(5) {
transition-delay: 0.45s;
}
&:nth-child(6) {
transition-delay: 0.5s;
}
&:nth-child(7) {
transition-delay: 0.55s;
}
&:nth-child(8) {
transition-delay: 0.6s;
}
&:nth-child(9) {
transition-delay: 0.65s;
}
&:nth-child(10) {
transition-delay: 0.7s;
}
}
}
}
.label {
display: inline-block;
cursor: pointer;
pointer-events: all;
}
.spacer {
display: inline-block;
width: 80px;
margin-left: 15px;
margin-right: 15px;
vertical-align: middle;
cursor: pointer;
position: relative;
&:before {
content: "";
position: absolute;
border-bottom: 1px solid #ffffff;
height: 1px;
width: 0%;
transition: width 0.25s ease;
transition-delay: 0.7s;
}
}
.item {
position: relative;
display: inline-block;
margin-right: 30px;
top: 10px;
opacity: 0;
transition: opacity 0.5s ease, top 0.5s ease;
transition-delay: 0;
&:hover {
span {
color: #ff0000;
}
}
&:nth-child(1) {
transition-delay: 0.45s;
}
&:nth-child(2) {
transition-delay: 0.4s;
}
&:nth-child(3) {
transition-delay: 0.35s;
}
&:nth-child(4) {
transition-delay: 0.3s;
}
&:nth-child(5) {
transition-delay: 0.25s;
}
&:nth-child(6) {
transition-delay: 0.2s;
}
&:nth-child(7) {
transition-delay: 0.15s;
}
&:nth-child(8) {
transition-delay: 0.1s;
}
&:nth-child(9) {
transition-delay: 0.05s;
}
&:nth-child(10) {
transition-delay: 0s;
}
}
span {
transition: color 0.5s ease;
}
.btn-flip {
opacity: 1;
outline: 0;
color: #fff;
line-height: 40px;
position: relative;
text-align: center;
letter-spacing: 1px;
display: inline-block;
text-decoration: none;
font-family: 'Open Sans';
text-transform: uppercase;
&:hover {
&:after {
opacity: 1;
transform: translateY(0) rotateX(0);
}
&:before {
opacity: 0;
transform: translateY(50%) rotateX(90deg);
}
}
&:after {
top: 0;
left: 0;
opacity: 0;
width: 100%;
color: #323237;
display: block;
transition: 0.5s;
position: absolute;
background: #adadaf;
content: attr(data-back);
transform: translateY(-50%) rotateX(90deg);
}
&:before {
top: 0;
left: 0;
opacity: 1;
color: #adadaf;
display: block;
padding: 0 30px;
line-height: 40px;
transition: 0.5s;
position: relative;
background: #323237;
content: attr(data-front);
transform: translateY(0) rotateX(0);
}
}
<div class="menu">
<div class="spacer"></div>
<div class="item"><span>Twitter</span></div>
<div class="item"><span>Instagram</span></div>
<div class="item"><span>Flickr</span></div>
<div class="item"><span>Behance</span></div>
<div class="item"><span>MixCloud</span></div>
</div>
You can add the same rules inside .menu:
.menu {
...
&:hover {
.btn-flip {
&:after {
opacity: 1;
transform: translateY(0) rotateX(0);
}
&:before {
opacity: 0;
transform: translateY(50%) rotateX(90deg);
}
}

Hover link border animation

I would like to know how to animate the link when I hover on it. I want the top border to move down and the bottom border to move up. The borders should fade away, when the animation ends. When I hover on the link, the borders should appear and show the animation.
HTML:
<ul>
<li class="active">Home</li>
<li>About Me</li>
<li>My Passion</li>
</ul>
CSS:
ul li a {
border-bottom: 3px transparent solid;
border-top: 3px transparent solid;
}
ul li a::before {
position: absolute;
left: 0;
top: 0;
visibility: hidden;
-moz-transition: 0.3s;
-o-transition: 0.3s;
-webkit-transition: 0.3s;
transition: 0.3s;
}
ul li a::after {
position: absolute;
left: 0;
top: 100%;
visibility: hidden;
-moz-transition: 0.3s;
-o-transition: 0.3s;
-webkit-transition: 0.3s;
transition: 0.3s;
}
ul li a:hover {
color: blue;
}
ul li a:hover::before {
visibility: visible;
top: 100%;
background: blue;
}
ul li a:hover::after {
visibility: visible;
top: 0;
background: blue;
}
Expected result:
I've re-created the example in your GIF.
For the text hover effect, make sure to use transition to ease the effect, e.g.:
a {
color: white;
text-decoration: none;
transition: 800ms ease color;
display: block;
}
a:hover {
color: gold;
}
I'm displaying the a tag as block to make sure it covers the whole li elements when hovered.
When using CSS pseudo elements always set a content property (content: '' is you want to style it):
li::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 5px;
background: gold;
opacity: 0;
}
Instead of using a border, I'm animating the pseudo before en after elements on hover. You can do this by using CSS keyframes.
li:hover::before {
opacity: 1;
animation: flyDown 300ms ease forwards;
}
li:hover::after {
opacity: 1;
animation: flyUp 300ms ease forwards;
}
#keyframes flyDown {
from {
transform: translateY(0px)
}
to {
transform: translateY(90px)
}
}
#keyframes flyUp {
from {
transform: translateY(00px)
}
to {
transform: translateY(-90px)
}
}
Please find jsfiddle here: https://jsfiddle.net/sanderdebr/fn4pgwv6/30/
---html---
<span class="a-border" onclick="menuclick(this)">ABOUT US</span>
<span class="a-border" onclick="menuclick(this)">CREATERS</span>
<span class="a-border" onclick="menuclick(this)">NEWS</span>
<span class="a-border" onclick="menuclick(this)">CONTACT</span>
---css---
a {
text-decoration: none;
}
a:hover {
cursor: pointer;
}
.a-border {
display: inline-block;
position: relative;
color: white;
padding: 0.5rem 0.25rem;
margin: 0 1.5rem;
overflow: hidden;
}
.a-border::after {
content: "";
display: block;
position: absolute;
bottom: -8px;
left: -3%;
width: 106%
border-top: 2px solid white;
transform: scale(0, 1);
transform-origin: 0% 100%;
transition: transform 0.4s;
}
a:hover .a-border::after {
transform:scale(1, 1);
}
a.focused .a-border::after {
transform: none;
}
---js---
function menuclick(underline) {
var focused = document.getElementsByClassName("focused");
var i;
for (i = 0; i < focused.length; i++) {
var under = focused[i];
if (under.classList.contains('focused')) {
under.classList.remove('focused');
}
}
if (!underline.parentElement.classList.contains('focused')) {
underline.parentElement.classList.add('focused');
}
}

Clear user search input for search="text" using CSS

I would like add a clear input text feature to the existing search functionality. When user click the cross animation it should clear the input text instead of moving the arrows away. I have added display:none at last not valid, but not working as expected. Can someone please assist on how to implement this functionality ?.
.search-box {
position: relative;
display: inline-block;
border: 2px solid #000;
border-radius: 20px;
float:right;
}
.search-box input[type="text"] {
-webkit-appearance: none;
position: relative;
display: block;
width: 20px;
height: 20px;
margin: 0;
padding: 5px;
border: none;
border-radius: 20px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-shadow: none;
box-shadow: none;
z-index: 1;
-webkit-transition: all 0.5s ease-out 0.5s;
transition: all 0.5s ease-out 0.5s;
outline: none;
}
.search-box input[type="text"]:focus {
width: 280px;
height: 30px;
margin-right: 20px;
-webkit-transition: all 0.5s ease-out 0s;
transition: all 0.5s ease-out 0s;
}
.search-box input[type="text"]:focus + span::before {
height: 14px;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.5s;
transition: all 0.2s ease-out 0.5s;
}
.search-box input[type="text"]:focus + span::after {
visibility: visible;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.7s;
transition: all 0.2s ease-out 0.7s;
}
.search-box span {
display: block;
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 0;
z-index: 10;
}
.search-box span::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 50%;
width: 2px;
height: 8px;
margin: -4px 0 0 0;
background-color: #000;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.2s ease-out 0.2s;
transition: all 0.2s ease-out 0.2s;
}
.search-box span::after {
content: '';
visibility: hidden;
display: block;
position: absolute;
top: 0;
left: 0;
width: 2px;
height: 14px;
margin: -36px 0 0 5px;
background-color: #000;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.2s ease-out 0s;
transition: all 0.2s ease-out 0s;
}
.search-box:not(:valid) ~ span {
display: none;
}
<form name="search">
<label class="search-box">
<input type="text" />
<span></span>
</label>
</form>
https://jsfiddle.net/0wansxza/
You could do it using jQuery with that $('#element').val('');.
jQuery(document).ready(function(){
jQuery('.search-box input[type="text"]').focusout(function() {
jQuery(this).val('');
})
});
.search-box {
position: relative;
display: inline-block;
border: 2px solid #000;
border-radius: 20px;
float:right;
}
.search-box input[type="text"] {
-webkit-appearance: none;
position: relative;
display: block;
width: 20px;
height: 20px;
margin: 0;
padding: 5px;
border: none;
border-radius: 20px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-shadow: none;
box-shadow: none;
z-index: 1;
-webkit-transition: all 0.5s ease-out 0.5s;
transition: all 0.5s ease-out 0.5s;
outline: none;
}
.search-box input[type="text"]:focus {
width: 280px;
height: 30px;
margin-right: 20px;
-webkit-transition: all 0.5s ease-out 0s;
transition: all 0.5s ease-out 0s;
}
.search-box input[type="text"]:focus + span::before {
height: 14px;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.5s;
transition: all 0.2s ease-out 0.5s;
}
.search-box input[type="text"]:focus + span::after {
visibility: visible;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.7s;
transition: all 0.2s ease-out 0.7s;
}
.search-box span {
display: block;
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 0;
z-index: 10;
}
.search-box span::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 50%;
width: 2px;
height: 8px;
margin: -4px 0 0 0;
background-color: #000;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.2s ease-out 0.2s;
transition: all 0.2s ease-out 0.2s;
}
.search-box span::after {
content: '';
visibility: hidden;
display: block;
position: absolute;
top: 0;
left: 0;
width: 2px;
height: 14px;
margin: -36px 0 0 5px;
background-color: #000;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.2s ease-out 0s;
transition: all 0.2s ease-out 0s;
}
.search-box:not(:valid) ~ span {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="search">
<label class="search-box">
<input type="text" />
<span></span>
</label>
</form>
Using Just CSS. I had to modify your markup a little. To clear the input field i had to add a button that resets the form when clicked. See my code and comments below. Hope it helps
.search-box {
position: relative;
display: inline-block;
border: 2px solid #000;
border-radius: 20px;
float:right;
}
.search-box input[type="text"] {
-webkit-appearance: none;
position: relative;
display: block;
width: 20px;
height: 20px;
margin: 0;
padding: 5px;
border: none;
border-radius: 20px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-webkit-box-shadow: none;
box-shadow: none;
z-index: 11;/**Changed This**/
-webkit-transition: all 0.5s ease-out 0.5s;
transition: all 0.5s ease-out 0.5s;
outline: none;
}
/**Updated the below codes**/
.search-box input[type="text"]:focus,
.search-box .btn:focus + input{
width: 280px;
height: 30px;
margin-right: 30px;
-webkit-transition: all 0.5s ease-out 0s;
transition: all 0.5s ease-out 0s;
}
/**Updated the below codes**/
.search-box input[type="text"]:focus + span::before,
.search-box .btn:focus + input[type="text"] + span::before{
height: 14px;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.5s;
transition: all 0.2s ease-out 0.5s;
}
/**Updated the below codes**/
.search-box input[type="text"]:focus + span::after,
.search-box .btn:focus + input[type="text"] + span::after{
visibility: visible;
margin: -22px 0 0 -15px;
-webkit-transition: all 0.2s ease-out 0.7s;
transition: all 0.2s ease-out 0.7s;
}
.search-box span {
display: block;
position: absolute;
right: 0;
bottom: 0;
width: 0;
height: 0;
z-index: 10;
}
.search-box span::before {
content: '';
display: block;
position: absolute;
top: 0;
left: 50%;
width: 2px;
height: 8px;
margin: -4px 0 0 0;
background-color: #000;
-webkit-transform: rotate(-45deg);
transform: rotate(-45deg);
-webkit-transition: all 0.2s ease-out 0.2s;
transition: all 0.2s ease-out 0.2s;
}
.search-box span::after {
content: '';
visibility: hidden;
display: block;
position: absolute;
top: 0;
left: 0;
width: 2px;
height: 14px;
margin: -36px 0 0 5px;
background-color: #000;
-webkit-transform: rotate(45deg);
transform: rotate(45deg);
-webkit-transition: all 0.2s ease-out 0s;
transition: all 0.2s ease-out 0s;
}
/**
.search-box:not(:valid) ~ span {
display: none;
}**/
/**Added the below codes**/
.search-box .btn {
position: absolute;
top: 0;
right: 0;
bottom: 0;
background: transparent;
border: 0;
outline: 0;
width: 30px;
cursor: pointer;
z-index: 11;
}
<form name="search">
<label class="search-box">
<!--Added the button to clear the field on click-->
<button class="btn" type="reset"></button>
<input type="text" />
<span></span>
</label>
</form>

Checkbox CSS :checked styling

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.