Below code, the transition is 3 milliseconds and the issue is not really noticeable.
body {
background-color: Royalblue; /*#f0f0f0;*/
}
label {
font-family: 'Montserrat', sans-serif;
font-size: 14px;
z-index: -1;
border: 0;
color: white;
position: relative;
}
.head {
color: white;
margin-left: 44%;
font-family: monospace;
font-size: 25px;
}
.username {
height:40px;
}
.password {
height:40px;
margin-top: 30%;
}
form {
position: relative; /* Parent relative */
margin-top: 10%;
margin-left: 41%;
/*border: 1.5px solid black;*/
width: 15%;
}
input {
position: absolute;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
background: transparent;
border: 0; /* BORDER yes/no */
border-bottom: 2px solid black;
background: transparent;
outline: 0;
height: 25px;
width: 180px;
z-index: 1;
margin-top: 5px;
}
label::after {
content: '';
position: absolute;
top: 1px;
left: 0;
width: 180px;
height: 23px;
border-radius: 2px;
transition: transform .3s;
}
label::after{
z-index: -1;
background: beige; /*#a86bf;*/
transform: scale3d(1, 0, 1);
transform-origin: 0% 0%;
}
input:focus {
border-radius: 2px;
}
input:focus + label::after,
input:valid + label::after {
transform: scale3d(1, -1.3, 1);
transition-timing-function: linear;
top: -3px;
}
span {
position: relative;
margin-top: -30px;
display: block;
padding: .6em ;
padding-left: 0px;
transition: top .5s ease, font-size .5s ease;
top: 0;
}
input:focus + label > span,
input:valid + label > span {
top: -23px;
font-size: 11px;
padding-bottom: 15px;
}
/*input:focus {
outline: 1;
}*/
/*.content {
margin-top: 10%;
margin-left: 41%;
}*/
/* font-family: monospace;*/
/*transform: translate3d(0, -80%, 0); */
/* transition-timing-function: linear;*/
<p class="head">Sign In</p>
<form>
<div class="content">
<div class="username">
<input type="text" name="name" class="user-input" id="user" required /> <!--input field-->
<label class="user-label" for="user"><span>Username</span></label>
</div>
<!-- <div class="password">
<input type="text" name="name" class="pass-input" id="pass" required />
<label class="pass-label" for="pass"><span>Password</span></label>
</div> -->
</div>
</form>
But changing transform time from label:after { transition: transform .3s;} to 2 seconds then it scales like this.
Why is there some exceeding scale at the bottom when unfocusing? I tried to tweak the top property in input:focus + label::after & label::afterin attempt of fixing it but nothing's working.
Try this and let me know if this solves your issue
body {
background-color: Royalblue; /*#f0f0f0;*/
}
label {
font-family: 'Montserrat', sans-serif;
font-size: 14px;
z-index: -1;
border: 0;
color: white;
position: relative;
}
.head {
color: white;
margin-left: 44%;
font-family: monospace;
font-size: 25px;
}
.username {
height:40px;
}
.password {
height:40px;
margin-top: 30%;
}
form {
position: relative; /* Parent relative */
margin-top: 10%;
margin-left: 41%;
/*border: 1.5px solid black;*/
width: 15%;
}
input {
position: absolute;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
background: transparent;
border: 0; /* BORDER yes/no */
border-bottom: 2px solid black;
background: transparent;
outline: 0;
height: 25px;
width: 180px;
z-index: 1;
margin-top: 5px;
}
label::after {
content: '';
position: absolute;
top: 1px;
left: 0;
width: 180px;
height: 23px;
border-radius: 2px;
transition: all 2s linear;
}
label::after {
z-index: -1;
background: beige; /*#a86bf;*/
transform: scale3d(1, 0, 1);
transform-origin: 0% 0%;
}
input:focus {
border-radius: 2px;
}
input:focus + label::after,
input:valid + label::after {
transform: scale3d(1, -1.3, 1);
transition-timing-function: linear;
top: -3px;
}
span {
position: relative;
margin-top: -30px;
display: block;
padding: .6em ;
padding-left: 0px;
transition: all 2s linear;
font-size: 12px;
top: 0;
}
input:focus + label > span,
input:valid + label > span {
top: -23px;
font-size: 11px;
padding-bottom: 15px;
}
/*input:focus {
outline: 1;
}*/
/*.content {
margin-top: 10%;
margin-left: 41%;
}*/
/* font-family: monospace;*/
/*transform: translate3d(0, -80%, 0); */
/* transition-timing-function: linear;*/
<p class="head">Sign In</p>
<form>
<div class="content">
<div class="username">
<input type="text" name="name" class="user-input" id="user" required /> <!--input field-->
<label class="user-label" for="user"><span>Username</span></label>
</div>
<!-- <div class="password">
<input type="text" name="name" class="pass-input" id="pass" required />
<label class="pass-label" for="pass"><span>Password</span></label>
</div> -->
</div>
</form>
Here is what I changed :
input {
height: 40px;
margin-top: 0;
box-sizing: border-box;
}
Example
body {
background-color: Royalblue;
/*#f0f0f0;*/
}
label {
font-family: 'Montserrat', sans-serif;
font-size: 14px;
z-index: -1;
border: 0;
color: white;
position: relative;
}
.head {
color: white;
margin-left: 44%;
font-family: monospace;
font-size: 25px;
}
.username {
height: 40px;
}
.password {
height: 40px;
margin-top: 30%;
}
form {
position: relative;
margin-top: 10%;
margin-left: 41%;
width: 15%;
}
input {
position: absolute;
font-family: 'Montserrat', sans-serif;
font-size: 15px;
background: transparent;
border: 0;
/* BORDER yes/no */
border-bottom: 2px solid black;
background: transparent;
outline: 0;
height: 25px;
width: 180px;
z-index: 1;
//margin-top: 5px;
/* new */
height: 40px;
margin-top: 0;
box-sizing: border-box;
}
label::after {
content: '';
position: absolute;
top: 1px;
left: 0;
width: 180px;
height: 23px;
border-radius: 2px;
transition: transform .3s;
}
label::after {
z-index: -1;
background: beige;
/*#a86bf;*/
transform: scale3d(1, 0, 1);
transform-origin: 0% 0%;
}
input:focus {
border-radius: 2px;
}
input:focus+label::after,
input:valid+label::after {
transform: scale3d(1, -1.3, 1);
transition-timing-function: linear;
top: -3px;
}
span {
position: relative;
margin-top: -30px;
display: block;
padding: .6em;
padding-left: 0px;
transition: top .5s ease, font-size .5s ease;
top: 0;
}
input:focus+label>span,
input:valid+label>span {
top: -23px;
font-size: 11px;
padding-bottom: 15px;
}
<p class="head">Sign In</p>
<form>
<div class="content">
<div class="username">
<input type="text" name="name" class="user-input" id="user" required />
<!--input field-->
<label class="user-label" for="user"><span>Username</span></label>
</div>
<!-- <div class="password">
<input type="text" name="name" class="pass-input" id="pass" required />
<label class="pass-label" for="pass"><span>Password</span></label>
</div> -->
</div>
</form>
Related
I want that when a user comes and tries to type text in "input" the label goes up, and if they leave that area blank it comes back to the original position. If user typed something over there it will stay up there.
I tried this code with input box with required it is working fine, but when I try to do this with input and add some content in input the label coming back down it need to be stay up there.
div{
margin-top:40px;
}
.btn-add input[type="text"]{
width: 90%;
padding: 10px 20px 0 20px;
border: none;
border-bottom:1px solid #999;
font-size: 140%;
color: #000;
}
.btn-add input:focus ~ .floating-label{
top: -20px;
bottom: 10px;
left: 10px;
font-size: 20px;
opacity: 1;
color: rgb(100, 6, 6);
}
.floating-label {
position: absolute;
pointer-events: none;
left: 20px;
top:10px;
transition: 0.2s ease all;
color: #999999;
font-size: 120%;
}
.form-float{
position: relative;
}
<div class="form-float btn-add">
<input type="text" class="inputText" placeholder="" >
<label class="floating-label" >Button text</label>
</div>
I remove input:not(:focus):valid~.floating-label so it can work with not required field
Try this code since because of placeholder happening.
.form-group {
position: relative;
margin-bottom: 1.5rem;
}
input + .form-control-placeholder {
position: absolute;
transition: all 200ms;
top: -20px;
bottom: 10px;
font-size: 20px;
opacity: 1;
color: rgb(100, 6, 6);
}
input:placeholder-shown + .form-control-placeholder {
position: absolute;
pointer-events: none;
left: 20px;
top:10px;
transition: 0.2s ease all;
color: #999999;
font-size: 120%;
}
.form-control:focus + .form-control-placeholder {
position: absolute;
transition: all 200ms;
top: -20px;
bottom: 10px;
font-size: 20px;
opacity: 1;
color: rgb(100, 6, 6);
}
input[type="text"]{
width: 90%;
padding: 10px 20px 0 20px;
border: none;
border-bottom:1px solid #999;
font-size: 140%;
color: #000;
}
label{
position: absolute;
pointer-events: none;
left: 20px;
top:10px;
transition: 0.2s ease all;
color: #999999;
font-size: 120%;
}
<br>
<br>
<div class="form-group">
<input type="text" class="form-control" placeholder=" " >
<label class="form-control-placeholder">Button text</label>
</div>
Add Space to you placeholder by default and after that use input:not(:placeholder-shown) property to check if input is empty or not. Here working example of your code
div{
margin-top:40px;
}
.btn-add input[type="text"]{
width: 90%;
padding: 10px 20px 0 20px;
border: none;
border-bottom:1px solid #999;
font-size: 140%;
color: #000;
}
.btn-add input:focus ~ .floating-label{
top: -20px;
bottom: 10px;
left: 10px;
font-size: 20px;
opacity: 1;
color: rgb(100, 6, 6);
}
.btn-add input:not(:placeholder-shown) ~ .floating-label{
top: -20px;
bottom: 10px;
left: 10px;
font-size: 20px;
opacity: 1;
color: rgb(100, 6, 6);
}
.floating-label {
position: absolute;
pointer-events: none;
left: 20px;
top:10px;
transition: 0.2s ease all;
color: #999999;
font-size: 120%;
}
.form-float{
position: relative;
}
<div class="form-float btn-add">
<input type="text" class="inputText" placeholder=" " >
<label class="floating-label" >Button text</label>
</div>
Since :placeholder-shown only works with placeholder text shown (no empty string) you could use visibility.
div {
margin-top:40px;
}
.btn-add input[type="text"] {
width: 90%;
padding: 10px 20px 0 20px;
border: none;
border-bottom:1px solid #999;
font-size: 140%;
color: #000;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 20px;
top: -20px;
transition: 0.2s ease all;
color: #999999;
font-size: 120%;
}
.form-float input:placeholder-shown ~ label {
top: 0;
visibility: hidden;
}
.form-float {
position: relative;
}
<div class="form-float btn-add">
<input type="text" placeholder="Button Label" >
<label class="floating-label">Button Label</label>
</div>
These are two solutions. I think they need some adjustment because probably they are not correct.
Solution #1: Floating label on focus
.custom-form-input {
display: block;
width: 100%;
height:32px;
padding: 1rem .55rem .065rem .55rem;
font-weight: 400;
border: 1px solid #cad3d6;
transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
background-color: #fafafa;
font-size: 0.79em;
color:#000000;
border-radius: 2px;
font-family: Arial, Helvetica, sans-serif;
}
.custom-form-input:focus,
.custom-form-input:active {
color: #212529;
background-color: #fff;
border-color: #585d61;
outline: 0;
}
.custom-form-floating {
position:relative;
}
.custom-form-floating-label {
position:absolute;
color: #9aa0a9;
font-size: 0.85em;
height:100%;
width:100%;
top: 0px;
display:flex;
align-items: center;
padding: 0 .55rem 0 .55rem;
transition: 0.2s ease all;
-moz-transition: 0.2s ease all;
-webkit-transition: 0.2s ease all;
user-select: none;
pointer-events: none
}
.custom-form-input:focus ~ label,
.custom-form-input:valid ~ label {
font-size: 0.65rem;
height:55%;
}
.wrapper {
width:150px;
}
<div class="custom-form-floating">
<input id="test" class="custom-form-input" aria-label="usuario o correo electrónico" required=true aria-required="true"/>
<label for="test" class="custom-form-floating-label">Example 1</label>
</div>
<div class="wrapper">
<div class="custom-form-floating">
<input id="test" class="custom-form-input" aria-label="usuario o correo electrónico" required=true aria-required="true"/>
<label for="test" class="custom-form-floating-label">Example 2</label>
</div>
</div>
Solution #2: Floating label when type a letter
.custom-form-input {
display: block;
width: 100%;
height: 5px;
font-weight: 400;
border: 1px solid #cad3d6;
transition: border-color .15s ease-in-out;
background-color: #fafafa;
font-size: 1.2em;
color: #000000;
padding: 1rem .50rem 1rem .50rem;
border-radius: 2px;
font-family: Arial, Helvetica, sans-serif;
}
.custom-form-input:focus,
.custom-form-input:active {
color: #212529;
background-color: #fff;
border-color: #585d61;
outline: 0;
}
.custom-form-floating {
position: relative;
}
.custom-form-floating-label {
position: absolute;
color: #9aa0a9;
font-size: 0.85em;
height: 100%;
width: 100%;
top: 0px;
display: flex;
align-items: center;
padding: 0 .55rem 0 .55rem;
transition: 0.2s ease all;
-moz-transition: 0.2s ease all;
-webkit-transition: 0.2s ease all;
user-select: none;
pointer-events: none
}
.custom-form-input:valid {
padding: 1.50rem .50rem .50rem .50rem;
font-size: 0.79em;
}
.custom-form-input:valid~label {
font-size: 0.65rem;
height: 55%;
}
.wrapper {
width:250px;
}
<div class="wrapper">
<div class="custom-form-floating">
<input id="test" class="custom-form-input"
aria-label="usuario o correo electrónico" required=true aria-required="true"/>
<label for="test" class="custom-form-floating-label">Correo electrónico o
usuario</label>
</div>
</div>
I am designing an app in Unqork. The issue I have is how to shape the radio button to look like the regular Learn More button. I only intend to style the radio button instead of making it into a multiple choice.
The style of the regular button is
.abc-quote-option-cta {
bottom: 38px;
left: 0;
right: 0;
padding-top: 24px;
position: absolute; }
.abc-quote-option-cta:before {
background-color: #979797;
content: '';
display: block;
height: 1px;
left: 62px;
opacity: .36;
position: absolute;
right: 56px;
top: 0;
}
.abc-quote-option-cta .btn.btn-primary {
border-radius: 6px;
border: solid 2px #01a7e1;
background-color: #FFFFFF;
border-radius: 6px;
color: #01a7e1;
display: block;
font-size: 1.8rem;
line-height: 1.44;
margin: 0 auto;
padding: 10px;
text-align: center;
transition: background-color .25s ease, width .13s ease-in, color .18s ease-out ;
width: 188px;
}
.abc-quote-option-cta .btn.btn-primary:hover,
.abc-quote-option-cta .btn.btn-primary:focus {
background-color: #0099cc;
color: #FFFFFF;
width: 251px;
}
Your help is very much appreciated. Thanks!
I hope this snippet will help you.
form {
max-width: 250px;
position: relative;
margin: 50px auto 0;
font-size: 15px;
}
.radiobtn {
position: relative;
display: block;
}
.radiobtn label {
display: block;
background: rgba(0, 0, 0, 0.2);
color: #000;
border-radius: 5px;
padding: 10px 20px;
border: 2px solid grey;
margin-bottom: 5px;
cursor: pointer;
}
.radiobtn label:after, .radiobtn label:before {
content: "";
position: absolute;
right: 11px;
top: 11px;
width: 20px;
height: 20px;
border-radius: 3px;
background:grey;
}
.radiobtn label:before {
background: transparent;
transition: 0.1s width cubic-bezier(0.075, 0.82, 0.165, 1) 0s, 0.3s height cubic-bezier(0.075, 0.82, 0.165, 2) 0.1s;
z-index: 2;
overflow: hidden;
background-repeat: no-repeat;
background-size: 13px;
background-position: center;
width: 0;
height: 0;
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNS4zIDEzLjIiPiAgPHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE0LjcuOGwtLjQtLjRhMS43IDEuNyAwIDAgMC0yLjMuMUw1LjIgOC4yIDMgNi40YTEuNyAxLjcgMCAwIDAtMi4zLjFMLjQgN2ExLjcgMS43IDAgMCAwIC4xIDIuM2wzLjggMy41YTEuNyAxLjcgMCAwIDAgMi40LS4xTDE1IDMuMWExLjcgMS43IDAgMCAwLS4yLTIuM3oiIGRhdGEtbmFtZT0iUGZhZCA0Ii8+PC9zdmc+);
}
input[type="radio"] {
display: none;
position: absolute;
width: 100%;
appearance: none;
}
input[type="radio"]:checked + label {
background:grey;
animation-name: blink;
animation-duration: 1s;
border-color: $accentcolor;
}
input[type="radio"]:checked + label:after {
background: $accentcolor;
}
input[type="radio"]:checked + label:before {
width: 20px;
height: 20px;
}
<form>
<div class="radiobtn">
<input type="radio" id="huey"
name="drone" value="huey" checked />
<label for="huey">Learn More</label>
</div>
<div class="radiobtn">
<input type="radio" id="dewey"
name="drone" value="dewey" />
<label for="dewey">Learn More</label>
</div>
</form>
Custom radio button without check mark.
form {
max-width: 200px;
position: relative;
margin: 50px auto 0;
font-size: 15px;
}
.radiobtn {
position: relative;
display: block;
text-align:center;
}
.radiobtn label {
display: block;
background:none;
color:#01a7e1;
border-radius: 5px;
padding: 10px 20px;
border: 2px solid #01a7e1;
margin-bottom: 5px;
cursor: pointer;
font-family:Arial, Helvetica, sans-serif;
}
input[type="radio"] {
display: none;
position: absolute;
width: 100%;
appearance: none;
}
input[type="radio"]:checked + label {
background:#01a7e1;
color:#fff;
}
<form>
<div class="radiobtn">
<input type="radio" id="huey"
name="drone" value="huey" checked />
<label for="huey">Learn More</label>
</div>
<div class="radiobtn">
<input type="radio" id="dewey"
name="drone" value="dewey" />
<label for="dewey">Learn More</label>
</div>
</form>
I hope this will help you.
form {
max-width: 250px;
position: relative;
margin: 50px auto 0;
font-size: 15px;
}
.radiobtn {
position: relative;
display: block;
}
.radiobtn label {
display: block;
background: rgba(0, 0, 0, 0.2);
color: #000;
border-radius: 5px;
padding: 10px 20px;
border: 2px solid grey;
margin-bottom: 5px;
cursor: pointer;
}
.radiobtn label:after,
.radiobtn label:before {
content: "";
position: absolute;
right: 11px;
top: 11px;
width: 20px;
height: 20px;
border-radius: 3px;
background: grey;
}
.radiobtn label:before {
background: transparent;
transition: 0.1s width cubic-bezier(0.075, 0.82, 0.165, 1) 0s, 0.3s height cubic-bezier(0.075, 0.82, 0.165, 2) 0.1s;
z-index: 2;
overflow: hidden;
background-repeat: no-repeat;
background-size: 13px;
background-position: center;
width: 0;
height: 0;
background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNS4zIDEzLjIiPiAgPHBhdGggZmlsbD0iI2ZmZiIgZD0iTTE0LjcuOGwtLjQtLjRhMS43IDEuNyAwIDAgMC0yLjMuMUw1LjIgOC4yIDMgNi40YTEuNyAxLjcgMCAwIDAtMi4zLjFMLjQgN2ExLjcgMS43IDAgMCAwIC4xIDIuM2wzLjggMy41YTEuNyAxLjcgMCAwIDAgMi40LS4xTDE1IDMuMWExLjcgMS43IDAgMCAwLS4yLTIuM3oiIGRhdGEtbmFtZT0iUGZhZCA0Ii8+PC9zdmc+);
}
input[type="radio"] {
display: none;
position: absolute;
width: 100%;
appearance: none;
}
input[type="radio"]:checked+label {
background: grey;
animation-name: blink;
animation-duration: 1s;
border-color: $accentcolor;
}
input[type="radio"]:checked+label:after {
background: $accentcolor;
}
input[type="radio"]:checked+label:before {
width: 20px;
height: 20px;
}
<form>
<div class="radiobtn">
<input type="radio" id="huey" name="drone" value="huey" checked />
<label for="huey">Learn More</label>
</div>
<div class="radiobtn">
<input type="radio" id="dewey" name="drone" value="dewey" />
<label for="dewey">Learn More</label>
</div>
</form>
I am trying to follow a tutorial so that when an input is selected the label rises and the line changes color. The problem is it creates a second line that displays in the middle of the input.
It should display like the one on this site here
I tried comparing the code then typed it exactly and it still isn't working.
My code is
html,
body {
height: 100%;
}
body {
display: grid;
font-family: Avenir;
-webkit-text-size-adjust: 100%;
-webkit-font-smoothing: antialiased;
}
* {
box-sizing: border-box;
}
.inp {
position: relative;
margin: auto;
width: 100%;
max-width: 280px;
}
.inp .label {
position: absolute;
top: 16px;
left: 0;
font-size: 16px;
color: #9098a9;
font-weight: 500;
transform-origin: 0 0;
transition: all 0.2s ease;
}
.inp .border {
position: absolute;
bottom: 0;
left: 0;
height: 2px;
width: 100%;
background: #07f;
transform: scaleX(0);
transform-origin: 0 0;
transition: all 0.15s ease;
}
.inp input {
-webkit-appearance: none;
width: 100%;
border: 0;
font-family: inherit;
padding: 12px 0;
height: 48px;
font-size: 16px;
font-weight: 500;
border-bottom: 2px solid #c8ccd4;
background: none;
border-radius: 0;
color: #223254;
transition: all 0.15s ease;
}
.inp input:hover {
background: rgba(34,50,84,0.03);
}
.inp input:not(:placeholder-shown) + span {
color: #5a667f;
transform: translateY(-26px) scale(0.75);
}
.inp input:focus {
background: none;
outline: none;
}
.inp input:focus + span {
color: #07f;
transform: translateY(-26px) scale(0.75);
}
.inp input:focus + span + .border {
transform: scaleX(1);
}
<!DOCTYPE html>
<html>
<head>
. . .
</head>
<body bgcolor="#f4b942">
<div>
<label for="inp" class="inp">
<input type="text" id="inp" placeholder=" ">
<span class="label">Insert Values</span>
<span class="border"></span>
</label>
</div>
</body>
</html>
Your code is not exactly same as the example link you mentioned. You have added <label> inside a <div>. <div> has a default display: block which is caused this issue. So there are two options 1) Remove <div> 2) Add change display: block to some other values like display: flex. It will work.
Below is code:
html,
body {
height: 100%;
}
body {
display: grid;
font-family: Avenir;
-webkit-text-size-adjust: 100%;
-webkit-font-smoothing: antialiased;
}
* {
box-sizing: border-box;
}
.div {
display: flex;
}
.inp {
position: relative;
margin: auto;
width: 100%;
max-width: 280px;
}
.inp .label {
position: absolute;
top: 16px;
left: 0;
font-size: 16px;
color: #9098a9;
font-weight: 500;
transform-origin: 0 0;
transition: all 0.2s ease;
}
.inp .border {
position: absolute;
bottom: 0;
left: 0;
height: 2px;
width: 100%;
background: #07f;
transform: scaleX(0);
transform-origin: 0 0;
transition: all 0.15s ease;
}
.inp input {
-webkit-appearance: none;
width: 100%;
border: 0;
font-family: inherit;
padding: 12px 0;
height: 48px;
font-size: 16px;
font-weight: 500;
border-bottom: 2px solid #c8ccd4;
background: none;
border-radius: 0;
color: #223254;
transition: all 0.15s ease;
}
.inp input:hover {
background: rgba(34, 50, 84, 0.03);
}
.inp input:not(:placeholder-shown)+span {
color: #5a667f;
transform: translateY(-26px) scale(0.75);
}
.inp input:focus {
background: none;
outline: none;
}
.inp input:focus+span {
color: #07f;
transform: translateY(-26px) scale(0.75);
}
<!DOCTYPE html>
<html>
<head>
. . .
</head>
<body bgcolor="#f4b942">
<div class="div">
<label for="inp" class="inp">
<input type="text" id="inp" placeholder=" ">
<span class="label">Insert Values</span>
<span class="border"></span>
</label>
</div>
</body>
</html>
I am trying to make a switch button by using HTML elements. But I can't do animation for this. Here I have tried to use transition CSS3 property. The transition will work for some elements only and its doesn't work as expected for switch-group:before element. Is there any way to improve more animation to get an attractive one?. I have tried many links but this doesn't help with my code. I have attached code below,
input[type=checkbox] {
display: none;
}
.switch-wrapper {
position: relative;
width: 70px;
border: 1px solid;
cursor: pointer;
height: 22px;
overflow: hidden;
}
.switch-on,
.switch-off {
display: block;
width: 50%;
float: left;
height: 100%;
transition: 0.5s;
}
.switch-on {
background-color: red;
margin-left: -100%;
text-indent: -18px;
line-height: 21px;
text-align: center;
}
.switch-off {
text-indent: 18px;
line-height: 21px;
text-align: center;
background-color: aliceblue;
}
.switch-group:before {
display: block;
content: "";
position: absolute;
height: 18px;
width: 18px;
margin: 2px;
background-color: #1b191e;
top: 0px;
}
.switch-group {
display: block;
position: relative;
height: 23px;
width: 200%;
user-select: none;
}
input[type=checkbox]:checked+.switch-group .switch-on {
margin-left: 0;
}
input[type=checkbox]:checked+.switch-group:before {
right: 50%;
}
<div class="switch-wrapper">
<input type="checkbox" id="checked" />
<label class="switch-group" for="checked">
<span class="switch-on">ON</span>
<span class="switch-off">OFF</span>
</label>
</div>
The transition will not work in your :before pseudo element because you are changing the :before right value from auto(by default) to 0...transition does not works on auto values...
So try to use left:0 at start and then change it value on click(when input checked) using calc() and also use transtion:0.5s in :before to make it animate
input[type=checkbox] {
display: none;
}
.switch-wrapper {
position: relative;
width: 70px;
border: 1px solid;
cursor: pointer;
height: 22px;
overflow: hidden;
}
.switch-on,
.switch-off {
display: block;
width: 50%;
float: left;
height: 100%;
transition: 0.5s;
}
.switch-on {
background-color: red;
margin-left: -50%;
text-indent: -18px;
line-height: 21px;
text-align: center;
}
.switch-off {
text-indent: 18px;
line-height: 21px;
text-align: center;
background-color: aliceblue;
}
.switch-group:before {
display: block;
content: "";
position: absolute;
height: 18px;
width: 18px;
margin: 2px;
background-color: #1b191e;
top: 0px;
left: 0;
transition: 0.5s;
}
.switch-group {
display: block;
position: relative;
height: 23px;
width: 200%;
user-select: none;
}
input[type=checkbox]:checked+.switch-group .switch-on {
margin-left: 0;
}
input[type=checkbox]:checked+.switch-group:before {
left: calc(50% - 22px);
}
<div class="switch-wrapper">
<input type="checkbox" id="checked" />
<label class="switch-group" for="checked">
<span class="switch-on">ON</span>
<span class="switch-off">OFF</span>
</label>
</div>
Or if you want your code to work in more intuitive way, try to use opacity instead of margin.
I have changed some of your css a little bit
input[type=checkbox] {
display: none;
}
.switch-wrapper {
position: relative;
width: 70px;
border: 1px solid;
cursor: pointer;
height: 22px;
overflow: hidden;
}
.switch-on,
.switch-off {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
transition: 0.5s;
padding: 2px 6px;
}
.switch-on {
background-color: red;
line-height: 21px;
opacity: 0;
}
.switch-off {
line-height: 21px;
background-color: aliceblue;
opacity: 1;
text-align: right;
}
.switch-group:before {
display: block;
content: "";
position: absolute;
height: 18px;
width: 18px;
margin: 2px;
background-color: #1b191e;
top: 0px;
left: 0;
transition: 0.5s;
z-index: 99;
}
.switch-group {
display: block;
position: relative;
height: 23px;
user-select: none;
}
input[type=checkbox]:checked+.switch-group .switch-on {
opacity: 1;
}
input[type=checkbox]:checked+.switch-group .switch-off {
opacity: 0;
}
input[type=checkbox]:checked+.switch-group:before {
left: calc(100% - 22px);
}
<div class="switch-wrapper">
<input type="checkbox" id="checked" />
<label class="switch-group" for="checked">
<span class="switch-on">ON</span>
<span class="switch-off">OFF</span>
</label>
</div>
Try this toggler
.onoffswitch {
position: relative; width: 48px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
height: 24px; padding: 0; line-height: 24px;
border: 2px solid #F1F1F5; border-radius: 24px;
background-color: #F1F1F5;
transition: background-color 0.3s ease-in;
}
.onoffswitch-label:before {
content: "";
display: block; width: 24px; margin: 0px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 22px;
border: 2px solid #F1F1F5; border-radius: 24px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label {
background-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label, .onoffswitch-checkbox:checked + .onoffswitch-label:before {
border-color: #2DC76D;
}
.onoffswitch-checkbox:checked + .onoffswitch-label:before {
right: 0px;
}
.onoffswitch-checkbox:checked + .onoffswitch-label span.switch-off {
opacity: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label span.switch-on{
opacity: 1;
}
span.switch-off {
opacity: 1;
float: right;
font-size: 12px;
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
}
span.switch-on {
position: absolute;
font-size: 12px;
top: 50%;
transform: translateY(-50%);
opacity: 0;
}
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch">
<label class="onoffswitch-label" for="myonoffswitch">
<span class="switch-on">ON</span>
<span class="switch-off">OFF</span></label>
</div>
You Can Try This.. Or visit This link For Details
.onoffswitch {
position: relative; width: 90px;
-webkit-user-select:none; -moz-user-select:none; -ms-user-select: none;
}
.onoffswitch-checkbox {
display: none;
}
.onoffswitch-label {
display: block; overflow: hidden; cursor: pointer;
border: 2px solid #999999; border-radius: 20px;
}
.onoffswitch-inner {
display: block; width: 200%; margin-left: -100%;
transition: margin 0.3s ease-in 0s;
}
.onoffswitch-inner:before, .onoffswitch-inner:after {
display: block; float: left; width: 50%; height: 30px; padding: 0; line-height: 30px;
font-size: 14px; color: white; font-family: Trebuchet, Arial, sans-serif; font-weight: bold;
box-sizing: border-box;
}
.onoffswitch-inner:before {
content: "ON";
padding-left: 10px;
background-color: #34A7C1; color: #FFFFFF;
}
.onoffswitch-inner:after {
content: "OFF";
padding-right: 10px;
background-color: #EEEEEE; color: #999999;
text-align: right;
}
.onoffswitch-switch {
display: block; width: 18px; margin: 6px;
background: #FFFFFF;
position: absolute; top: 0; bottom: 0;
right: 56px;
border: 2px solid #999999; border-radius: 20px;
transition: all 0.3s ease-in 0s;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-inner {
margin-left: 0;
}
.onoffswitch-checkbox:checked + .onoffswitch-label .onoffswitch-switch {
right: 0px;
}
<div class="onoffswitch">
<input type="checkbox" name="onoffswitch" class="onoffswitch-checkbox" id="myonoffswitch" checked>
<label class="onoffswitch-label" for="myonoffswitch">
<span class="onoffswitch-inner"></span>
<span class="onoffswitch-switch"></span>
</label>
</div>
i'm using the css3 search box code below and i want to know how to change the expanding direction of the search box from left to right
wai
#import url(http://fonts.googleapis.com/css?family=Lato:100,300,400,700);
#import url(https://raw.github.com/FortAwesome/Font-Awesome/master/docs/assets/css/font-awesome.min.css);
body {
background: #DDD;
font-size: 15px;
}
#wrap {
margin: 50px 100px;
display: inline-block;
position: relative;
height: 60px;
float: right;
padding: 0;
position: relative;
}
input[type="text"] {
height: 60px;
font-size: 55px;
display: inline-block;
font-family: "Lato";
font-weight: 100;
border: none;
outline: none;
color: #555;
padding: 3px;
padding-right: 60px;
width: 0px;
position: absolute;
top: 0;
right: 0;
background: none;
z-index: 3;
transition: width .4s cubic-bezier(0.000, 0.795, 0.000, 1.000);
cursor: pointer;
}
input[type="text"]:focus:hover {
border-bottom: 1px solid #BBB;
}
input[type="text"]:focus {
width: 700px;
z-index: 1;
border-bottom: 1px solid #BBB;
cursor: text;
}
input[type="submit"] {
height: 67px;
width: 63px;
display: inline-block;
color:red;
float: right;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRFU1NT9fX1lJSUXl5e1dXVfn5+c3Nz6urqv7+/tLS0iYmJqampn5+fysrK39/faWlp////Vi4ZywAAABF0Uk5T/////////////////////wAlrZliAAABLklEQVR42rSWWRbDIAhFHeOUtN3/ags1zaA4cHrKZ8JFRHwoXkwTvwGP1Qo0bYObAPwiLmbNAHBWFBZlD9j0JxflDViIObNHG/Do8PRHTJk0TezAhv7qloK0JJEBh+F8+U/hopIELOWfiZUCDOZD1RADOQKA75oq4cvVkcT+OdHnqqpQCITWAjnWVgGQUWz12lJuGwGoaWgBKzRVBcCypgUkOAoWgBX/L0CmxN40u6xwcIJ1cOzWYDffp3axsQOyvdkXiH9FKRFwPRHYZUaXMgPLeiW7QhbDRciyLXJaKheCuLbiVoqx1DVRyH26yb0hsuoOFEPsoz+BVE0MRlZNjGZcRQyHYkmMp2hBTIzdkzCTc/pLqOnBrk7/yZdAOq/q5NPBH1f7x7fGP4C3AAMAQrhzX9zhcGsAAAAASUVORK5CYII=) center center no-repeat;
text-indent: -10000px;
border: none;
position: absolute;
top: 0;
right: 0;
z-index: 2;
cursor: pointer;
opacity: 0.4;
cursor: pointer;
transition: opacity .4s ease;
}
input[type="submit"]:hover {
opacity: 0.8;
}
<div id="wrap">
<form action="" autocomplete="on">
<input id="search" name="search" type="text" placeholder="What're we looking for ?"><input id="search_submit" value="Rechercher" type="submit">
</form>
</div>
Everything seems to work fine except i need it to slide to the right direction
body {
background: #DDD;
font-size: 15px;
}
#wrap {
margin: 50px 100px;
display: inline-block;
position: relative;
height: 60px;
float: left;
padding: 0;
position: relative;
}
input[type="text"] {
height: 60px;
font-size: 55px;
display: inline-block;
font-family: "Lato";
font-weight: 100;
border: none;
outline: none;
color: #555;
padding: 3px;
padding-left: 60px;
width: 0px;
position: absolute;
top: 0;
left: 0;
background: none;
z-index: 3;
transition: width .4s cubic-bezier(0.000, 0.795, 0.000, 1.000);
cursor: pointer;
}
input[type="text"]:focus:hover {
border-bottom: 1px solid #BBB;
}
input[type="text"]:focus {
width: 700px;
z-index: 1;
border-bottom: 1px solid #BBB;
cursor: text;
}
input[type="submit"] {
height: 67px;
width: 63px;
display: inline-block;
color:red;
float: left;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRFU1NT9fX1lJSUXl5e1dXVfn5+c3Nz6urqv7+/tLS0iYmJqampn5+fysrK39/faWlp////Vi4ZywAAABF0Uk5T/////////////////////wAlrZliAAABLklEQVR42rSWWRbDIAhFHeOUtN3/ags1zaA4cHrKZ8JFRHwoXkwTvwGP1Qo0bYObAPwiLmbNAHBWFBZlD9j0JxflDViIObNHG/Do8PRHTJk0TezAhv7qloK0JJEBh+F8+U/hopIELOWfiZUCDOZD1RADOQKA75oq4cvVkcT+OdHnqqpQCITWAjnWVgGQUWz12lJuGwGoaWgBKzRVBcCypgUkOAoWgBX/L0CmxN40u6xwcIJ1cOzWYDffp3axsQOyvdkXiH9FKRFwPRHYZUaXMgPLeiW7QhbDRciyLXJaKheCuLbiVoqx1DVRyH26yb0hsuoOFEPsoz+BVE0MRlZNjGZcRQyHYkmMp2hBTIzdkzCTc/pLqOnBrk7/yZdAOq/q5NPBH1f7x7fGP4C3AAMAQrhzX9zhcGsAAAAASUVORK5CYII=) center center no-repeat;
text-indent: -10000px;
border: none;
position: absolute;
top: 0;
left: 0;
z-index: 2;
cursor: pointer;
opacity: 0.4;
cursor: pointer;
transition: opacity .4s ease;
}
input[type="submit"]:hover {
opacity: 0.8;
}
<div id="wrap">
<form action="" autocomplete="on">
<input id="search" name="search" type="text" placeholder="What're we looking for ?"><input id="search_submit" value="Rechercher" type="submit">
</form>
</div>
like this
body {
background: #DDD;
font-size: 15px;
}
#wrap {
margin: 50px 100px;
display: inline-block;
position: relative;
height: 60px;
float: right;
padding: 0;
position: relative;
}
input[type="text"] {
height: 60px;
font-size: 30px;
display: block;
font-family: "Lato";
font-weight: 200;
outline: none;
border:none;
color: black;
padding-right: 400px;
width: 100%;
position: absolute;
float: left;
top: 0;
right: 0;
background: none;
z-index: 3;
transition: all .4s ;
cursor: pointer;
opacity:0;
}
input[type="text"]:focus:hover {
border-bottom: 1px solid #BBB;
}
input[type="text"]:focus {
padding-right: 0px;
opacity:1;
border:normal;
z-index: 1;
border-bottom: 1px solid #BBB;
cursor: text;
}
input[type="submit"] {
height: 67px;
width: 63px;
display: inline-block;
color:red;
float: right;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADNQTFRFU1NT9fX1lJSUXl5e1dXVfn5+c3Nz6urqv7+/tLS0iYmJqampn5+fysrK39/faWlp////Vi4ZywAAABF0Uk5T/////////////////////wAlrZliAAABLklEQVR42rSWWRbDIAhFHeOUtN3/ags1zaA4cHrKZ8JFRHwoXkwTvwGP1Qo0bYObAPwiLmbNAHBWFBZlD9j0JxflDViIObNHG/Do8PRHTJk0TezAhv7qloK0JJEBh+F8+U/hopIELOWfiZUCDOZD1RADOQKA75oq4cvVkcT+OdHnqqpQCITWAjnWVgGQUWz12lJuGwGoaWgBKzRVBcCypgUkOAoWgBX/L0CmxN40u6xwcIJ1cOzWYDffp3axsQOyvdkXiH9FKRFwPRHYZUaXMgPLeiW7QhbDRciyLXJaKheCuLbiVoqx1DVRyH26yb0hsuoOFEPsoz+BVE0MRlZNjGZcRQyHYkmMp2hBTIzdkzCTc/pLqOnBrk7/yZdAOq/q5NPBH1f7x7fGP4C3AAMAQrhzX9zhcGsAAAAASUVORK5CYII=) center center no-repeat;
text-indent: -10000px;
border: none;
position: absolute;
top: 0;
right: 0;
z-index: 2;
cursor: pointer;
opacity: 0.4;
cursor: pointer;
transition: opacity .4s ease;
}
input[type="submit"]:hover {
opacity: 0.8;
}
form {
width: 460px;
overflow:hidden;
}
<div id="wrap">
<form action="" autocomplete="on" onclick='return false'>
<input id="search" name="search" type="text" placeholder="What're we looking for ?" ><input id="search_submit" value="Rechercher" type="submit">
</form>
</div>