> .form-control-plaintext,
> .form-select {
~ label {
- transform: $form-floating-label-transform;
+ @include form-floating-active-label-styles();
+ color: rgba(var(--#{$prefix}body-color-rgb), #{$form-floating-label-opacity});
+
+ &::after {
+ position: absolute;
+ inset: $form-floating-padding-y ($form-floating-padding-x * .5);
+ z-index: -1;
+ height: $form-floating-label-height;
+ content: "";
+ background-color: $input-bg;
+ @include border-radius($input-border-radius);
+ }
}
}
+
// Duplicated because `:-webkit-autofill` invalidates other selectors when grouped
> .form-control:-webkit-autofill {
~ label {
- transform: $form-floating-label-transform;
+ @include form-floating-active-label-styles();
+ color: rgba(var(--#{$prefix}body-color-rgb), #{$form-floating-label-opacity});
}
}
border-width: $input-border-width 0; // Required to properly position label text - as explained above
}
}
+
+ > :disabled ~ label {
+ color: $form-floating-label-disabled-color;
+
+ &::after {
+ background-color: $input-disabled-bg;
+ }
+ }
}
+
+// Todo in v6: Consider combining this with the .form-control-plaintext rules to reduce some CSS?
+.form-floating-always {
+ > .form-control {
+ @include form-floating-active-input-styles();
+
+ &::placeholder {
+ color: $input-color;
+ }
+ &:focus::placeholder {
+ color: $input-placeholder-color;
+ }
+ }
+
+ > label {
+ @include form-floating-active-label-styles();
+ }
+}
</div>
{{< /example >}}
+ ## Input groups
+
+ Floating labels also support `.input-group`.
+
+ {{< example >}}
+ <div class="input-group mb-3">
+ <span class="input-group-text">@</span>
+ <div class="form-floating">
+ <input type="text" class="form-control" id="floatingInputGroup1" placeholder="Username">
+ <label for="floatingInputGroup1">Username</label>
+ </div>
+ </div>
+ {{< /example >}}
+
+ When using `.input-group` and `.form-floating` along with form validation, the `-feedback` should be placed outside of the `.form-floating`, but inside of the `.input-group`. This means that the feedback will need to be shown using javascript.
+
+ {{< example >}}
+ <div class="input-group has-validation">
+ <span class="input-group-text">@</span>
+ <div class="form-floating is-invalid">
+ <input type="text" class="form-control is-invalid" id="floatingInputGroup2" placeholder="Username" required>
+ <label for="floatingInputGroup2">Username</label>
+ </div>
+ <div class="invalid-feedback">
+ Please choose a username.
+ </div>
+ </div>
+ {{< /example >}}
+
+## Always floating
+
+Make any `.form-control` always use a floating label with visible placeholder with the `.form-floating-always` modifier class. Visible placeholders use the default input `color` and lighten to the placeholder color on focus. This matches them with other floating labels built with plaintext inputs and selects.
+
+{{< example >}}
+<div class="form-floating form-floating-always mb-3">
+ <input type="email" class="form-control" id="floatingInput" placeholder="name@example.com">
+ <label for="floatingInput">Email address</label>
+</div>
+<div class="form-floating form-floating-always">
+ <input type="password" class="form-control" id="floatingPassword" placeholder="••••••••">
+ <label for="floatingPassword">Password</label>
+</div>
+{{< /example >}}
+
## Layout
When working with the Bootstrap grid system, be sure to place form elements within column classes.