VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-alerts-sass/

⇱ Bootstrap 5 Alerts SASS - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Alerts SASS

Last Updated : 28 Apr, 2025

Bootstrap 5 Alerts SASS can be used to change the default values provided for the alert by customizing the SCSS file.

SASS variables of Alerts:

  • $alert-padding-y: This variable provides the top and bottom padding of the alert. By default, it is 1rem.
  • $alert-padding-x: This variable provides the left and right padding of the alert. By default, it is 1rem.
  • $alert-margin-bottom: This variable provides the bottom margin of the alert. By default, it is 1rem.
  • $alert-border-radius: This variable provides the border radius of the alert. By default, it is 0.375rem.
  • $alert-link-font-weight: This variable provides the font weight of the alert link. By default, it is 700.
  • $alert-border-width: This variable provides the border width of the alert. By default, it is 1px.
  • $alert-bg-scale: This variable provides the contrast of the background color of the alert. By default, it is -80%
  • $alert-border-scale: This variable provides the contrast of the border of the alert. By default, it is -70%
  • $alert-color-scale: This variable provides the contrast of the text color in the alert. By default, it is 40%.
  • $alert-dismissible-padding-r: This variable provides the right padding of the alert which can be dismissed. By default, it is 3rem

SASS Variant Mixin of Alerts:

  • alert-variant: This mixin 'alert-variant' of alert is used in combination with the $theme-colors variable to create contextual modifier classes for alerts.
 

SASS Loop of Alerts:

  • @each: @each loop of alerts is used along with the variant mixin 'alert-variant' to generate contextual modifier classes for modifying the alert background color, border color, and alert text color of the alerts.

Steps to override SCSS of BootStrap:

Step 1: Install bootstrap using the following command: 

npm i bootstrap

Step 2: Create your custom CSS 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: The custom SCSS file name is β€œcustom.scss” and "custom.css" is the converted file

πŸ‘ Image

Syntax:

$variable:value;

@import "./node_modules/bootstrap/scss/bootstrap"

Example 1: In this example, making use of some of the above variables is shown.

custom.scss

custom.css

Output:

πŸ‘ Image
Output

Example 2: In this example, the following code demonstrates the use of some of the above variables

custom.scss

custom.css

Output:

πŸ‘ Image
Output

Example 3: In this example, the following code demonstrates making use of some of the above variables.

custom.scss

custom.css

Output:

πŸ‘ Image
Output

Reference: https://getbootstrap.com/docs/5.0/components/alerts/#sass

Comment
Article Tags:

Explore