Performance: Creating custom component variants
This affects page load speed and rendering performance by adding CSS rules and potentially increasing DOM complexity.
.btn-custom { --bs-btn-bg: #123456; --bs-btn-color: white; }.btn-custom { background-color: #123456; color: white; padding: 1rem 2rem; border-radius: 0; }| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Custom variant with many new CSS rules | No extra DOM nodes | Triggers full style recalculation | Medium paint cost due to style changes | [X] Bad |
| Custom variant using CSS variables and utilities | No extra DOM nodes | Minimal style recalculation scoped to variant | Low paint cost | [OK] Good |
btn-custom?
$btn-custom-bg: #28a745; @include button-variant($btn-custom-bg, #fff);Test
$btn-special-bg: #ff5733; @include button-variant($btn-special-bg, #fff);What is the most likely reason your custom variant
btn-special is not working?btn-special class but does not apply it automatically.btn-special along with btn.btn-special to the button element -> Option Ccard-blue variant and applies it to a card?card and card-blue classes to keep Bootstrap card styles and add custom variant styles.Pass the test and this pattern moves unknown