Floating Labels
How do I make an floating labels?
Inputs with labels that float to the top of the field when there is a value.. What is a floating labels? How do you make a floating labels? This script and codes were developed by Cory on 13 December 2022, Tuesday.
Floating Labels - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Floating Labels</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <label for="text"> <div class="label-text">Text</div> <input id="text" type="text"/>
</label>
<label for="number"> <div class="label-text">Number</div> <input id="number" type="number" required/>
</label>
<label for="date"> <div class="label-text">Date</div> <input id="date" type="date" required/>
</label> <script src="js/index.js"></script>
</body>
</html>
Floating Labels - Script Codes CSS Codes
label { position: relative; margin-top: 1em; display: inline-block;
}
input { padding: .5em; outline: none; border: 1px solid #ccc; border-radius: .5em; margin: 0;
}
[required] { box-shadow: 0 0 .25em .25em hsla(0, 0%, 0%, .2);
}
:invalid { border-color: red;
}
.label-text { font-size: .8em; color: #999; font-family: "Helvetica", sans-serif; padding: .5em; -webkit-transition: top .25s; transition: top .25s;
}
.as-placeholder .label-text { position: absolute; top: 0; left: 0;
}
.as-label .label-text { position: absolute; top: -1.6em; padding: .5em .5em .25em .5em; background: #fff;
}
Floating Labels - Script Codes JS Codes
var labels = document.querySelectorAll('label');
Array.prototype.slice.call(labels, 0).forEach(function (label) { label.classList.add('as-placeholder');
});
document.body.addEventListener('focus', function (evt) { var target = evt.target, label = target.labels[0]; if (target.nodeName === 'INPUT' && label) { if (label.classList.contains('as-label')) { return; } else { label.classList.add('as-label'); label.classList.remove('as-placeholder'); } }
}, true);
document.body.addEventListener('blur', function (evt) { var target = evt.target, label = target.labels[0], required = target.required; target.required = false; if (target.nodeName === 'INPUT' && label) { if (target.validity.valid && target.value === "") { label.classList.add('as-placeholder'); label.classList.remove('as-label'); } target.required = required; }
}, true)
Developer | Cory |
Username | uniqname |
Uploaded | December 13, 2022 |
Rating | 3 |
Size | 2,238 Kb |
Views | 22,264 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
X-Picture tag | 2,573 Kb |
PictureTime | 3,565 Kb |
Memory Leak Demo | 2,074 Kb |
Digital Clock | 1,897 Kb |
Hover activated accordian with default state | 1,946 Kb |
Javascript Digital Clock Example | 1,797 Kb |
JS REPL | 5,216 Kb |
Audio Player | 7,940 Kb |
A content slider | 2,374 Kb |
Paper like dialog compoent | 4,701 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Addthis_button | Esambino | 1,691 Kb |
Basic HTML Slideshow | Tomhodgins | 3,386 Kb |
Cartoon Bomb | Tcmulder | 4,929 Kb |
Practice using Wixel | Emnk | 3,057 Kb |
Realistic Buttons | Stoypenny | 2,248 Kb |
Loader | MikitaLisavets | 3,321 Kb |
Background Images | Jooonebug | 2,100 Kb |
A Pen by Alex Bergin | Abergin | 3,347 Kb |
Cool audio | Bigliam | 1,868 Kb |
After America | Jonathangarner | 2,686 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!