![]() |
VOOZH | about |
Bootstrap 5 Floating labels can be used to change the default values provided for the floating label by customizing scss file of bootstrap5.
SASS variables of Floating Labels:
Steps to override scss of Bootstrap:
Step 1: Install bootstrap using following command:
npm i bootstrapStep 2: Create your custom scss file and write the variable you want to override. Then include the bootstrap scss file using import.
$class_to_override: values;
@import "node_modules/bootstrap/scss/bootstrap"
Step 3: Convert the file to CSS using live server.
Step 4: Include the converted scss file to your HTML after the link tag of Bootstrap css.
Project Structure: Here the custom scss file name is "custom.scss" and custom.css is converted file
$class_to_override: values;
@import "node_modules/bootstrap/scss/bootstrap"
Example 1: In this example, making use of the $form-floating-padding-x, $form-floating-padding-y, $form-floating-height, $form-floating-label-opacity variables. Here in the scss file, the top and bottom padding of floating label is changed to 30px, the height of the floating label is changed to 100px, the left and right padding of floating label is changed to 30 px, the opacity of floating label on clicked is changed to 0.9.
custom.scss
CSS file created after conversion
custom.css
index.html
Output:
Example 2: In this example, making use of the $form-floating-padding-x, $form-floating-padding-y, $form-floating-height, $form-floating-input-padding-t, $form-floating-input-padding-b, $form-floating-transition variables. Here in the scss file, the top and bottom padding of the floating label is changed to 30px, the height of the floating label is changed to 100px, the left and right padding of the floating label is changed to 30 px, the opacity transition of the floating labels on clicked is changed to 0.1 with ease-in speed curve and the transformation of the floating label is changed to 4 seconds of transition duration with ease-in speed curve.
custom.scss
CSS file created after conversion
custom.css
index.html
Output:
Reference:https://getbootstrap.com/docs/5.0/forms/floating-labels/#sass