🏠 Home / Hub

💅 SCSS Lesson 01 — Variables & Basics

← Back to SCSS Menu  |  🏠 Hub

1. SCSS ဆိုတာ ဘာလဲ

SCSS (Sassy CSS) = CSS ကို extend လုပ်ထားတဲ့ preprocessor
Browser က SCSS တိုက်ရိုက် မဖတ်ဘူး → Compile ပြီး CSS ဖြစ်မှ browser ဖတ်မယ်

CSS → ရေးလို့ ရပေမယ့် variables, nesting, reuse မရ
SCSS → CSS လိုပဲ ရေးပြီး superpowers ပြောင်းပြောင်းတောက်ရ
/* Plain CSS */
:root {
  --primary: #e040fb;
  --padding: 16px;
}
.button {
  background: var(--primary);
  padding: var(--padding);
  border-radius: 6px;
}
.button:hover {
  background: #c000d0;
}
// SCSS
$primary: #e040fb;
$padding: 16px;

.button {
  background: $primary;
  padding: $padding;
  border-radius: 6px;

  &:hover {
    background: darken($primary, 15%);
  }
}

2. Variables — $variable_name

// Colors
$primary:    #e040fb;
$secondary:  #7b1fa2;
$success:    #28a745;
$danger:     #dc3545;
$text:       #333333;
$white:      #ffffff;

// Spacing
$padding-sm:  8px;
$padding-md:  16px;
$padding-lg:  24px;
$gap:         20px;

// Typography
$font-base:   'Arial', sans-serif;
$font-size:   16px;
$line-height: 1.6;

// Breakpoints
$mobile:  576px;
$tablet:  768px;
$desktop: 1200px;

// Usage
.card {
  padding: $padding-md;
  font-family: $font-base;
  color: $text;
}

3. Variable Scope

$color: red;   // global variable

.parent {
  $color: blue;   // local variable (overrides inside)
  color: $color;  // blue

  .child {
    color: $color;  // also blue (inherits from parent block)
  }
}

.other {
  color: $color;  // red (back to global)
}

// !default — only set if not already defined
$primary: #e040fb !default;  // won't overwrite if $primary exists
💡 Variables ကို file ထိပ်မှာ ထားပါ — _variables.scss file မှာ ခွဲထုတ်တာ best practice

4. SCSS Compile လုပ်နည်း

# 1. Install Sass (globally)
npm install -g sass

# 2. Single file compile
sass style.scss style.css

# 3. Watch mode (save တိုင်း auto compile)
sass --watch style.scss:style.css

# 4. Folder watch
sass --watch scss/:css/

# 5. Minified output (production)
sass --style=compressed style.scss style.min.css
VS Code Extension: "Live Sass Compiler" by Glenn Marks
→ Save လုပ်တာနဲ့ auto compile + browser refresh (setup command မပါ)

5. SCSS vs CSS vs LESS vs Stylus

FeatureCSSSCSSLESS
Variables--var (custom properties)$var@var
Nesting
Mixins
Compile needed
PopularityUniversal⭐ Most popular2nd
Framework useAllBootstrap 5, MaterialBootstrap 3
💡 Industry standard = SCSS — Bootstrap 5, Angular Material, Vuetify တွေ SCSS သုံး

← SCSS Menu  |  Next: SCSS 02 → Nesting →

📌 Study Checklist