Loading...
Loading...
This skill should be used when the user asks "how do I customize Bootstrap", "how to create a custom Bootstrap theme", "what Sass variables can I override", "how to implement dark mode in Bootstrap", "how to change Bootstrap colors", "how to override Bootstrap defaults", "how to add custom colors to Bootstrap", "how to enable Bootstrap shadows", "how to compile Bootstrap Sass", "how to use Bootstrap CSS variables", or needs help with Bootstrap theming, Sass variable overrides, CSS custom properties, or color mode implementation.
npx skill4agent add sjnims/bootstrap-expert bootstrap-customize/* Global override */
:root {
--bs-primary: #0074d9;
--bs-primary-rgb: 0, 116, 217;
--bs-body-font-family: 'Inter', sans-serif;
}
/* Component-level override */
.my-card {
--bs-card-bg: #f0f0f0;
--bs-card-border-color: transparent;
}
/* Local scope override */
.custom-button {
--bs-btn-bg: #custom-color;
--bs-btn-border-color: #custom-color;
--bs-btn-hover-bg: #darker-custom;
}bs-$prefix$prefix: "myapp-"; // Results in --myapp-primary, --myapp-body-bg, etc.// 1. Include functions first
@import "bootstrap/scss/functions";
// 2. Override default variables
$primary: #0074d9;
$secondary: #7fdbff;
$font-family-base: 'Inter', sans-serif;
$border-radius: 0.5rem;
$enable-shadows: true;
// 3. Import Bootstrap
@import "bootstrap/scss/bootstrap";$theme-colors: (
"primary": $primary,
"secondary": $secondary,
"success": $success,
"info": $info,
"warning": $warning,
"danger": $danger,
"light": $light,
"dark": $dark
);// Add to theme-colors map
$custom-colors: (
"custom": #900,
"brand": #1a73e8
);
// Merge with defaults
$theme-colors: map-merge($theme-colors, $custom-colors);.bg-custom.text-brand.btn-custom$theme-colors// Light mode variants
$theme-colors-text: map-merge($theme-colors-text, ("custom": #712cf9));
$theme-colors-bg-subtle: map-merge($theme-colors-bg-subtle, ("custom": #e1d2fe));
$theme-colors-border-subtle: map-merge($theme-colors-border-subtle, ("custom": #bfa1fc));
// Dark mode variants
$theme-colors-text-dark: map-merge($theme-colors-text-dark, ("custom": #e1d2f2));
$theme-colors-bg-subtle-dark: map-merge($theme-colors-bg-subtle-dark, ("custom": #8951fa));
$theme-colors-border-subtle-dark: map-merge($theme-colors-border-subtle-dark, ("custom": #e1d2f2));*-text-emphasis*-bg-subtle*-border-subtle$theme-colors: map-remove($theme-colors, "info", "light");Warning: The,primary, andsuccesskeys are required and cannot be removed. They're used by Bootstrap's core styles for links, form validation, and other components. Removing them will cause Sass compilation errors.danger
secondaryinfowarninglightdarkprimarysuccessdangerdata-bs-theme<html><!-- Light mode (default) -->
<html lang="en" data-bs-theme="light">
<!-- Dark mode -->
<html lang="en" data-bs-theme="dark">
<!-- Per-component -->
<div data-bs-theme="dark">
<div class="card">Dark card in light page</div>
</div>const toggleTheme = () => {
const html = document.documentElement;
const current = html.getAttribute('data-bs-theme');
html.setAttribute('data-bs-theme', current === 'dark' ? 'light' : 'dark');
};
// With system preference
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
document.documentElement.setAttribute('data-bs-theme',
prefersDark.matches ? 'dark' : 'light'
);
// Listen for system changes
prefersDark.addEventListener('change', (e) => {
document.documentElement.setAttribute('data-bs-theme',
e.matches ? 'dark' : 'light'
);
});$color-mode-type$color-mode-type: data;data-bs-theme<html data-bs-theme="dark">$color-mode-type: media;prefers-color-scheme@media (prefers-color-scheme: dark) {
/* Dark mode styles applied automatically */
}// Light mode colors
:root,
[data-bs-theme="light"] {
--bs-body-bg: #ffffff;
--bs-body-color: #212529;
}
// Dark mode colors
[data-bs-theme="dark"] {
--bs-body-bg: #1a1a2e;
--bs-body-color: #e1e1e1;
--bs-primary: #6ea8fe;
}tint-color($color, $weight)shade-color($color, $weight)shift-color($color, $weight)color-contrast($color)// Generate color scale
$primary-light: tint-color($primary, 40%);
$primary-dark: shade-color($primary, 20%);
// Auto-contrast text
.custom-badge {
background-color: $success;
color: color-contrast($success); // Returns #fff or #212529
}
// Hover states
.btn-custom:hover {
background-color: shift-color($brand, 15%);
}escape-svg()add()subtract()references/sass-functions-mixins.md$font-family-base: system-ui, -apple-system, sans-serif;
$font-family-monospace: SFMono-Regular, Menlo, monospace;
$font-size-base: 1rem;
$font-size-sm: $font-size-base * 0.875;
$font-size-lg: $font-size-base * 1.25;
$font-weight-normal: 400;
$font-weight-bold: 700;
$line-height-base: 1.5;
$headings-font-family: null; // Inherits $font-family-base
$headings-font-weight: 500;$spacer: 1rem;
$spacers: (
0: 0,
1: $spacer * 0.25, // 0.25rem
2: $spacer * 0.5, // 0.5rem
3: $spacer, // 1rem
4: $spacer * 1.5, // 1.5rem
5: $spacer * 3 // 3rem
);$border-radius: 0.375rem;
$border-radius-sm: 0.25rem;
$border-radius-lg: 0.5rem;
$border-radius-xl: 1rem;
$border-radius-xxl: 2rem;
$border-radius-pill: 50rem;$enable-caret: true;
$enable-rounded: true;
$enable-shadows: false;
$enable-gradients: false;
$enable-transitions: true;
$enable-reduced-motion: true;
$enable-smooth-scroll: true;
$enable-grid-classes: true;
$enable-container-classes: true;
$enable-negative-margins: false;
$enable-dark-mode: true;
$color-mode-type: data; // 'data' or 'media':focus$focus-ring-width: .25rem;
$focus-ring-opacity: .25;
$focus-ring-color: rgba($primary, $focus-ring-opacity);
$focus-ring-blur: 0;
$focus-ring-box-shadow: 0 0 $focus-ring-blur $focus-ring-width $focus-ring-color;// Global button variables
$btn-padding-y: 0.5rem;
$btn-padding-x: 1rem;
$btn-font-size: 1rem;
$btn-border-radius: $border-radius;
// Per-variant customization via CSS
.btn-primary {
--bs-btn-bg: #0074d9;
--bs-btn-border-color: #0074d9;
--bs-btn-hover-bg: #0063b8;
--bs-btn-hover-border-color: #005aa3;
--bs-btn-active-bg: #005aa3;
--bs-btn-active-border-color: #00518f;
}$card-spacer-y: 1rem;
$card-spacer-x: 1rem;
$card-border-width: 1px;
$card-border-radius: $border-radius;
$card-border-color: rgba(0, 0, 0, 0.125);
$card-bg: $white;
$card-cap-bg: rgba(0, 0, 0, 0.03);$input-padding-y: 0.375rem;
$input-padding-x: 0.75rem;
$input-font-size: 1rem;
$input-border-radius: $border-radius;
$input-border-color: $gray-400;
$input-focus-border-color: tint-color($primary, 50%);
$input-focus-box-shadow: 0 0 0 0.25rem rgba($primary, 0.25);<!-- Base class provides core styling -->
<button class="btn">Base button</button>
<!-- Modifier classes add variants -->
<button class="btn btn-primary">Primary</button>
<button class="btn btn-lg">Large</button>
<button class="btn btn-primary btn-lg">Primary Large</button>$theme-colors// How Bootstrap generates .alert-primary, .alert-danger, etc.
@each $state in map-keys($theme-colors) {
.alert-#{$state} {
--#{$prefix}alert-color: var(--#{$prefix}#{$state}-text-emphasis);
--#{$prefix}alert-bg: var(--#{$prefix}#{$state}-bg-subtle);
--#{$prefix}alert-border-color: var(--#{$prefix}#{$state}-border-subtle);
}
}$theme-colors// Base class
.callout {
padding: var(--bs-callout-padding, 1rem);
border-left: 4px solid var(--bs-callout-border-color, currentcolor);
background: var(--bs-callout-bg, transparent);
}
// Generate variants from theme colors
@each $state, $value in $theme-colors {
.callout-#{$state} {
--bs-callout-border-color: var(--bs-#{$state});
--bs-callout-bg: var(--bs-#{$state}-bg-subtle);
}
}.callout-primary.callout-danger.calloutreferences/sass-functions-mixins.mdbutton-variant().custom-component {
// Use Bootstrap's spacing
padding: map-get($spacers, 3);
margin-bottom: map-get($spacers, 4);
// Use Bootstrap's colors
background-color: var(--bs-body-bg);
color: var(--bs-body-color);
border: 1px solid var(--bs-border-color);
border-radius: var(--bs-border-radius);
// Use Bootstrap's shadows
@if $enable-shadows {
box-shadow: $box-shadow-sm;
}
// Responsive behavior
@include media-breakpoint-up(md) {
padding: map-get($spacers, 4);
}
}// Required core
@import "bootstrap/scss/functions";
@import "bootstrap/scss/variables";
@import "bootstrap/scss/variables-dark";
@import "bootstrap/scss/maps";
@import "bootstrap/scss/mixins";
@import "bootstrap/scss/root";
// Optional - import only what you use
@import "bootstrap/scss/reboot";
@import "bootstrap/scss/type";
@import "bootstrap/scss/containers";
@import "bootstrap/scss/grid";
@import "bootstrap/scss/buttons";examples/selective-imports.scss// Instead of importing everything
// import * as bootstrap from 'bootstrap';
// Import only what you need
import Modal from 'bootstrap/js/dist/modal';
import Dropdown from 'bootstrap/js/dist/dropdown';
import Collapse from 'bootstrap/js/dist/collapse';
// Initialize manually
const modal = new Modal('#myModal');// postcss.config.js
module.exports = {
plugins: [
require('@fullhuman/postcss-purgecss')({
content: ['./src/**/*.html', './src/**/*.js'],
// Safelist Bootstrap's dynamic classes
safelist: {
standard: [/^modal/, /^show/, /^fade/, /^collapse/, /^offcanvas/],
deep: [/^tooltip/, /^popover/, /^bs-/]
}
})
]
}showfadecollapsing# .browserslistrc
>= 0.5%
last 2 major versions
not dead
not Explorer <= 11bootstrap.min.cssbootstrap.cssbootstrap.bundle.min.jsbootstrap.bundle.js# nginx.conf
gzip on;
gzip_types text/css application/javascript;defer<!-- Critical CSS in head -->
<link rel="stylesheet" href="bootstrap.min.css">
<!-- Scripts at end of body with defer -->
<script src="bootstrap.bundle.min.js" defer></script>data:escape-svg()// Custom checkbox with local SVG instead of data: URI
$form-check-input-checked-bg-image: url("/assets/icons/check.svg");references/sass-variables.mdreferences/sass-functions-mixins.mdexamples/color-mode-toggle.htmlexamples/custom-theme-demo.html