![]() |
VOOZH | about |
Bootstrap 5 Close button SASS can be used to change the default values provided for the close button by customizing scss file of bootstrap 5.
Step 1: Install bootstrap using following command:
npm i bootstrap
Step 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 a live server extension.
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 the converted file.
$btn-close-width:value; // for changing the width of the close button $btn-close-padding-x:value; // for changing the left padding and right padding of the close button $btn-close-color:value; // for changing the color of the close button $btn-close-bg:value; // for changing the background image of close button $btn-close-opacity:value; // for changing the opacity of close button $btn-close-hover-opacity:value; // for changing the opacity of close button on hovering $btn-close-disabled-opacity:value; // for changing the opacity of close button when close button is disabled @import "./node_modules/bootstrap/scss/bootstrap"
Example 1: In this example, use the $btn-close-hover-opacity, $btn-close-bg, $btn-close-width, $btn-close-padding-x, $btn-close-opacity, $btn-close-disabled-opacity variables. Here in the scss file, the background image of a close button is changed instead of the default close image, the opacity of the close button on hovering is changed to 1, the width of the close button is changed to 2em, and the left and right padding of the close button is changed to 1em, the opacity of the close button is changed to 0.6, the opacity of a disabled close button is changed to 0.7.
custom.scss
CSS file created after conversion
custom.css
index.html
Output:Example 2: In this example, use the $btn-close-hover-opacity, $btn-close-width, $btn-close-padding-x, $btn-close-opacity, $btn-close-disabled-opacity, $btn-close-color variables. Here in the scss file, the color of the default close button is changed to green, the opacity of the close button on hovering is changed to 1, the width of the close button is changed to 2em, the left and right padding of the close button is changed to 1em, the opacity of the close button is changed to 0.6, the opacity of a disabled close button is changed to 0.1.
custom.scss
CSS file created after conversion
custom.css
index.html
Output:
https://getbootstrap.com/docs/5.0/components/close-button/#sass