vue3-float-label
Version:
A Vue 3 component for float labels.
86 lines (83 loc) • 2.6 kB
CSS
:root {
--vfl-padding-y: 17px;
--vfl-padding-x: 16px;
--vfl-label-color: #6c6c6c;
--border-color: lightgray;
--border-width: 1px;
}
.float-label {
display: flex;
flex-direction: column;
position: relative;
width: 100%;
}
.float-label__label__bg {
background-image: linear-gradient(180deg, #FFF 55%, #ffffff00 100%);
display: block;
pointer-events: none;
position: absolute;
top: 2px;
right: calc(var(--vfl-padding-x) - 2px);
left: calc(var(--vfl-padding-x) - 2px);
height: 26px;
opacity: 0;
transition: opacity 0.3s;
}
.float-label__label__text {
transition: all .2s;
opacity: 1;
left: calc(var(--vfl-padding-x) -2px);
display: table;
}
.float-label--fade-anim .float-label__label__text {
opacity: 0;
}
.float-label input, .float-label textarea, .float-label select {
padding: var(--vfl-padding-y) var(--vfl-padding-x);
width: 100%;
font-size: 16px;
line-height: 20px;
border: var(--border-width) solid var(--border-color);
margin-bottom: 6px;
-webkit-appearance: none;
-moz-appearance: none;
}
.float-label select {
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E") right 16px top 22px no-repeat;
}
.float-label input:focus, .float-label textarea:focus, .float-label select:focus {
outline: 2px solid #80b4d3;
}
.float-label select {
background-position: top 7px right -3px;
}
.float-label input::placeholder, .float-label > textarea::placeholder, .float-label select::placeholder, .float-label__label__text {
position: absolute;
top: var(--vfl-padding-y);
left: var(--vfl-padding-x);
display: block;
line-height: 24px;
color: var(--vfl-label-color);
}
.float-label input::placeholder, .float-label textarea::placeholder {
color: transparent;
transition: opacity 0.2s;
}
.float-label--fade-anim input::placeholder, .float-label--fade-anim textarea::placeholder {
color: gray;
}
.float-label--fixed .float-label__label__text, .float-label--on-focus input:focus ~ .float-label__label .float-label__label__text {
transform-origin: top left;
transform: scale(.85) translateY(-18px);
opacity: 1;
pointer-events: none;
}
.float-label--fixed input::placeholder, .float-label--fixed textarea::placeholder, .float-label--on-focus input:focus::placeholder {
opacity: 0;
}
.float-label--fixed .float-label__label__bg {
opacity: 1;
}
.float-label--no-click {
pointer-events: none;
}