label is not floating to the top - html

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>

Related

Content Moves on Opening Select Dropdown

I need help with the Select Dropdown. It moves the content (Hello World) when opened. I have used Radio Input to select the specfic option when performing a Search. If there is any other better solution for this type of functionality, please assist.
HTML
<span class="dropdown-el">
<input type="radio" name="sortType" value="Relevance" checked="checked" id="sort-relevance"><label for="sort-relevance">Relevance</label>
<input type="radio" name="sortType" value="Popularity" id="sort-best"><label for="sort-best">Product Popularity</label>
<input type="radio" name="sortType" value="PriceIncreasing" id="sort-low"><label for="sort-low">Price Low to High</label>
<input type="radio" name="sortType" value="PriceDecreasing" id="sort-high"><label for="sort-high">Price High to Low</label>
<input type="radio" name="sortType" value="ProductBrand" id="sort-brand"><label for="sort-brand">Product Brand</label>
<input type="radio" name="sortType" value="ProductName" id="sort-name"><label for="sort-name">Product Name</label>
</span>
<h1> Hello World</h1>
CSS
body {
text-align: center;
background: #ebf4fb;
min-height: 95vh;
margin: 0;
padding: 0;
border-bottom: 5vh solid #3694d7;
font-family: "Myriad Pro", "Arial", sans;
font-size: 24px;
}
.dropdown-el {
margin-top: 20vh;
min-width: 12em;
position: relative;
display: inline-block;
margin-right: 1em;
min-height: 2em;
max-height: 2em;
overflow: hidden;
top: 0.5em;
cursor: pointer;
text-align: left;
white-space: nowrap;
color: #444;
outline: none;
border: 0.06em solid transparent;
border-radius: 1em;
background-color: #cde4f5;
transition: 0.3s all ease-in-out;
}
.dropdown-el input:focus + label {
background: #def;
}
.dropdown-el input {
width: 1px;
height: 1px;
display: inline-block;
position: absolute;
opacity: 0.01;
}
.dropdown-el label {
border-top: 0.06em solid #d9d9d9;
display: block;
height: 2em;
line-height: 2em;
padding-left: 1em;
padding-right: 3em;
cursor: pointer;
position: relative;
transition: 0.3s color ease-in-out;
}
.dropdown-el label:nth-child(2) {
margin-top: 2em;
border-top: 0.06em solid #d9d9d9;
}
.dropdown-el input:checked + label {
display: block;
border-top: none;
position: absolute;
top: 0;
width: 100%;
}
.dropdown-el input:checked + label:nth-child(2) {
margin-top: 0;
position: relative;
}
.dropdown-el::after {
content: "";
position: absolute;
right: 0.8em;
top: 0.9em;
border: 0.3em solid #3694d7;
border-color: #3694d7 transparent transparent transparent;
transition: 0.4s all ease-in-out;
}
.dropdown-el.expanded {
border: 0.06em solid #3694d7;
background: #fff;
border-radius: 0.25em;
padding: 0;
box-shadow: rgba(0, 0, 0, 0.1) 3px 3px 5px 0px;
max-height: 15em;
}
.dropdown-el.expanded label {
border-top: 0.06em solid #d9d9d9;
}
.dropdown-el.expanded label:hover {
color: #3694d7;
}
.dropdown-el.expanded input:checked + label {
color: #3694d7;
}
.dropdown-el.expanded::after {
transform: rotate(-180deg);
top: 0.55em;
}
JQuery
$('.dropdown-el').click(function(e) {
e.preventDefault();
e.stopPropagation();
$(this).toggleClass('expanded');
$('#'+$(e.target).attr('for')).prop('checked',true);
});
$(document).click(function() {
$('.dropdown-el').removeClass('expanded');
});
https://codepen.io/libsys/pen/bGKomaE
Please assist.

Move input field on top of span

I've a span as a label for my inputfield. The label goes above the input field when selected.
My problem is that when you try to click on the input field, the label is 'in front' of the inputfield and blocks you from selecting it.
I tried fixing it using z-indexes but this doesn't seem to work.
Can somebody help me with getting the input field in front of the span?
#input {
color: #686868;
vertical-align: middle;
padding: 0px !important;
font-size: 16px;
border-width: 0;
overflow: visible;
box-shadow: none;
border: none;
border-bottom: 1px solid #d5dce3;
background-color: transparent !important;
}
#input:focus {
border-color: #1F76BC;
}
#label {
color: rgba(0,0,0,.99);
transition-timing-function: cubic-bezier(.075,.82,.165,1);
transition-duration: .5s;
position: absolute;
width: 100%;
text-align: left;
font-size: 16px;
bottom: 6px;
color: #8792a1;
}
.container:focus-within #label {
transform: translate3d(0,-26px,0);
color: rgba(0,0,0,.99);
}
.container {
position: relative;
margin-top: 32px;
}
<div class="container">
<span id="label">Provincie</span>
<input type="text" id="input" value="" size="40">
</div>
Use label instead of span and your input will be well clickable, regardless of the location of the placeholder
input = document.querySelector("#input");
label = document.querySelector(".container > label");
input.addEventListener("change", function () {
if (this.value !== "") {
label.style.transform = "translate3d(0, -26px, 0)";
} else {
label.style.transform = "";
}
});
#input {
color: #686868;
vertical-align: middle;
padding: 0px !important;
font-size: 16px;
border-width: 0;
overflow: visible;
box-shadow: none;
border: none;
border-bottom: 1px solid #d5dce3;
background-color: transparent !important;
}
#input:focus {
border-color: #1f76bc;
}
label {
color: rgba(0, 0, 0, 0.99);
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1);
transition-duration: 0.5s;
position: absolute;
width: 100%;
text-align: left;
font-size: 16px;
bottom: 6px;
color: #8792a1;
}
.container:focus-within label {
transform: translate3d(0, -26px, 0);
color: rgba(0, 0, 0, 0.99);
}
.container {
position: relative;
margin-top: 32px;
}
<div class="container">
<label for="input">Provincie</label>
<input type="text" id="input" value="" size="40" />
</div>
please add this style.
#input{
position:relative;
z-index:999;
}
#input {
color: #686868;
vertical-align: middle;
padding: 0px !important;
font-size: 16px;
border-width: 0;
overflow: visible;
box-shadow: none;
border: none;
border-bottom: 1px solid #d5dce3;
background-color: transparent !important;
position:relative;
z-index:999;
}
#input:focus {
border-color: #1F76BC;
}
#label {
color: rgba(0,0,0,.99);
transition-timing-function: cubic-bezier(.075,.82,.165,1);
transition-duration: .5s;
position: absolute;
width: 100%;
text-align: left;
font-size: 16px;
bottom: 6px;
color: #8792a1;
}
.container:focus-within #label {
transform: translate3d(0,-26px,0);
color: rgba(0,0,0,.99);
}
.container {
position: relative;
margin-top: 32px;
}
<div class="container">
<span id="label">Provincie</span>
<input type="text" id="input" value="" size="40">
</div>
Something like this??
#input {
color: #686868;
vertical-align: middle;
padding: 0px !important;
font-size: 16px;
border-width: 0;
overflow: visible;
box-shadow: none;
border: none;
border-bottom: 1px solid #d5dce3;
background-color: transparent !important;
}
#input:focus {
border-color: #1F76BC;
}
#label {
color: rgba(0, 0, 0, .99);
transition-timing-function: cubic-bezier(.075, .82, .165, 1);
transition-duration: .5s;
position: absolute;
width: 100%;
text-align: left;
font-size: 16px;
bottom: 6px;
color: #8792a1;
}
.container:focus-within #label {
transform: translate3d(0, -26px, 0);
color: rgba(0, 0, 0, .99);
}
.container {
position: relative;
margin-top: 32px;
}
<div class="container">
<input type="text" id="input" value="" size="40" placeholder="Provincie">
</div>

How to centre align a heading with existing CSS

I have a css template for a search bar which i am using. I need to add a heading just above and below the search bar , however as i add it , the heading is not centre aligning with my code nor the margin styling is working for me. Can anybody tell me what should be the css to align it in centre of the page , just above the search bar. If i add alignment, the search bar alignment is disturbed. Here is the css for search bar :
.heading{
font-family: Fondamento;
font-size: 24px;
font-style: normal;
font-variant: normal;
font-weight: 700;
line-height: 26.4px;
padding: 0.75em;
position: relative;
}
* {
border: 0;
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
font-size: calc(16px + (24 - 16)*(100vw - 320px)/(1920 - 320));
}
body, button, input {
font: 1em Hind, sans-serif;
line-height: 1.5em;
}
body, input {
color: #171717;
}
body, .search-bar {
display: flex;
}
body {
background: #f1f1f1;
height: 100vh;
}
.search-bar input,
.search-btn,
.search-btn:before,
.search-btn:after {
transition: all 0.25s ease-out;
}
.search-bar input,
.search-btn {
width: 3em;
height: 3em;
}
.search-bar input:invalid:not(:focus),
.search-btn {
cursor: pointer;
}
.search-bar,
.search-bar input:focus,
.search-bar input:valid {
width: 100%;
}
.search-bar input:focus,
.search-bar input:not(:focus) + .search-btn:focus {
outline: transparent;
}
.search-bar {
margin: auto;
padding: 1.5em;
justify-content: center;
max-width: 30em;
}
.search-bar input {
background: transparent;
border-radius: 1.5em;
box-shadow: 0 0 0 0.4em #171717 inset;
padding: 0.75em;
transform: translate(0.5em,0.5em) scale(0.5);
transform-origin: 100% 0;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
}
.search-bar input::-webkit-search-decoration {
-webkit-appearance: none;
}
.search-bar input:focus,
.search-bar input:valid {
background: #fff;
border-radius: 0.375em 0 0 0.375em;
box-shadow: 0 0 0 0.1em #d9d9d9 inset;
transform: scale(1);
}
.search-btn {
background: #171717;
border-radius: 0 0.75em 0.75em 0 / 0 1.5em 1.5em 0;
padding: 0.75em;
position: relative;
transform: translate(0.25em,0.25em) rotate(45deg) scale(0.25,0.125);
transform-origin: 0 50%;
}
.search-btn:before,
.search-btn:after {
content: "";
display: block;
opacity: 0;
position: absolute;
}
.search-btn:before {
border-radius: 50%;
box-shadow: 0 0 0 0.2em #f1f1f1 inset;
top: 0.75em;
left: 0.75em;
width: 1.2em;
height: 1.2em;
}
.search-btn:after {
background: #f1f1f1;
border-radius: 0 0.25em 0.25em 0;
top: 51%;
left: 51%;
width: 0.75em;
height: 0.25em;
transform: translate(0.2em,0) rotate(45deg);
transform-origin: 0 50%;
}
.search-btn span {
display: inline-block;
overflow: hidden;
width: 1px;
height: 1px;
}
/* Active state */
.search-bar input:focus + .search-btn,
.search-bar input:valid + .search-btn {
background: #2762f3;
border-radius: 0 0.375em 0.375em 0;
transform: scale(1);
}
.search-bar input:focus + .search-btn:before,
.search-bar input:focus + .search-btn:after,
.search-bar input:valid + .search-btn:before,
.search-bar input:valid + .search-btn:after {
opacity: 1;
}
.search-bar input:focus + .search-btn:hover,
.search-bar input:valid + .search-btn:hover,
.search-bar input:valid:not(:focus) + .search-btn:focus {
background: #0c48db;
}
.search-bar input:focus + .search-btn:active,
.search-bar input:valid + .search-btn:active {
transform: translateY(1px);
}
#media screen and (prefers-color-scheme: dark) {
body, input {
color: #f1f1f1;
}
body {
background: #171717;
}
.search-bar input {
box-shadow: 0 0 0 0.4em #f1f1f1 inset;
}
.search-bar input:focus,
.search-bar input:valid {
background: #3d3d3d;
box-shadow: 0 0 0 0.1em #3d3d3d inset;
}
.search-btn {
background: #f1f1f1;
}
}
i need to change the ".heading" css.
HTML Code :
<body>
<h1 class = "heading">WikiMedia</h1>
<form action="/search" method="post" class="search-bar">
<input type="search" name="text" pattern=".*\S.*" required>
<button class="search-btn" type="submit">
<span>Search</span>
</button>
</form>
</body>
without the HTML code its not possible to give you a solution but i have some suggestions.
put the heading in a seperate div and then change its display:flex. then add justify-content:center and align-items:center.
this should work.

Custom checkboxes move slightly when selected

I modified the checkboxes in my project to look more aligned with the rest of the design but I have a problem: whenever selected the label of the checkbox moves slightly.
input[type="checkbox"] {
display: none !important;
}
input[type="checkbox"]+label:before {
position: relative;
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label:before {
position: relative;
content: "✔";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
<input type="checkbox" />
<label>Click to accept</label>
Here's the result:
And here's what happens if I select it:
What am I doing wrong?
Nowadays and for awhile you can fix this if you set the parent to display:flex
input[type="checkbox"] {
display: none !important;
}
label {
display: flex;
/* just to vertically the text with the box */
align-items: center
}
input[type="checkbox"]+label::before {
content: "";
display: block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label::before {
content: "✔";
/* just to center inside the box */
display: grid;
place-content: center;
}
<input id="input" type="checkbox" />
<label for="input">Click to accept</label>
OLD ANSWER
To fix the "moving" you need to:
set vertical-align: some value in label::before I have choose bottom.
And to align the "✔" (in case it doesn't - snippet isn't), you need to:
add text-align:center and line-height:22px (same as the height) in :checked+label::before
input[type="checkbox"] {
display: none !important;
}
input[type="checkbox"]+label::before {
position: relative;
content: " ";
display: inline-block;
vertical-align: bottom;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: 0 10px 0 0;
}
input[type="checkbox"]:checked+label::before {
content: "✔";
text-align: center;
line-height: 22px;
}
<input id="input" type="checkbox" />
<label for="input">Click to accept</label>
NB: In both answers I removed duplicated properties and you're missing the for attribute in label to match id in input, otherwise you can't click in the pseudo checkbox, only in the label
You can see another way here.
See below working example:
/*--CSS--*/
input[type="checkbox"] {
-webkit-appearance: none;
background-color: transparent;
-webkit-rtl-ordering: logical;
user-select: text;
cursor: pointer;
padding: 1px;
border-width: 0;
border-style: inset;
border-color: initial;
border-image: initial;
float: left;
margin: 0 25px 0 0;
position: relative;
}
input[type="checkbox"]:after {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
content: "";
position: absolute;
left: 0;
z-index: 1;
width: 16px;
height: 16px;
border: 1px solid #c0c0c0;
top:0;
}
input[type="checkbox"]:before {
-webkit-transition: all 0.3s ease-in-out;
-moz-transition: all 0.3s ease-in-out;
transition: all 0.3s ease-in-out;
content: "";
position: absolute;
left: 0;
z-index: 1;
width: 16px;
height: 16px;
border: 1px solid #c0c0c0;
top:0;
opactity:0;
}
input[type="checkbox"]:checked:before {
-webkit-transform: rotate(-45deg);
-moz-transform: rotate(-45deg);
-ms-transform: rotate(-45deg);
-o-transform: rotate(-45deg);
transform: rotate(-45deg);
height: 5px;
border-color: #009688;
border-top-style: none;
border-right-style: none;
outline: none;
opacity: 1;
width: 12px;
top: 3px;
left: 3px;
}
input[type="checkbox"]:focus{outline:0;}
<!--HTML-->
<input type="checkbox" />
<label>Click to accept</label>
I have used a flexbox for the label to align the items vertically. Adding text-align:center when the checkbox is checked, ensures the marker is horizontally centered.
label {
display: flex;
align-items: center;
}
input[type="checkbox"] {
display: none;
}
input[type="checkbox"]+label:before {
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin-right: 0.5em;
}
input[type="checkbox"]:checked+label:before {
content: "✔";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
margin-right: 0.5em;
text-align: center;
}
<input type="checkbox" id="accept" />
<label for="accept">Click to accept</label>
you can try this, this is working
input[type="checkbox"] {
position: absolute;
width: 100%;
height: 100%;
opacity: 0;
}
input[type="checkbox"] + label:before {
position: relative;
content: " ";
display: inline-block;
width: 22px;
height: 22px;
border: 1px solid grey;
top: 4px;
margin: -8px 10px 0 0;
vertical-align: middle;
}
input[type="checkbox"]:checked + label:before {
content: "✔";
text-align: center;
line-height: 22px;
}
<input type="checkbox"/>
<label>Click to accept</label>

How to move placeholder to top on focus AND while typing?

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>