项目作者: tkrotoff

项目描述 :
Bootstrap 5 Floating Label
高级语言: HTML
项目地址: git://github.com/tkrotoff/bootstrap-floating-label.git
创建时间: 2018-08-30T18:11:31Z
项目社区:https://github.com/tkrotoff/bootstrap-floating-label

开源协议:MIT License

下载


@tkrotoff/bootstrap-floating-label

@tkrotoff/bootstrap-floating-label">npm version
Node.js CI
Prettier
Airbnb Code Style

Floating label for Bootstrap 5

demo

Example: https://codesandbox.io/s/github/tkrotoff/bootstrap-floating-label/tree/codesandbox.io

  • Small: less than 200 lines of SCSS
  • Works with modern browsers
  • Works with any font family and size
  • Uses Bootstrap variables

⚠️ Latest implementation for Bootstrap 4 is @tkrotoff/bootstrap-floating-label v0.8

The Nielsen Norman Group talks about “Placeholders and Floating Labels disadvantages”

Usage

npm install @tkrotoff/bootstrap-floating-label

Import bootstrap-floating-label.scss after bootstrap.scss:

  1. @import '~bootstrap/scss/bootstrap';
  2. @import '~@tkrotoff/bootstrap-floating-label/src/bootstrap-floating-label';

Place <label> under <input> inside your Bootstrap code:

  1. <div class="floating-label">
  2. <input type="email" id="email" class="form-control" placeholder="name@example.com">
  3. <label for="email">Email</label>
  4. </div>

Limitations

There is no good way to detect if the user entered text inside an input using CSS.

Thus a placeholder is required <input placeholder=" "> otherwise the label will be above the input instead of inside (see https://codepen.io/tkrotoff/pen/KjgyZj).