CSS Pseudo-ဒြပ်စင်များ
Pseudo-Elements တွေက ဘာတွေလဲ။
CSS pseudo-ဒြပ်စင်ကို ဒြပ်စင်တစ်ခု၏ သတ်မှတ်ထားသော အစိတ်အပိုင်းများကို ပုံစံချရန် အသုံးပြုသည်။
ဥပမာအားဖြင့်၊ ၎င်းကိုအသုံးပြုနိုင်သည်-
- ဒြပ်စင်တစ်ခု၏ ပထမအက္ခရာ သို့မဟုတ် စာကြောင်းကို ပုံစံထုတ်ပါ။
- ဒြပ်စင်တစ်ခု၏ အကြောင်းအရာ ရှေ့ သို့မဟုတ် နောက်တွင် အကြောင်းအရာကို ထည့်သွင်းပါ။
အထားအသို
pseudo-ဒြပ်စင်များ၏ syntax-
selector::pseudo-element {
property: value;
}
::ပထမလိုင်း Pseudo-ဒြပ်စင်
::first-line
pseudo-ဒြပ်စင်ကို စာသားတစ်ခု၏ ပထမစာကြောင်းသို့ အထူးစတိုင်လ်တစ်ခုထည့်ရန် အသုံးပြုသည် ။
အောက်ပါဥပမာသည် <p> ဒြပ်စင်များအားလုံးတွင် စာသား၏ပထမစာကြောင်းကို ဖော်မတ်ပေးသည်-
ဥပမာ
p::first-line
{
color: #ff0000;
font-variant: small-caps;
}
မှတ်ချက်- pseudo- ::first-line
ဒြပ်စင်ကို ပိတ်ဆို့အဆင့်ဒြပ်စင်များတွင်သာ အသုံးပြုနိုင်သည်။
အောက်ပါဂုဏ်သတ္တိများသည် ::first-line
pseudo-ဒြပ်စင်နှင့်သက်ဆိုင်သည်-
- ဖောင့်ဂုဏ်သတ္တိများ
- အရောင်ဂုဏ်သတ္တိများ
- နောက်ခံဂုဏ်သတ္တိများ
- စကားလုံးအကွာအဝေး
- စာလုံးအကွာအဝေး
- စာသားအလှဆင်
- ဒေါင်လိုက် ညှိခြင်း။
- စာသားအသွင်ပြောင်း
- မျဉ်းအမြင့်
- ရှင်းလင်းသော
double colon သင်္ကေတကို သတိပြုပါ - ::first-line
နှင့် ဆန့်ကျင်ဘက်
:first-line
တွင် double colon သည် CSS3 ရှိ pseudo-ဒြပ်စင်များအတွက် single-colon သင်္ကေတကို အစားထိုးခဲ့သည်။ ၎င်းသည် pseudo-class
နှင့် pseudo-ဒြပ်စင်များ အကြားခွဲခြားရန် W3C မှကြိုးပမ်းမှု ဖြစ်သည်။
single-colon syntax ကို CSS2 နှင့် CSS1 တွင် pseudo-classes နှင့် pseudo-elements နှစ်ခုလုံးအတွက် အသုံးပြုခဲ့သည်။
နောက်ပြန်လိုက်ဖက်ညီမှုအတွက်၊ single-colon syntax ကို CSS2 နှင့် CSS1 pseudo-elements အတွက် လက်ခံနိုင်သည် ။
::ပထမစာလုံး Pseudo-ဒြပ်စင်
::first-letter
pseudo-element ကို စာသားတစ်ခု၏ ပထမအက္ခရာသို့ အထူးစတိုင်လ်တစ်ခုထည့်ရန် အသုံးပြုသည် ။
အောက်ပါဥပမာသည် <p> ဒြပ်စင်များအားလုံးတွင် စာသား၏ပထမစာလုံးကို ဖော်မတ်ပေးသည်-
ဥပမာ
p::first-letter
{
color: #ff0000;
font-size: xx-large;
}
မှတ်ချက်- pseudo- ::first-letter
ဒြပ်စင်ကို ပိတ်ဆို့အဆင့်ဒြပ်စင်များတွင်သာ အသုံးပြုနိုင်သည်။
အောက်ပါဂုဏ်သတ္တိများသည် ::ပထမစာလုံး pseudo- ဒြပ်စင်နှင့် သက်ဆိုင်သည်-
- ဖောင့်ဂုဏ်သတ္တိများ
- အရောင်ဂုဏ်သတ္တိများ
- နောက်ခံဂုဏ်သတ္တိများ
- အနားသတ်ဂုဏ်သတ္တိများ
- padding ဂုဏ်သတ္တိများ
- နယ်စပ်ဂုဏ်သတ္တိများ
- စာသားအလှဆင်
- vertical-align ("float" သည် "none" ရှိမှသာ)
- စာသားအသွင်ပြောင်း
- မျဉ်းအမြင့်
- မျှော
- ရှင်းလင်းသော
Pseudo-ဒြပ်စင်များနှင့် HTML အတန်းများ
Pseudo-ဒြပ်စင်များကို HTML အတန်းများနှင့်ပေါင်းစပ်နိုင်သည်။
ဥပမာ
p.intro::first-letter {
color: #ff0000;
font-size: 200%;
}
အထက်ဖော်ပြပါ ဥပမာသည် အနီရောင်နှင့် ပိုကြီးသော အရွယ်အစားဖြင့် class="intro" ဖြင့် စာပိုဒ်များ၏ ပထမအက္ခရာကို ပြသပါမည်။
Pseudo-ဒြပ်စင်များစွာ
pseudo-ဒြပ်စင်များစွာကိုလည်း ပေါင်းစပ်နိုင်သည်။
အောက်ပါဥပမာတွင်၊ စာပိုဒ်တစ်ခု၏ပထမစာလုံးသည် xx-ကြီးမားသောဖောင့်အရွယ်အစားဖြင့်အနီရောင်ဖြစ်လိမ့်မည်။ ပထမစာကြောင်း၏ကျန်သည် အပြာရောင်ဖြစ်ပြီး စာလုံးသေးလေးဖြင့် ရေးပါမည်။ ကျန်စာပိုဒ်သည် မူရင်းဖောင့်အရွယ်အစားနှင့် အရောင်ဖြစ်လိမ့်မည်-
ဥပမာ
p::first-letter
{
color: #ff0000;
font-size: xx-large;
}
p::first-line
{
color: #0000ff;
font-variant: small-caps;
}
CSS - Pseudo-element မတိုင်ခင် ::
ဒြပ် စင် ::before
တစ်ခု၏အကြောင်းအရာမပါဝင်မီ အကြောင်းအရာအချို့ကို ထည့်သွင်းရန် pseudo-ဒြပ်စင်ကို အသုံးပြုနိုင်သည်။
အောက်ဖော်ပြပါ ဥပမာသည် <h1> ဒြပ်စင်တစ်ခုစီ၏ အကြောင်းအရာရှေ့တွင် ပုံတစ်ပုံကို ထည့်သွင်းသည်-
ဥပမာ
h1::before
{
content: url(smiley.gif);
}
CSS - ::after Pseudo-element
ဒြပ် စင် ::after
တစ်ခု၏အကြောင်းအရာပြီးနောက် အကြောင်းအရာအချို့ကို ထည့်သွင်းရန် pseudo-ဒြပ်စင်ကို အသုံးပြုနိုင်သည်။
အောက်ဖော်ပြပါ ဥပမာသည် <h1> ဒြပ်စင်တစ်ခုစီ၏ အကြောင်းအရာပြီးနောက် ပုံတစ်ခု ထည့်သွင်းသည်-
ဥပမာ
h1::after
{
content: url(smiley.gif);
}
CSS - :: အမှတ်အသား Pseudo-ဒြပ်စင်
::marker
pseudo-ဒြပ်စင်သည် စာရင်းအရာများ၏ အမှတ်အသားများကို ရွေးချယ်သည် ။
အောက်ဖော်ပြပါ ဥပမာသည် စာရင်းအကြောင်းအရာများ၏ အမှတ်အသားများကို ပုံစံပြသည်-
ဥပမာ
::marker {
color: red;
font-size: 23px;
}
CSS - ::selection Pseudo-element
::selection
pseudo-ဒြပ်စင်သည် အသုံးပြုသူမှ ရွေးချယ်ထားသော ဒြပ်စင်၏ အစိတ်အပိုင်းနှင့် ကိုက်ညီပါသည် ။
အောက်ပါ CSS ဂုဏ်သတ္တိများကို ::selection
:
color
,
background
, cursor
, နှင့် outline
.
အောက်ပါဥပမာသည် ရွေးချယ်ထားသောစာသားကို အဝါရောင်နောက်ခံတွင် အနီရောင်ဖြစ်စေသည်-
ဥပမာ
::selection {
color: red;
background: yellow;
}
CSS Pseudo Elements အားလုံး
Selector | Example | Example description |
---|---|---|
::after | p::after | Insert something after the content of each <p> element |
::before | p::before | Insert something before the content of each <p> element |
::first-letter | p::first-letter | Selects the first letter of each <p> element |
::first-line | p::first-line | Selects the first line of each <p> element |
::marker | ::marker | Selects the markers of list items |
::selection | p::selection | Selects the portion of an element that is selected by a user |
CSS Pseudo Classes အားလုံး
Selector | Example | Example description |
---|---|---|
:active | a:active | Selects the active link |
:checked | input:checked | Selects every checked <input> element |
:disabled | input:disabled | Selects every disabled <input> element |
:empty | p:empty | Selects every <p> element that has no children |
:enabled | input:enabled | Selects every enabled <input> element |
:first-child | p:first-child | Selects every <p> elements that is the first child of its parent |
:first-of-type | p:first-of-type | Selects every <p> element that is the first <p> element of its parent |
:focus | input:focus | Selects the <input> element that has focus |
:hover | a:hover | Selects links on mouse over |
:in-range | input:in-range | Selects <input> elements with a value within a specified range |
:invalid | input:invalid | Selects all <input> elements with an invalid value |
:lang(language) | p:lang(it) | Selects every <p> element with a lang attribute value starting with "it" |
:last-child | p:last-child | Selects every <p> elements that is the last child of its parent |
:last-of-type | p:last-of-type | Selects every <p> element that is the last <p> element of its parent |
:link | a:link | Selects all unvisited links |
:not(selector) | :not(p) | Selects every element that is not a <p> element |
:nth-child(n) | p:nth-child(2) | Selects every <p> element that is the second child of its parent |
:nth-last-child(n) | p:nth-last-child(2) | Selects every <p> element that is the second child of its parent, counting from the last child |
:nth-last-of-type(n) | p:nth-last-of-type(2) | Selects every <p> element that is the second <p> element of its parent, counting from the last child |
:nth-of-type(n) | p:nth-of-type(2) | Selects every <p> element that is the second <p> element of its parent |
:only-of-type | p:only-of-type | Selects every <p> element that is the only <p> element of its parent |
:only-child | p:only-child | Selects every <p> element that is the only child of its parent |
:optional | input:optional | Selects <input> elements with no "required" attribute |
:out-of-range | input:out-of-range | Selects <input> elements with a value outside a specified range |
:read-only | input:read-only | Selects <input> elements with a "readonly" attribute specified |
:read-write | input:read-write | Selects <input> elements with no "readonly" attribute |
:required | input:required | Selects <input> elements with a "required" attribute specified |
:root | root | Selects the document's root element |
:target | #news:target | Selects the current active #news element (clicked on a URL containing that anchor name) |
:valid | input:valid | Selects all <input> elements with a valid value |
:visited | a:visited | Selects all visited links |