Movatterモバイル変換


[0]ホーム

URL:


Framework:


Hire UsGet CoreUI PRO all-access

React Floating labels

Floating labels

React floating label component. Create beautifully simple form labels that float over your input fields.

Other Frameworks

CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.

On this page

Example#

UsefloatingLabel property on<CFormInput>,<CFormSelect> or<CFormTextarea> to enable floating labels with textual form fields. Aplaceholder is required on each<CFormInput>,<CFormSelect> and<CFormTextarea> as our method of CSS-only floating labels uses the:placeholder-shown pseudo-element.

You can create the same form control by wrapping a pair of<CFormInput> and<CFormLabel> elements in<CFormFloating> to enable floating labels with textual form fields. Aplaceholder is required on each<CFormInput> as our method of CSS-only floating labels uses the:placeholder-shown pseudo-element. Also, note that the<CFormInput> must come first so we can utilize a sibling selector (e.g.,~).

<CFormFloatingclassName="mb-3">
<CFormInputtype="email"id="floatingInput"placeholder="[email protected]"/>
<CFormLabelhtmlFor="floatingInput">Email address</CFormLabel>
</CFormFloating>
<CFormFloating>
<CFormInputtype="password"id="floatingPassword"placeholder="Password"/>
<CFormLabelhtmlFor="exampleFormControlTextarea1">Password</CFormLabel>
</CFormFloating>

When there's avalue already defined,<CFormLabel>s will automatically adjust to their floated position.

Form validation styles also work as expected.

Textareas#

By default,<CFormTextarea>s will be the same height as<CFormInput>s.

To set a custom height on your<CFormTextarea>, do not use therows attribute. Instead, set an explicitheight (either inline or via custom CSS).

Selects#

Other than<CFormInput>, floating labels are only available on<CFormSelect>s. They work in the same way, but unlike<CFormInput>s, they'll always show the<CFormLabel> in its floated state.Selects withsize andmultiple are not supported.

Layout#

When working with the CoreUI for Bootstrap grid system, be sure to place form elements within column classes.

API#

Check out the documentation below for a comprehensive guide to all the props you can use with the components mentioned here.

CoreUI for React is Open Source UI Components Library for React.js.

CoreUI code licensedMIT, docsCC BY 3.0. CoreUI PRO requires acommercial license.


[8]ページ先頭

©2009-2025 Movatter.jp