Skip to content

Instantly share code, notes, and snippets.

@matt-daniel-brown
Created December 10, 2020 15:55
Show Gist options
  • Save matt-daniel-brown/14b3e3ab5234365e223fac236cb7bca9 to your computer and use it in GitHub Desktop.
Save matt-daniel-brown/14b3e3ab5234365e223fac236cb7bca9 to your computer and use it in GitHub Desktop.
CDN Floating Labels
<div class="body">
<div class="container max-width-xxxs">
<form>
<div class="wrapper">
<input class="form-control width-100%" placeholder="Name" type="text" name="inputName" id="inputName">
<label class="floating-label" for="inputName">Name</label>
</div>
</form>
</div>
</div>
<script src="https://unpkg.com/[email protected]/main/assets/js/util.js"></script>
// 💡 Floating labels in CSS using the :placeholder-shown selector.
.body {
height: 100vh;
display: flex;
align-items: center;
}
.wrapper {
position: relative;
}
.floating-label {
position: absolute;
top: -1.25em;
left: 0;
opacity: 0;
transform: translateY(20%);
transition: transform .3s;
}
.form-control:not(:placeholder-shown) + .floating-label {
opacity: 1;
transform: translateY(0);
}
<link href="https://unpkg.com/[email protected]/main/assets/css/style.css" rel="stylesheet" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment