Multi-brand stylesheet generation helps you create different looks for multiple brands using one set of styles. It saves time and keeps your code organized.
Multi-brand stylesheet generation in SASS
$brands: ( brand1: ( primary-color: #ff0000, font-family: "Arial, sans-serif" ), brand2: ( primary-color: #0000ff, font-family: "Georgia, serif" ) ); @each $brand, $settings in $brands { .#{$brand} { --primary-color: #{map-get($settings, primary-color)}; font-family: #{map-get($settings, font-family)}; } }
Use $brands map to store brand-specific settings.
@each loop helps generate styles for each brand automatically.
$brands: ( redbrand: ( primary-color: #e63946, font-family: "Helvetica, sans-serif" ), bluebrand: ( primary-color: #1d3557, font-family: "Times New Roman, serif" ) ); @each $brand, $settings in $brands { .#{$brand} { color: map-get($settings, primary-color); font-family: map-get($settings, font-family); } }
$brands: ( brandA: ( primary-color: #2a9d8f ), brandB: ( primary-color: #e76f51 ) ); @each $brand, $settings in $brands { .#{$brand} { background-color: map-get($settings, primary-color); } }
This HTML file uses Sass to generate styles for two brands: Alpha and Beta. Each brand section has its own color and font style. The styles are applied using CSS custom properties and Sass maps with loops.
Note: Sass code must be compiled to CSS before it can be used in the browser. The Sass code shown in the original example should be placed in a separate .scss file and compiled to CSS, which is then linked or included in the HTML.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Multi-brand Stylesheet Example</title> <style> /* Sass code cannot be used directly inside <style> tags in HTML. It needs to be compiled to CSS first. */ </style> </head> <body> <section class="alpha"> <h1>Alpha Brand</h1> <p>This section uses Alpha brand colors and fonts.</p> </section> <section class="beta"> <h1>Beta Brand</h1> <p>This section uses Beta brand colors and fonts.</p> </section> </body> </html>
Remember to compile Sass to CSS before using it in the browser.
Use CSS custom properties for easier theme switching in runtime.
Keep brand variables organized in maps for easy updates.
Multi-brand stylesheets let you style many brands from one codebase.
Sass maps and loops help generate brand-specific CSS automatically.
Use CSS variables for flexible and maintainable brand styles.