I want to display the label of an input inside its input, so that when I click the input, the label will animate and go above the input and change the styles of the input's border.
Like so:
* {
margin: 0;
padding: 0;
}
form {
width: 100%;
max-width: 500px;
margin: 0 auto;
outline: 1px solid lightgrey;
padding: 10px;
}
label, input[type='text'], input[type='password'] {
font-size: 12pt;
padding: 8px;
}
label {
color: grey;
}
input {
border: none;
outline: none;
border-bottom: 1px solid grey;
}
<form>
<label for="username">Username</label>
<input id="username" name="username" type="text"/>
<br/>
<label for="password">Password</label>
<input id="password" name="password" type="password"/>
<br/>
<input type="submit" value"login"/>
</form>
How can I achieve this with CSS?
This looks a lot like the Google new material design inputs.
I created custom inputs for you that look like what you are looking for.
.input-group {
position: relative;
margin: 40px 0 20px;
}
input {
font-size: 18px;
padding: 10px 10px 10px 5px;
display: block;
width: 300px;
border: none;
border-bottom: 1px solid #757575;
}
input:focus {
outline: none;
}
label {
color: #999;
font-size: 18px;
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;
}
input:focus ~ label,
input:valid ~ label {
top: -20px;
font-size: 14px;
color: #4285f4;
}
.bar {
position: relative;
display:block;
width:315px;
}
.bar:before,
.bar:after {
content: '';
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: #4285f4;
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%;
}
input:focus ~ .bar:before,
input:focus ~ .bar:after {
width: 50%;
}
.highlight {
position: absolute;
height: 60%;
width: 100px;
top: 25%;
left: 0;
pointer-events: none;
opacity: 0.5;
}
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: #4285f4; }
to { width: 0; background: transparent; }
}
#-moz-keyframes inputHighlighter {
from { background: #4285f4; }
to { width: 0; background: transparent; }
}
#keyframes inputHighlighter {
from { background: #4285f4; }
to { width: 0; background: transparent; }
}
<div class="input-group">
<input type="text" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Username</label>
</div>
<div class="input-group">
<input type="password" required>
<span class="highlight"></span>
<span class="bar"></span>
<label>Password</label>
</div>
Edited #23 Dec 2017
This will also help you. Considering your image i am asking you want to change text after click?
input {
margin: 40px 25px;
width: 200px;
display: block;
border: none;
padding: 10px 0;
border-bottom: solid 1px #1abc9c;
-webkit-transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
transition: all 0.3s cubic-bezier(0.64, 0.09, 0.08, 1);
background: -webkit-linear-gradient(top, rgba(255, 255, 255, 0) 96%, #1abc9c 4%);
background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 96%, #1abc9c 4%);
background-position: -200px 0;
background-size: 200px 100%;
background-repeat: no-repeat;
color: #0e6252;
}
input:focus, input:valid {
box-shadow: none;
outline: none;
background-position: 0 0;
}
input::-webkit-input-placeholder {
-webkit-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
}
input:focus::-webkit-input-placeholder, input:valid::-webkit-input-placeholder {
color: #1abc9c;
font-size: 11px;
-webkit-transform: translateY(-8px);
transform: translateY(-8px);
visibility: visible !important;
}
<input placeholder="Username" type="text" required>
<input placeholder="Password" type="password" required>
Check this Tutorial Link
Demo Link
This is inspired by latest Gmail Login style
HTML
<div class="form-wrapper-outer">
<div class="form-logo">
<img src="https://www.freakyjolly.com/wp-content/uploads/2017/08/cropped-fjlogo2.png" alt="logo">
</div>
<div class="form-greeting">
<span>It's nice to meet you.</span>
</div>
<div class="field-wrapper">
<input type="email" name="email" id="">
<div class="field-placeholder"><span>Enter your email</span></div>
</div>
<div class="field-wrapper">
<input type="password" name="password" id="">
<div class="field-placeholder"><span>Enter your password</span></div>
</div>
<div class="form-button">
<button type="button" class="btn btn-primary">Login</button>
</div>
</div>
CSS Style
.field-wrapper{
position: relative;
margin-bottom: 15px;
}
.field-wrapper input{
border: 1px solid #DADCE0;
padding: 15px;
border-radius: 4px;
width: 100%;
}
.field-wrapper input:focus{
border:1px solid #1A73E8;
}
.field-wrapper .field-placeholder{
font-size: 16px;
position: absolute;
/* background: #fff; */
bottom: 17px;
-webkit-box-sizing: border-box;
box-sizing: border-box;
color: #80868b;
left: 8px;
padding: 0 8px;
-webkit-transition: transform 150ms cubic-bezier(0.4,0,0.2,1),opacity 150ms cubic-bezier(0.4,0,0.2,1);
transition: transform 150ms cubic-bezier(0.4,0,0.2,1),opacity 150ms cubic-bezier(0.4,0,0.2,1);
z-index: 1;
text-align: left;
width: 100%;
}
.field-wrapper .field-placeholder span{
background: #ffffff;
padding: 0px 8px;
}
.field-wrapper input:not([disabled]):focus~.field-placeholder
{
color:#1A73E8;
}
.field-wrapper input:not([disabled]):focus~.field-placeholder,
.field-wrapper.hasValue input:not([disabled])~.field-placeholder
{
-webkit-transform: scale(.75) translateY(-39px) translateX(-60px);
transform: scale(.75) translateY(-39px) translateX(-60px);
}
jQuery Event Listener
$(".field-wrapper .field-placeholder").on("click", function () {
$(this).closest(".field-wrapper").find("input").focus();
});
$(".field-wrapper input").on("keyup", function () {
var value = $.trim($(this).val());
if (value) {
$(this).closest(".field-wrapper").addClass("hasValue");
} else {
$(this).closest(".field-wrapper").removeClass("hasValue");
}
});
I Hope this will also help you.
The input animation happens when we add required attribute in it, this can be done without adding required attribute also.
HTML
<div class="floating-label">
<input class="floating-input" type="text" placeholder=" ">
<label>Text</label>
</div>
<div class="floating-label">
<input class="floating-input" type="text" onclick="(this.type='time')" placeholder=" ">
<label>Time</label>
</div>
<div class="floating-label">
<input class="floating-input" type="text" onclick="(this.type='date')" placeholder=" ">
<label>Date</label>
</div>
<div class="floating-label">
<input class="floating-input" type="password" placeholder=" ">
<label>Password</label>
</div>
<div class="floating-label">
<select class="floating-select" onclick="this.setAttribute('value', this.value);" value="">
<option value=""></option>
<option value="1">Alabama</option>
<option value="2">Boston</option>
<option value="3">Ohaio</option>
<option value="4">New York</option>
<option value="5">Washington</option>
</select>
<label>Select</label>
</div>
<div class="floating-label">
<textarea class="floating-input floating-textarea" placeholder=" "></textarea>
<label>Textarea</label>
</div>
CSS
.floating-label {
position:relative;
margin-bottom:20px;
}
.floating-input , .floating-select {
font-size:14px;
padding:4px 4px;
display:block;
width:180px;
height:30px;
background-color: transparent;
border:none;
border-bottom:1px solid #757575;
}
.floating-input:focus , .floating-select:focus {
outline:none;
border-bottom:2px solid #5264AE;
}
label {
color:#999;
font-size:14px;
font-weight:normal;
position:absolute;
pointer-events:none;
left:5px;
top:5px;
transition:0.2s ease all;
-moz-transition:0.2s ease all;
-webkit-transition:0.2s ease all;
}
.floating-input:focus ~ label, .floating-input:not(:placeholder-shown) ~ label {
top:-18px;
font-size:14px;
color:#5264AE;
}
.floating-select:focus ~ label , .floating-select:not([value=""]):valid ~ label {
top:-18px;
font-size:14px;
color:#5264AE;
}
.floating-input:focus ~ .bar:before, .floating-input:focus ~ .bar:after, .floating-select:focus ~ .bar:before, .floating-select:focus ~ .bar:after {
width:50%;
}
*, *:before, *:after {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.floating-textarea {
min-height: 30px;
max-height: 260px;
overflow:hidden;
overflow-x: hidden;
}
DEMO
Floating Label's - Pure CSS - without Required*
.box {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 200px;
background: #fff;
padding: 40px;
border: 1px solid red;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
.box input {
padding: 10px 0;
margin-bottom: 30px;
}
.box input {
width: 100%;
box-sizing: border-box;
box-shadow: none;
outline: none;
border: none;
border-bottom: 2px solid #999;
}
.box form div {
position: relative;
}
.box form div label {
position: absolute;
top: 10px;
left: 0;
color: #999;
transition: 0.5s;
pointer-events: none;
}
.box input:focus~label,
.box input:valid~label {
top: -12px;
left: 0;
color: red;
}
.box input:focus,
.box input:valid {
border-bottom: 2px solid red;
}
<div class="box">
<form>
<div>
<input type="text" name="" required="">
<label>First Name</label>
</div>
<div>
<input type="text" name="" required="">
<label>Last Name</label>
</div>
</form>
</div>
Like #daniel-j-abraham i use the input:not(:placeholder-shown) ~ label method. You just need to set a placeholder=" " (with a space) to your inputs (see this pen for live example)
it works just like the required method but it's way more convenient since it works also with non required fields.
i don't understand why this method isn't more used / upvoted ^^
CODE :
HTML :
<form class="contactForm">
<div>
<input id="contactName" value="" name="name" type="text" placeholder=" ">
<label for="contactName">name</label>
</div>
<div>
<input id="contactCompany" value="" name="company" type="text" placeholder=" ">
<label for="contactCompany">company</label>
</div>
<div>
<input id="contactPosition" value="" name="position" type="text" placeholder=" ">
<label for="contactPosition">position</label>
</div>
<div>
<button type="submit" class="submit">Send</button>
</form>
CSS:
/*basic styling */
.contactForm {
text-align: center;
margin: auto;
width: 300px;
padding-top: 15px
}
.contactForm > div {
position: relative;
width: 100%;
}
.contactForm > div input {
width: 100%;
height: 42px;
margin: 10px;
border: none;
border-bottom: 2px solid #eee;
border-left: 2px solid #eee;
padding: 0 10px;
transition: all .3s ease;
outline: none !important;
}
.contactForm > div label {
position: absolute;
top: 0;
left: 0;
margin: 20px;
transition: all .3s ease;
}
.contactForm > div input:focus {
border-color: #ff6291;
}
.contactForm > div input:not(:placeholder-shown) {
border-color: #26e9b9;
}
/* END of basic styling*/
/*************************************************/
/* NOW that's the part that interests us */
/*************************************************/
/* label goes up when input is focused OR filled */
.contactForm > div input:focus ~ label,
.contactForm > div input:not(:placeholder-shown) ~ label {
font-size: 12px;
transform: translateY(-30px);
}
/* label color on focused state */
.contactForm > div input:focus ~ label {
color: #ff6291;
}
/* label color on filled state */
.contactForm > div input:not(:placeholder-shown) ~ label {
color: #26e9b9;
}
/* button styling */
.submit {
color: #fff!important;
background-image: linear-gradient(to right,#ff017d 0,#ff7f78 40%,#fff 50%,#26e9b9 60%,#44c0ff 100%)!important;
background-size: 300% 200%!important;
background-position: -1px 0;
transition: background-position .3s;
border: none!important;
border-radius: 50px;
padding: 10px 42px;
text-transform: uppercase;
}
.submit:hover {
background-position: 95% 0 !important;
cursor: pointer;
}
Related
I had this piece of CSS implemented to have a transparent autofill background. But something has recently changed that it stopped working?
#-webkit-keyframes autofill {
to {
color: white;
background: transparent;
}
}
input:-webkit-autofill {
-webkit-animation-name: autofill;
-webkit-animation-fill-mode: both;
}
Is there a fix to this?
form {
background-color: red;
}
div {
margin: 15px 0;
position: relative;
width: 360px;
color: red;
background-color: red;
}
textarea,
select,
input {
height: 30px;
line-height: 30px;
border-radius: 5px;
border: 1px solid #000;
width: 100%;
box-sizing: border-box;
padding: 0 10px;
color: red;
background-color: red;
}
textarea {
height: 200px;
color: red;
background-color: red;
}
textarea+label {
width: calc(100% - 2px) !important;
top: 1px;
box-sizing: border-box;
border-radius: 5px 5px 0 0;
text-align: center;
color: red;
}
textarea:invalid,
select:invalid,
input:invalid {
box-shadow: none;
color: red;
}
textarea:invalid+label,
select:invalid+label,
input:invalid+label {
padding: 0 10px;
max-width: 360px;
color: red;
}
textarea:focus+label,
select:focus+label,
input:focus+label,
label {
position: absolute;
background: #a4a290;
max-width: 0;
padding: 0;
overflow: hidden;
left: 1px;
top: 1px;
height: 28px;
font: 14px/28px sans-serif;
-webkit-transition: all 0.25s;
-o-transition: all 0.25s;
transition: all 0.25s;
color: red;
border-radius: 5px 0 0 5px;
}
textarea:focus+label {
height: 0;
color: red;
#-webkit-keyframes autofill {
to {
color: white;
background: transparent;
}
}
input:-webkit-autofill {
-webkit-animation-name: autofill;
-webkit-animation-fill-mode: both;
}
<form>
<div>
<input type="text" id="firstname" required/>
<label for="firstname">First Name</label>
</div>
<div>
<input type="text" id="secondname" required/>
<label for="secondname">Second Name</label>
</div>
<div>
<select id="type" required>
<option value=""></option>
<option value="1">Type 1</option>
<option value="2">Type 2</option>
<option value="3">Type 3</option>
<option value="4">Type 4</option>
</select>
<label for="type">Select type...</label>
</div>
<div>
<textarea id="comment" required/></textarea>
<label for="comment">Comment</label>
</div>
</form>
Just this would do the job perfectly :
input:-webkit-autofill {
-webkit-text-fill-color: transparent;
transition: background-color 5000s ease-in-out 0s;
}
form {
background-color: red;
}
div {
margin: 15px 0;
position: relative;
width: 360px;
color: red;
background-color: red;
}
textarea,
select,
input {
height: 30px;
line-height: 30px;
border-radius: 5px;
border: 1px solid #000;
width: 100%;
box-sizing: border-box;
padding: 0 10px;
color: red;
background-color: red;
}
textarea {
height: 200px;
color: red;
background-color: red;
}
textarea+label {
width: calc(100% - 2px) !important;
top: 1px;
box-sizing: border-box;
border-radius: 5px 5px 0 0;
text-align: center;
color: red;
}
textarea:invalid,
select:invalid,
input:invalid {
box-shadow: none;
color: red;
}
textarea:invalid+label,
select:invalid+label,
input:invalid+label {
padding: 0 10px;
max-width: 360px;
color: red;
}
textarea:focus+label,
select:focus+label,
input:focus+label,
label {
position: absolute;
background: #a4a290;
max-width: 0;
padding: 0;
overflow: hidden;
left: 1px;
top: 1px;
height: 28px;
font: 14px/28px sans-serif;
-webkit-transition: all 0.25s;
-o-transition: all 0.25s;
transition: all 0.25s;
color: red;
border-radius: 5px 0 0 5px;
}
textarea:focus+label {
height: 0;
color: red;
}
input:-webkit-autofill {
-webkit-text-fill-color: black;
transition: background-color 5000s ease-in-out 0s;
}
<form>
<div>
<input type="text" id="firstname" required />
<label for="firstname">First Name</label>
</div>
<div>
<input type="email" id="email" required />
<label for="email">Email</label>
</div>
<div>
<input type="text" id="secondname" required />
<label for="secondname">Second Name</label>
</div>
<div>
<select id="type" required>
<option value=""></option>
<option value="1">Type 1</option>
<option value="2">Type 2</option>
<option value="3">Type 3</option>
<option value="4">Type 4</option>
</select>
<label for="type">Select type...</label>
</div>
<div>
<textarea id="comment" required /></textarea>
<label for="comment">Comment</label>
</div>
</form>
Source
https://jsbin.com/zofuqunavo/
#keyframes autofill {
to {
color: white;
background: green;
}
}
input:focus {
animation-name: autofill;
animation-fill-mode: both;
}
Using input:focus selector instead of input:autofill seem fix your issue.
Autofill is a bit unstable feature, the behaviour is changed multiple times and each browser has own implementation.
I want to have the textfield just like gmail has right now. I mean when we focus on the text field, the label or placeholder goes to the top exactly at the top border line of its text field with no border line on the background of the label only. I tried but could not make it happen and i found the code in internet which did not work either. Here is what the code is
.FieldWrapper input[type="text"] {
box-sizing: border-box;
width: 100%;
height: calc(3em + 2px);
margin: 0 0 1em;
padding: 1em;
border: 1px solid #ccc;
background: #fff;
resize: none;
outline: none;
}
.FieldWrapper input[type="text"]:focus {
border-color: #00bafa;
}
.FieldWrapper input[type="text"]:focus+label[placeholder]:before {
color: #00bafa;
}
.FieldWrapper input[type="text"]:focus+label[placeholder]:before,
.FieldWrapper input[type="text"]:valid+label[placeholder]:before {
transition-duration: 0.2s;
-webkit-transform: translate(0, -1.5em) scale(0.9, 0.9);
transform: translate(0, -1.5em) scale(0.9, 0.9);
}
.FieldWrapper input[type="text"]:invalid+label[placeholder][alt]:before {
content: attr(alt);
}
.FieldWrapper input[type="text"]+label[placeholder] {
display: block;
pointer-events: none;
line-height: 1.25em;
margin-top: calc(-1em - 2px);
margin-bottom: calc((3em - 1em) + 2px);
}
.FieldWrapper input[type="text"]+label[placeholder]:before {
content: attr(placeholder);
display: inline-block;
margin: 0 calc(1em + 2px);
padding: 0 2px;
color: #898989;
white-space: nowrap;
transition: 0.3s ease-in-out;
background-image: linear-gradient(to bottom, #fff, #fff);
background-size: 100% 5px;
background-repeat: no-repeat;
background-position: center;
}
<div class="FieldWrapper">
<input type='text' name="name" />
<label alt="field name" placeholder="field name" />
</div>
This is what exactly i was expecting
Try this:
.input-container {
position: relative;
font-family: Arial;
}
.input-container input {
height: 32px;
line-height: 24px;
border-radius: 8px;
border: 1px solid #dcdcdc;
min-width: 300px;
padding: 4px 8px;
transition: all .2s ease;
}
.input-container label {
position: absolute;
top: 12px;
left: 4px;
background-color: #fff;
padding: 0 4px;
font-size: 14px;
pointer-events: none;
transition: all .2s ease;
}
.input-container input:focus {
outline: none;
border: 1px solid #3f51b5;
}
.input-container input:valid + label,
.input-container input:focus + label {
top: -8px;
color: #3f51b5;
}
<div class="input-container">
<input id="my-input" type="text" required>
<label for="my-input">My input label</label>
</div>
So I'm trying to make a dropdown list overlap the elements below when expanded. Unfortunately, even when elements in the same stacking context have a position, and dropdown container div set to a z-index of 2, the issue still persists; instead of overlapping the elements below, it shifts them down. I have also attempted shuffling around the stacking context by adding the opacity property to various elements, but that hasn't worked either. The code can be seen below:
#firstone {
z-index: 2;
}
#contain {
height: 400px;
width: 400px;
background-color: rgba(100, 25, 25, 0.2);
}
body {
text-align: center;
}
input:focus {
outline: none;
}
.fancy_input_box {
text-align: left;
display: inline-block;
margin: 40px 3% 1px;
position: relative;
}
.fancy_input {
font: 15px/24px "Lato", Arial, sans-serif;
color: #aaa;
box-sizing: border-box;
letter-spacing: 1px;
border: 0;
padding: 7px 7px;
border: 1px solid #ccc;
position: relative;
background: transparent;
}
.fancy_input:focus~.dropdown-content {
display: block;
cursor: default;
}
.fancy_input:focus~.dropdown-content>span {
display: block;
cursor: default;
}
.dropdown-content {
display: none;
background-color: rgba(0, 0, 0, 0.2);
width: 222px;
overflow: auto;
position: relative;
}
.dropdown-content:active {
display: block;
}
.dropdown-content>span {
padding: 12px 16px;
display: none;
}
.dropdown-content>span:hover {
background-color: rgba(0, 0, 0, 0.1);
}
.fancy_input~.fancy_label {
position: absolute;
left: 14px;
width: 100%;
top: 10px;
color: #aaa;
letter-spacing: 0.5px;
transition: 0.3s;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
z-index: -1;
}
.fancy_input:focus~.fancy_label {
top: -18px;
left: 1px;
font-size: 12px;
color: grey !important;
transition: 0.3s;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
}
.fancy_input:focus {
border: 1px solid grey !important;
}
.fancy_input:not(focus):valid~.fancy_label {
top: -18px;
font-size: 12px;
left: 1px;
color: #aaa;
transition: 0.3s;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
}
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="test.css">
</head>
<body>
<div id="contain">
<div id="firstone" class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="25" size="25" required>
<label class="fancy_label">Search</label>
<div class="dropdown-content">
<span>a</span>
<span>b</span>
<span>c</span>
<span>d</span>
<span>e</span>
</div>
</div>
<div class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="4" size="10">
<label class="fancy_label">Thing</label>
</div>
<br>
<div>
<div class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="4" size="10">
<label class="fancy_label">stuff</label>
</div>
<div class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="4" size="10">
<label class="fancy_label">more stuff</label>
</div>
<div class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="4" size="10">
<label class="fancy_label">more stuff</label>
</div>
</div>
</div>
</body>
</html>
You dropdown content should be absolute positioned.
Update your dropdown styles as shown below :
.dropdown-content {
display: none;
background-color: rgba(0, 0, 0, 0.2);
width: 222px;
overflow: auto;
position: absolute;
left: 0;
top: 100%;
}
Try following code just set position absolute. also i change width 100% in dropdown-content div for good design.
#firstone {
z-index: 2;
}
#contain {
height: 400px;
width: 400px;
background-color: rgba(100, 25, 25, 0.2);
}
body {
text-align: center;
}
input:focus {
outline: none;
}
.fancy_input_box {
text-align: left;
display: inline-block;
margin: 40px 3% 1px;
position: relative;
}
.fancy_input {
font: 15px/24px "Lato", Arial, sans-serif;
color: #aaa;
box-sizing: border-box;
letter-spacing: 1px;
border: 0;
padding: 7px 7px;
border: 1px solid #ccc;
position: relative;
background: transparent;
}
.fancy_input:focus~.dropdown-content {
display: block;
cursor: default;
}
.fancy_input:focus~.dropdown-content>span {
display: block;
cursor: default;
}
.dropdown-content {
display: none;
background-color: rgba(0, 0, 0, 0.2);
width: 100%;
overflow: auto;
position: absolute;
}
.dropdown-content:active {
display: block;
}
.dropdown-content>span {
padding: 12px 16px;
display: none;
}
.dropdown-content>span:hover {
background-color: rgba(0, 0, 0, 0.1);
}
.fancy_input~.fancy_label {
position: absolute;
left: 14px;
width: 100%;
top: 10px;
color: #aaa;
letter-spacing: 0.5px;
transition: 0.3s;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
z-index: -1;
}
.fancy_input:focus~.fancy_label {
top: -18px;
left: 1px;
font-size: 12px;
color: grey !important;
transition: 0.3s;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
}
.fancy_input:focus {
border: 1px solid grey !important;
}
.fancy_input:not(focus):valid~.fancy_label {
top: -18px;
font-size: 12px;
left: 1px;
color: #aaa;
transition: 0.3s;
-webkit-transition: 0.3s;
-moz-transition: 0.3s;
}
<div id="contain">
<div id="firstone" class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="25" size="25" required>
<label class="fancy_label">Search</label>
<div class="dropdown-content">
<span>a</span>
<span>b</span>
<span>c</span>
<span>d</span>
<span>e</span>
</div>
</div>
<div class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="4" size="10">
<label class="fancy_label">Thing</label>
</div>
<br>
<div>
<div class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="4" size="10">
<label class="fancy_label">stuff</label>
</div>
<div class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="4" size="10">
<label class="fancy_label">more stuff</label>
</div>
<div class="fancy_input_box">
<input class="fancy_input" type="text" placeholder="" maxlength="4" size="10">
<label class="fancy_label">more stuff</label>
</div>
</div>
</div>
just add position:absoute and top:100%; in your dropdown-content class
jsfiddle from your code
.dropdown-content {
display: none;
background-color: rgba(0, 0, 0, 0.2);
width: 222px;
overflow: auto;
position: absolute;
left: 0;
top: 100%;
}
How can I place label on top of the input tag, by default it is placed inside of the input tag when I click on it, it jumps to the top of the input tag,
This is my attempt:
input {
font-size: 18px;
padding: 10px 10px 10px 5px;
-webkit-appearance: none;
display: block;
background: #fafafa;
color: #636363;
width: 100%;
border: none;
border-radius: 0;
border-bottom: 1px solid #757575;
}
input:focus {
outline: none;
}
/* Label */
label {
color: #999;
font-size: 18px;
font-weight: normal;
position: absolute;
pointer-events: none;
left: 5px;
top: 10px;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}
/* active */
input:focus ~ label,
input.used ~ label {
top: -20px;
-webkit-transform: scale(.75);
transform: scale(.75);
left: -2px;
/* font-size: 14px; */
color: #000;
}
/* Underline */
.bar {
position: relative;
display: block;
width: 100%;
}
.bar:before,
.bar:after {
content: '';
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: #4a89dc;
-webkit-transition: all 0.2s ease;
transition: all 0.2s ease;
}
.bar:before {
left: 50%;
}
.bar:after {
right: 50%;
}
/* active */
input:focus ~ .bar:before,
input:focus ~ .bar:after {
width: 50%;
}
/* Highlight */
.highlight {
position: absolute;
height: 60%;
width: 100px;
top: 25%;
left: 0;
pointer-events: none;
opacity: 0.5;
}
/* active */
input:focus ~ .highlight {
-webkit-animation: inputHighlighter 0.3s ease;
animation: inputHighlighter 0.3s ease;
}
<div class="group">
<input type="text" name="name" placeholder="" readonly>
<span class="highlight">
</span><span class="bar"></span>
<label>FULLNAME</label>
</div>
Please how can I place the label on top of the input tag permanently. At the moment it is placed on the input tag and on clicking to it, it jumps to the top of the tag
you could try something like
<form name="message" method="post">
<section>
<div>
<label for="name">Name</label>
<input id="name" type="text" value="" name="name">
</div>
<div>
<label for="email">Email</label>
<input id="email" type="text" value="" name="email">
</div>
</section>
<section>
<div>
<label for="subject">Subject</label>
<input id="subject" type="text" value="" name="subject">
</div>
<div class="full">
<label for="message">Message</label>
<input id="message" type="text" value="" name="message">
</div>
</section>
</form>
I want the placeholder to move to the top when the textbox is on focus and also while the user is typing.
I'm not sure if this is just html/css or any javascript too.
My current css looks like this, and I have no js code yet:
input:focus::-webkit-input-placeholder {
font-size: .75em;
position: relative;
top: -15px;
transition: 0.2s ease-out;
}
input::-webkit-input-placeholder {
transition: 0.2s ease-in;
}
input[type="text"]:focus, input[type="password"]:focus {
height: 50px;
padding-bottom: 0px;
transition: 0.2s ease-in;
}
input[type="text"], input[type="password"] {
height: 50px;
transition: 0.2s ease-in;
}
It almost does the work but the placeholder disappears when I start typing. I'm using twitter-bootstrap, if that makes anything easier!
Thanks.
You could do it like this
HTML:
<div>
<input type="text" class="inputText" />
<span class="floating-label">Your email address</span>
</div>
CSS:
input:focus ~ .floating-label,
input:not(:focus):valid ~ .floating-label{
top: 8px;
bottom: 10px;
left: 20px;
font-size: 11px;
opacity: 1;
}
.inputText {
font-size: 14px;
width: 200px;
height: 35px;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 20px;
top: 18px;
transition: 0.2s ease all;
}
Working JSFiddle here https://jsfiddle.net/273ntk5s/2/
.user-input-wrp {
position: relative;
width: 50%;
}
.user-input-wrp .inputText{
width: 100%;
outline: none;
border:none;
border-bottom: 1px solid #777;
box-shadow: none !important;
}
.user-input-wrp .inputText:focus{
border-color: blue;
border-width: medium medium 2px;
}
.user-input-wrp .floating-label {
position: absolute;
pointer-events: none;
top: 18px;
left: 10px;
transition: 0.2s ease all;
}
.user-input-wrp input:focus ~ .floating-label,
.user-input-wrp input:not(:focus):valid ~ .floating-label{
top: 0px;
left: 10px;
font-size: 13px;
opacity: 1;
}
<h1>The floating label</h1>
<div class="user-input-wrp">
<br/>
<input type="text" class="inputText" required/>
<span class="floating-label">Your email address</span>
</div>
Modified the code from #user1846747 a little.
Only using HTML and css
.searchformfld{
position: relative;
margin: 5px 0px;
}
.searchformfld label{
position: absolute;
padding-left: 10px;
top:15px;
cursor: text;
}
.searchformfld input:focus + label,.searchformfld input:not(:placeholder-shown) + label{
opacity:1;
transform: scale(.9) translateY(-100%) translateX(-10px);
color:#000;
}
.searchformfld input:focus{
border:1px solid #000;
outline-color: #000;
}
.searchformfld{
padding: 15px;
margin:15px 0px;
}
.searchformfld input{
width:100%;
padding-left: 10px;
}
.searchformfld label,.searchformfld input{
transition: all 0.2s;
transition-timing-function: ease;
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
opacity:0.5;
}
<div class="searchformfld">
<input type="text" class="candidateName" id="candidateName" name="candidateName" placeholder=" "/>
<label for="candidateName">Candidate name</label>
</div>
You can try the below code. It only uses HTML and CSS and does not reply on Javascript or component libraries:
.text-field {
position: relative;
margin: 10px 2.5px 20px 2.5px;
}
input {
display: inline-block;
border: thin solid #fafafa;
border-bottom: solid medium #999;
color: #444;
background-color: #fafafa;
padding: 10px 10px 10px 10px;
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
input:focus {
border: thin solid #32cd32;
border-bottom: solid medium #32cd32;
background-color:#fff;
}
label {
color: #999;
position: absolute;
pointer-events: none;
left: 10px;
top: 10px;
transition: 0.2s;
}
input:focus ~ label, input:valid ~ label {
top: -10px;
left: 15px;
font-size: small;
color: #32cd32;
background-color:#fff;
padding:0 5px 0 5px;
}
<div class="text-field">
<input type="text" required>
<label>Input field 1</label>
</div>
<div class="text-field">
<input type="text" required>
<label>Input field 2</label>
</div>
span{
display:block;
}
input:focus::-webkit-input-placeholder { color:transparent; }
input:focus:-moz-placeholder { color:transparent; } /* FF 4-18 */
input:focus::-moz-placeholder { color:transparent; } /* FF 19+ */
input:focus:-ms-input-placeholder { color:transparent; } /* IE 10+ */
<script src="http://code.jquery.com/jquery-3.1.1.min.js"></script>
<script>
$(document).ready(function() {
$('input').focus(function(){
placeholder = $(this).attr('placeholder');
if(placeholder != undefined){
$(this).parent().prepend('<span class="input-placeholder">'+placeholder+'</span>');
}
});
$('input').blur(function(){
$(this).parent().find('.input-placeholder').remove();
});
});
</script>
<div>
<input type="text" class="inputText" placeholder="Email adress" required/>
</div>
The solution I want to propose deals with an input with the movement of the placeholder without the need for the required attribute
.inputField {
position: relative;
}
.inputField input {
padding: 8px 20px;
padding-top: 18px;
border: 1.8px solid rgba(107, 107, 107, 0.4);
border-radius: 3px;
width: 50%;
color: black;
}
.inputField input:focus {
border: 1.8px solid #6b6b6b;
outline: none;
}
.inputField span {
pointer-events: none;
opacity: 0.5;
position: absolute;
padding-left: 20px;
left: 0;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
cursor: text;
}
.inputField input:focus+span,
.inputField input:not(:placeholder-shown)+span {
top: 7px;
-webkit-transform: scale(0.7) translateY(-10%) translateX(-8.5px);
transform: scale(0.7) translateY(-10%) translateX(-8.5px);
}
.inputField input,
.inputField span {
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-transition: all 0.2s;
transition: all 0.2s;
-webkit-transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
}
<div class="inputField">
<input type="text" placeholder=" " />
<span>Placeholder</span>
</div>
That site isn't moving the placeholder, but placing a div (.floating-label) over the input, so when the input is focused the div just animates to be over the input. The key part here is using pointer-events: none; in the floating div, so when you click it the event goes through it to the input box behind it.
if your Floating label is not working when required attribute is removed, try this: using input:not(:placeholder-shown)
input:focus ~ .floating-label,
input:not(:placeholder-shown) ~ .floating-label{
top: 8px;
bottom: 10px;
left: 20px;
font-size: 11px;
opacity: 1;
}
.inputText {
font-size: 14px;
width: 200px;
height: 35px;
}
.floating-label {
position: absolute;
pointer-events: none;
left: 20px;
top: 18px;
transition: 0.2s ease all;
}
<div>
<input placeholder="" type="text" class="inputText" />
<span class="floating-label">Your email address</span>
</div>