Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 4.1 floating labels

I've found on Google a doc example for Bootstrap 4.1 in which they feature floating labels: getbootstrap.com/docs/4.1/examples/floating-labels/

In that page, however, it is not explained how that can be achieved, and I can't find anything in the docs for v. 4.1. Floating labels are not even listed as a new feature in the ship list.

Does anyone know if floating labels are supported?

like image 220
don Avatar asked Jun 04 '18 18:06

don


People also ask

Does bootstrap 5 have float label?

A bootstrap 5 floating label is a text label that shows at full font size within an input field. The label "floats" above the input field when interacting, allowing the user to enter a value. A bootstrap 5 Floating labels indicate the required kind of input for a field.

What are floating labels?

Floating labels display the type of input a field requires. Every Text Field and Select should have a label, except for full-width text fields, which use the input's placeholder attribute instead. Labels are aligned with the input line and always visible.


2 Answers

It says on the Bootstrap examples page that floating-labels are...

"Experiments - Examples that focus on future-friendly features or techniques."

Like many of the other examples, there's an additional CSS file used in the example...

enter image description here

Using the floating-labels.css they work as expected in the supported browsers...

https://www.codeply.com/go/X9VbHqzD4B

like image 141
Zim Avatar answered Sep 25 '22 20:09

Zim


Best way for me is using transform translate. It is smoother. I have added extra classes to prevent overwriting bootstraps original classes.

body{padding:75px}
.form-group.floating>label {
    bottom: 34px;
    left: 8px;
    position: relative;
    background-color: white;
    padding: 0px 5px 0px 5px;
    font-size: 1.1em;
    transition: 0.1s;
    pointer-events: none;
    font-weight: 500 !important;
    transform-origin: bottom left;
}

.form-control.floating:focus~label{
    transform: translate(1px,-85%) scale(0.80);
    opacity: .8;
    color: #005ebf;
}

.form-control.floating:valid~label{
    transform-origin: bottom left;
    transform: translate(1px,-85%) scale(0.80);
    opacity: .8;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>


<div class="form-group floating">
<input type="text" class="form-control floating" id="usr" required value="">
<label for="usr">Username</label>
</div>
like image 25
Mike Aron Avatar answered Sep 22 '22 20:09

Mike Aron