Tag name တိုက်ရိုက် target လုပ်တယ် — page ထဲ အဲဒီ element အကုန်ကို apply ဖြစ်
p { color: red; }
h4 { color: blue; }
span { color: green; }
ဒီ paragraph က p selector ကြောင့် red ဖြစ်တယ်
Class တူတဲ့ element တွေ အကုန်ကို target — element တစ်ခုမှာ class တစ်ခုထက်မက ထည့်လို့ရ
.highlight { background: yellow; }
.bold-text { font-weight: bold; }
.big-text { font-size: 1.3em; }
<p class="highlight bold-text">Multiple classes!</p>
highlight class ထည့်ထားတယ်
bold-text class ထည့်ထားတယ်
big-text class ထည့်ထားတယ်
Classes 3 ခုလုံး ထည့်ထားတယ်!
Page ထဲ unique element တစ်ခုပဲ target — ID တစ်ခုကို element တစ်ခုပဲ သုံးသင့်
#special-title {
color: red;
font-size: 1.4em;
text-decoration: underline;
}
ပုံမှန် paragraph (class/id မပါ)
ID="special-title" — unique element!
ပုံမှန် paragraph နောက်တစ်ကြောင်း
div p → Descendant (div ထဲ မည်သည့် p မဆို) div > p → Child (div ရဲ့ direct child p ပဲ) h5 + p → Adjacent (h5 ရဲ့ ချက်ချင်းနောက် p) h5 ~ p → Sibling (h5 ရဲ့ နောက် sibling p အကုန်)
green — descendant
green — nested ရှိရင်လည်း
red bold — direct child
ပုံမှန် — nested မဟုတ်
ချက်ချင်းနောက် p → blue!
ဒုတိယ p → မပြောင်းဘူး
sibling p → yellow bg
ဒါလည်း sibling → yellow bg
Element ရဲ့ state ပေါ် မူတည်ပြီး style ချ — :hover, :focus, :nth-child, :first-child...
a:hover { background: blue; color: white; }
li:first-child { color: green; }
li:nth-child(2) { color: blue; }
li:nth-child(odd) { background: #f0f0f0; }
input:focus { border-color: blue; }
Element ရဲ့ တစ်ပိုင်းကို target — ::before, ::after, ::first-line, ::first-letter
p::first-line { color: blue; } /* ပထမဆုံး line */
p::first-letter { font-size: 2em; } /* ပထမဆုံး စာလုံး */
.box::before { content: "→ "; color: green; }
.box::after { content: " ←"; color: red; }
::first-line (blue):
ဒီ paragraph ရဲ့ ပထမဆုံး line ကသာ blue ဖြစ်မယ်
ဒုတိယ line ကတော့ ပုံမှန် color ဖြစ်နေမယ်
::before / ::after:
ဒီ text မှာ before နဲ့ after ပါတယ်
ဒါလည်း ထပ်တူ style ဖြစ်တယ်
::first-letter (Drop Cap):
ဒီ paragraph ရဲ့ ပထမဆုံး စာလုံးက ကြီးတယ် — drop cap effect လို့ ခေါ်တယ်
[type="text"] { border: 2px solid green; }
[type="email"] { border: 2px solid blue; }
[disabled] { opacity: 0.4; }
[href^="https"] { color: green; } /* starts with */
[href$=".pdf"] { color: red; } /* ends with */
[href*="vue"] { color: orange; } /* contains */
a[target="_blank"]::after { content: " ↗"; }
Conflict ဖြစ်ရင် specificity အမြင့်ဆုံးကအနိုင်ရတယ်
/* Specificity တွက်နည်း: (inline, id, class, element) */ p → (0, 0, 0, 1) → score: 1 .class → (0, 0, 1, 0) → score: 10 #id → (0, 1, 0, 0) → score: 100 style="" → (1, 0, 0, 0) → score: 1000 !important → nuclear option 💣
p { color: blue } → score: 1
.class { color: green } → score: 10
#id { color: red } → score: 100
ဒီ text က blue ဖြစ်ဖို့ p{color:blue} ရှိပေမဲ့ .class{green} ရှိပေမဲ့ — #id{red} ကအနိုင်ရတယ်!
Next: CSS Lesson 02 → Box Model