So I got this CSS Custom Checkbox but transitions doesn't seem to work on it. I didn't make the code tho, I got it from here.
Here is my slightly modified version:
.checkbox {
position: absolute;
opacity: 0;
}
.checkbox + label {
position: relative;
cursor: pointer;
padding: 0;
}
.checkbox + label:before {
content: '';
margin-right: 10px;
display: inline-block;
vertical-align: text-top;
width: 20px;
height: 20px;
background: #ccf2ff;
border-radius: 6px;
box-shadow: 0 0 0 3px #99e6ff;
}
.checkbox:hover + label:before {
background: #80dfff;
}
.checkbox:focus + label:before {
box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.12);
}
.checkbox:checked + label:before {
background: #33ccff;
}
.checkbox:disabled + label {
cursor: auto;
}
.checkbox:disabled + label:before {
box-shadow: none;
background: #ddd;
}
.checkbox:checked + label:after {
content: '';
position: absolute;
left: 5px;
top: 9px;
background: white;
width: 2px;
height: 2px;
box-shadow:
2px 0 0 white,
4px 0 0 white,
4px -2px 0 white,
4px -4px 0 white,
4px -6px 0 white,
4px -8px 0 white;
transform: rotate(45deg);
}
.checkbox, .button, input, select
{
-webkit-transition-duration: 0.2s;
-moz-transition-duration: 0.2s;
-o-transition-duration: 0.2s;
transition-duration: 0.2s;
}
Every other transition works fine, it's just the checkbox thats the problem. Am I missing something here? Or is there something wrong with the code that's making transitions not work? Please help me.
You are applying your custom checkbox style to the :before pseudo element of the label tag so you just need to apply the transition to that also:
.checkbox,
.button,
input,
select,
.checkbox + label:before
{
-webkit-transition-duration: 0.2s;
-moz-transition-duration: 0.2s;
-o-transition-duration: 0.2s;
transition-duration: 0.2s;
}
Related
I have an animation that wipes from left to right on hover here. I want to have an exit animation that also goes from left to right (not right to left as shown in the demo). How can I achieve this?
.btn {
color: #31302B;
background: #FFF;
margin: 25px;
padding: 10px 0;
width: 240px;
border: 3px solid #31302B;
font-size: 14px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 2px;
display: inline-block;
text-align: center;
cursor: pointer;
box-shadow: inset 0 0 0 0 #6a0dad;
-webkit-transition: all ease 0.8s;
-moz-transition: all ease 0.8s;
transition: all ease 0.8s;
}
.btn:hover {
box-shadow: inset 240px 0 0 0 #6a0dad;
color: #fff;
}
<div class="btn">CONTAINER</div>
You could use #keyframes:
.btn {
color: #31302B;
background: #FFF;
margin: 25px;
padding: 10px 0;
width: 240px;
border: 3px solid #31302B;
font-size: 14px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 2px;
display: inline-block;
text-align: center;
cursor: pointer;
animation: out 0.8s ease;
}
#keyframes in {
from {
box-shadow: inset 0 0 0 0 #6a0dad;
color: black;
}
to {
box-shadow: inset 240px 0 0 0 #6a0dad;
color: white;
}
}
#keyframes out {
from {
box-shadow: inset -240px 0 0 0 #6a0dad;
color: white;
}
to {
box-shadow: inset 0 0 0 0 #6a0dad;
color: black;
}
}
.btn:hover {
animation: in 0.8s ease;
box-shadow: inset 240px 0 0 0 #6a0dad;
color: white;
}
<div class="btn">CONTAINER</div>
I would suggest using pseudo-element ::after and transform-origin for this.
.btn::after {
z-index: -1;
content: '';
position: absolute;
left: 0;
top: 0;
background: #6a0dad;
height: 100%;
width: 100%;
transform: scaleX(0);
transition: all ease 0.8s;
transform-origin: left;
}
.btn:hover {
color: white;
}
.btn:hover::after {
transform: scaleX(1);
transform-origin: right;
}
Add position: relative; z-index: 1; to .btn class
A simple background transition can easily do this without keyframes:
.btn {
color: #31302B;
background: #FFF;
margin: 25px;
padding: 10px 0;
width: 240px;
border: 3px solid #31302B;
font-size: 14px;
font-weight: bold;
letter-spacing: 1px;
text-transform: uppercase;
border-radius: 2px;
display: inline-block;
text-align: center;
cursor: pointer;
background:linear-gradient(#6a0dad,#6a0dad) left/0% 100% no-repeat;
transition: all ease 0.5s,background-position 0s 0.5s;
}
.btn:hover {
background-size:100% 100%;
background-position:right;
color: #fff;
}
<div class="btn">CONTAINER</div>
Related: How to animate underline from left to right?
I'm styling my checkboxes to look like toggle switches which works beautifully in Chrome, UC Browser, Safari for Windows and is a bit choppy in Firefox but acceptable. Unfortunately in Edge it doesn't work at all.
I've looked through the CSS properties I'm using and it appears as though all are supported by Edge so I don't understand what I'm missing.
.toggle{
width:34px;
height:16px;
border-radius:40px;
position:relative;
-webkit-appearance: none;
margin:2px 0 0 0px;
box-shadow: inset 1px 1px 1px rgba(0, 0, 0, 0.4);
background: -webkit-linear-gradient(#c6c6c6,#e3e3e3);
cursor:hand;cursor:pointer;pointer:hand;
outline: 0;
}
.toggle:checked{
background: -webkit-linear-gradient(#77178F,#AD73BB);
box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle:before {
content:'';
letter-spacing:1px;
color: rgba(0,0,0,.15);
font-size:10px;
font-weight:100;
text-shadow:1px 1px 1px rgba(255,255,255,1);
width:7px;
height:7px;
padding:2px;
top:2px;
left:2px;
position:absolute;
border-radius:40px;
background: linear-gradient(#ebebeb,#f1f1f1);
box-shadow: -2px 2px 8px rgba(0, 0, 0, 0.2),
-1px 1px 2px rgba(0, 0, 0, 0.3),
inset 1px 1px 1px #ffffff;
transition: all 0.4s;
}
.toggle:checked:before {
left:20px;
background:#f1f1f1;
}
.toggle:checked:after {
background: linear-gradient(#d8eec4,#5fa718);
box-shadow: inset -1px -1px 4px #417f0b,
inset 1px 1px 2px #5b9f1a;
}
<input type=checkbox class=toggle>
It looks to me like -webkit-appearance:none is not doing what it's supposed to (hide the original checkbox) but that also is supposedly supported.
If anybody has any experience with this issue and can give me some insight it would be much appreciated.
It's better to hide a checkbox, wrap it with another element (e.g. label) and add a sibling to the checkbox. You can find an example of checkbox-switch here https://www.w3schools.com/howto/howto_css_switch.asp.
Or you can adjust code below:
.toggle {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle input[type=checkbox] {
opacity: 0; /* or use display: none; to hide default checkbox */
width: 0;
height: 0;
}
.toggle .slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(#ebebeb, #f1f1f1);
box-shadow: inset 1px 1px 1px rgba(0, 0, 0, 0.4);
-webkit-transition: .4s;
transition: .4s;
}
.toggle .slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background: #ffffff;
-webkit-transition: .4s;
transition: .4s;
}
.toggle input[type=checkbox]:checked + .slider {
background: linear-gradient(#77178F,#AD73BB);
box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle input[type=checkbox]:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
.toggle .slider.round {
border-radius: 34px;
}
.toggle .slider.round:before {
border-radius: 50%;
}
<label class="toggle">
<input type="checkbox">
<span class="slider round"></span>
</label>
You could add a label to meet your requirements as a workaround. In this way you could connect a label with a checkbox and apply the styles to the label instead of the checkbox itself.
Here is my testing code.
CSS.
.toggle {
visibility: hidden;
opacity: 0;
}
.toggle + label {
width: 34px;
height: 16px;
border-radius: 40px;
position: relative;
box-shadow: inset 1px 1px 1px rgba(0, 0, 0, 0.4);
background: linear-gradient(#c6c6c6,#e3e3e3);
cursor: pointer;
outline: 0;
display: inline-block;
}
.toggle + label:before {
content: '';
letter-spacing: 1px;
color: rgba(0,0,0,.15);
font-size: 10px;
font-weight: 100;
text-shadow: 1px 1px 1px rgba(255,255,255,1);
width: 7px;
height: 7px;
padding: 2px;
top: 2px;
left: 2px;
position: absolute;
border-radius: 40px;
background: linear-gradient(#ebebeb,#f1f1f1);
box-shadow: -2px 2px 8px rgba(0, 0, 0, 0.2), -1px 1px 2px rgba(0, 0, 0, 0.3), inset 1px 1px 1px #ffffff;
transition: all 0.4s;
}
.toggle:checked + label {
background: linear-gradient(#77178F,#AD73BB);
box-shadow: inset 1px 1px 3px rgba(0, 0, 0, 0.4);
}
.toggle:checked + label:before {
left: 20px;
background: #f1f1f1;
}
.toggle:checked + label:after {
background: linear-gradient(#d8eec4,#5fa718);
box-shadow: inset -1px -1px 4px #417f0b, inset 1px 1px 2px #5b9f1a;
}
HTML
<input type="checkbox" class="toggle" id="mycheckbox">
<label for="mycheckbox" />
Adding another flexible variation of the selected answer to the mix: https://codepen.io/hawatt/pen/MWKyJJZ
HAML
.toggle-switch
%input{type: 'checkbox', id: 'away-from-desk' }
%span.toggle-handle
%label{'for' => 'away-from-desk'} Away from desk
SCSS
$toggle-width: 2.8rem;
$toggle-height: 1.5rem;
$toggle-handle-diameter: calc(#{$toggle-height} * 0.8);
.toggle-switch {
position: relative;
display: flex;
align-items: center;
input {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: $toggle-width;
height: $toggle-height;
display: inline-flex;
position: relative;
border-radius: $toggle-height;
overflow: hidden;
outline: none;
border: none;
cursor: pointer;
background-color: #c0c0c0;
transition: all ease 0.3s;
z-index: 0;
text-indent: -5000px;
}
.toggle-handle {
pointer-events: none;
display: flex;
position: absolute;
z-index: 2;
width: $toggle-handle-diameter;
height: $toggle-handle-diameter;
background: #fff;
border-radius: 50%;
left: 0;
margin: 0 0.35rem;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
transition: all ease 0.3s;
}
input:checked,
input.enabled {
background-color: dodgerblue;
& + .toggle-handle {
left: calc(#{$toggle-width} - #{$toggle-handle-diameter} - 0.25rem);
}
}
label {
cursor: pointer;
}
}
I'm trying to get a css menu working but want to use vuejs/nuxt-link instead of a traditional a href as this is a single page application Im trying to learn how to build
I have the following
How do I convert this to work with nuxt-link instead of a href
Thanks
HTML I currently have
<nav class="radial">
<input type="checkbox" id="menu" checked>
About
Resume
Blog
Github
a
<label for="menu" class='fa-bars'>Menu</label>
</nav>
I'd like to use (for example) in my html, assuming this is possible.
<nuxt-link :to="'/about'"><fa icon="bars" /></nuxt-link>
The css I currently have is as follows
nav.radial {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
position: relative;
top: -2.5rem;
width: 3rem;
height: 3rem;
margin: 0 100px;
}
nav.radial input {
display: none;
}
nav.radial > label,
nav.radial > a {
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #21618C;
color: white;
text-align: center;
font-size: 0;
line-height: 3rem;
}
nav.radial label:before,
nav.radial a:before {
font-size: 1.2rem;
color: white;
}
nav.radial a {
color: transparent;
text-decoration: none;
box-sizing: border-box;
}
nav.radial label {
border-radius: 0 0 1.5rem 1.5rem;
cursor: pointer;
box-sizing: border-box;
border-bottom: 0.25rem solid #2f2f2f;
box-shadow: 0 0.1875rem rgba(0, 0, 0, 0.25);
transition: border-bottom 0.25s, box-shadow 0.5s;
}
nav.radial input:checked ~ label {
border-bottom-width: 1px;
box-shadow: none;
}
nav.radial a[href] {
transition: top 0.1s, left 0.25s, opacity 1s, box-shadow 0.25s;
border-radius: 1.5rem;
opacity: 0;
box-shadow: 0 0 0 rgba(0, 0, 0, 0);
border-bottom: 1px solid #888;
box-sizing: border-box;
}
nav.radial a[href]:hover {
background-color: #E6EDF2;
border-bottom-color: #2c7768;
}
nav.radial input:checked ~ a[href] {
transition: top 1s, left 0.6s, box-shadow 1s, background-color 0.25s, border-bottom-color 0.25s, border-bottom-width 0.25s;
opacity: 1;
}
nav.radial a[href]:hover {
border-bottom-width: 0.25rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(1),
nav.radial input:checked ~ a[href]:nth-of-type(5) {
box-shadow: 0 -0.1875rem 0.375rem rgba(0, 0, 0, 0.25);
}
nav.radial input:checked ~ a[href]:nth-of-type(1) {
left: -4.72707721rem;
top: 0.83351125rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(2) {
left: -3.08538053rem;
top: 3.67701333rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(3) {
left: 0rem;
top: 4.8rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(4) {
left: 3.08538053rem;
top: 3.67701333rem;
}
nav.radial input:checked ~ a[href]:nth-of-type(5) {
left: 4.72707721rem;
top: 0.83351125rem;
}
many thanks for any assistance in advance
I styled up this checkbox to look like a switch. I would like to put the words "ON" and "OFF" inside of it. That's what I'm having trouble with.
Here is the codepen: http://codepen.io/anon/pen/BKMErO
CSS:
.switch-field {
display: table-cell;
vertical-align: middle;
}
input.switch {
position: absolute;
margin-left: -9999px;
visibility: hidden;
}
input.switch + label {
background-color: #f0f0f0;
border: 1px solid #ccc;
display: block;
position: relative;
cursor: pointer;
outline: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input.switch + label, input.switch + label:before, input.switch + label:after {
-webkit-border-radius: 2.4em;
-moz-border-radius: 2.4em;
-ms-border-radius: 2.4em;
-o-border-radius: 2.4em;
border-radius: 2.4em;
}
input.switch + label {
background-color: #f0f0f0;
border: 1px solid #ccc;
width: 4.8em;
height: 2.4em;
overflow: hidden;
}
input.switch + label:before, input.switch + label:after {
display: block;
position: absolute;
top: 0;
left: 0;
bottom: 0;
content: "";
}
input.switch + label:before {
background-color: #bbb;
right: 0;
-webkit-transition: background 0.3s;
-moz-transition: background 0.3s;
-o-transition: background 0.3s;
transition: background 0.3s;
}
input.switch + label:after {
background-color: #fff;
width: 2.4em;
width: calc(2.4em - 2px);
-webkit-box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
-webkit-transition: margin 0.3s;
-moz-transition: margin 0.3s;
-o-transition: margin 0.3s;
transition: margin 0.3s;
}
input.switch:checked + label:before {
background-color: green;
}
input.switch:checked + label:after {
margin-left: 2.5em;
}
HTML:
<div class="switch-field">
<input id="cmn-toggle-1" class="switch" type="checkbox">
<label for="cmn-toggle-1"></label>
</div><!-- /.switch-field -->
Give this a try
http://codepen.io/Atula/pen/ZWwdmm?editors=0100
css
content: 'ON';
padding: 10px 0;
text-align:center;
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
.switch-field {
display: table-cell;
vertical-align: middle;
}
input.switch {
position: absolute;
margin-left: -9999px;
visibility: hidden;
}
input.switch + label {
background-color: #f0f0f0;
border: 1px solid #ccc;
display: block;
position: relative;
cursor: pointer;
outline: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
input.switch + label, input.switch + label:before, input.switch + label:after {
-webkit-border-radius: 2.4em;
-moz-border-radius: 2.4em;
-ms-border-radius: 2.4em;
-o-border-radius: 2.4em;
border-radius: 2.4em;
}
input.switch + label {
background-color: #f0f0f0;
border: 1px solid #ccc;
width: 4.8em;
height: 2.4em;
overflow: hidden;
}
input.switch + label:before, input.switch + label:after {
display: block;
position: absolute;
top: 0;
left: 0;
bottom: 0;
content: "";
}
input.switch + label:before {
background-color: #bbb;
right: 0;
-webkit-transition: background 0.3s;
-moz-transition: background 0.3s;
-o-transition: background 0.3s;
transition: background 0.3s;
}
input.switch + label:after {
background-color: #fff;
width: 2.4em;
width: calc(2.4em - 2px);
-webkit-box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
-moz-box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
-webkit-transition: margin 0.3s;
-moz-transition: margin 0.3s;
-o-transition: margin 0.3s;
transition: margin 0.3s;
}
input.switch:checked + label:before {
background-color: green;
content :'ON';
text-align :left;
color:#fff;
padding:5px
}
input.switch:checked + label:after {
margin-left: 2.5em;
text-align :right;
}
</style>
</head>
<body>
<div class="switch-field">
<input id="cmn-toggle-1" class="switch" type="checkbox">
<label for="cmn-toggle-1"></label>
</div><!-- /.switch-field -->
</body>
</html>
I made a custom checkbox with css. For the checked icon i use Google's material icons. Now the only problem is that the icon is not vertically centered. How do I do that?
HTML:
<input type="checkbox" id="remember">
<label for="remember">Angemeldet bleiben</label>
CSS:
/* Basic Styling
----------------------------------------------------------------------------------------------------*/
input[type="radio"],
input[type="checkbox"] {
display: none;
}
input[type="radio"] + label,
input[type="checkbox"] + label {
margin-right: 20px;
padding-left: 30px;
cursor: pointer;
display: inline-block;
position: relative;
}
input[type="radio"] + label:before,
input[type="checkbox"] + label:before,
input[type="radio"] + label:after,
input[type="checkbox"] + label:after {
width: 20px;
height: 20px;
content: '';
top: 0;
left: 0;
color: #fafafa;
text-align: center;
position: absolute;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
/* Radios
----------------------------------------------------------------------------------------------------*/
input[type="radio"] + label:before {
border: 1px solid #eee;
border-radius: 50%;
box-shadow: inset 0 0 0 0.4em #fafafa, inset 0 0 0 1em #fafafa;
}
input[type="radio"] + label:hover:before {
border: 1px solid #eee;
border-radius: 50%;
box-shadow: inset 0 0 0 0.4em #fafafa, inset 0 0 0 1em #eee;
}
input[type="radio"]:checked + label:before {
border: 1px solid #2196F3;
border-radius: 50%;
box-shadow: inset 0 0 0 0.4em #fafafa, inset 0 0 0 1em #2196F3;
}
/* Checkboxes
----------------------------------------------------------------------------------------------------*/
input[type="checkbox"] + label:before {
font-family: 'Material Icons';
font-size: 18px;
content: '\E876';
border: 1px solid #eee;
border-radius: 2px;
background: #fafafa;
}
input[type="checkbox"] + label:hover:before {
color: #eee;
}
input[type="checkbox"]:checked + label:before {
color: #2196F3;
}
Here is what it looks like:
There are few ways to do that, but in my opinion, the best solution is with CSS vertical-align Property.
Required reading on THIS link.
Use line-height property.
input[type="radio"] + label:before,
input[type="checkbox"] + label:before,
input[type="radio"] + label:after,
input[type="checkbox"] + label:after {line-height: 19px;}
Demo:http://jsfiddle.net/k3zLj0w4/