CSS Pseudo-classes
Pseudo-classes ဆိုတာ ဘာလဲ။
ဒြပ်စင်တစ်ခု၏ အထူးအခြေအနေတစ်ခုကို သတ်မှတ်ရန် pseudo-class ကိုအသုံးပြုသည်။
ဥပမာအားဖြင့်၊ ၎င်းကိုအသုံးပြုနိုင်သည်-
- အသုံးပြုသူတစ်ဦးက ၎င်းကို မောက်စ်တင်သည့်အခါ အစိတ်အပိုင်းတစ်ခု ပုံစံဖန်တီးပါ။
- လည်ပတ်ခဲ့သည့်ပုံစံနှင့် မလည်ပတ်ရသေးသောလင့်ခ်များ မတူညီပါ။
- အာရုံစူးစိုက်မှုရလာသောအခါတွင် အစိတ်အပိုင်းတစ်ခုကို ပုံစံသွင်းပါ။
Mouse Over Me
အထားအသို
pseudo-classes ၏ syntax
selector:pseudo-class {
property: value;
}
Anchor Pseudo-classes
လင့်ခ်များကို ပုံစံအမျိုးမျိုးဖြင့် ပြသနိုင်သည်-
ဥပမာ
/* unvisited link */
a:link {
color: #FF0000;
}
/* visited
link */
a:visited {
color: #00FF00;
}
/* mouse over link */
a:hover {
color: #FF00FF;
}
/* selected link */
a:active {
color: #0000FF;
}
မှတ်ချက်- ထိရောက်စေရန်အတွက် CSS ၏ အဓိပ္ပါယ်ဖွင့်ဆိုချက်တွင် ပါ a:hover
ရှိရမည် a:link
။
ထိရောက်မှုရှိစေရန်အတွက် CSS ၏ အဓိပ္ပါယ်ဖွင့်ဆိုချက်တွင် ပါဝင်ရမည် ။
Pseudo-class အမည်များသည် စာလုံးအကြီးအသေး အာရုံမခံပါ။a:visited
a:active
a:hover
Pseudo-classes နှင့် HTML Classes များ
Pseudo-class များကို HTML အတန်းများနှင့် ပေါင်းစပ်နိုင်သည်။
ဥပမာရှိ လင့်ခ်ကို နှိပ်လိုက်သောအခါ၊ ၎င်းသည် အရောင်ပြောင်းသွားလိမ့်မည်-
ဥပမာ
a.highlight:hover {
color: #ff0000;
}
<div> ပေါ်တွင် ရွှေ့ပါ။
:hover
<div> ဒြပ်စင်တစ်ခုပေါ်တွင် pseudo-class ကိုအသုံးပြုခြင်း၏ဥပမာ တစ်ခု။
ဥပမာ
div:hover {
background-color: blue;
}
ရိုးရှင်းသော Tooltip ကို Hover
<p> ဒြပ်စင်ကိုပြသရန် (ကိရိယာအကြံပြုချက်ကဲ့သို့)
Tada! Here I am!
ဥပမာ
p {
display: none;
background-color: yellow;
padding: 20px;
}
div:hover p {
display: block;
}
CSS - :first-child Pseudo-class
pseudo-class သည် :first-child
အခြားဒြပ်စင်တစ်ခု၏ ပထမကလေးဖြစ်သည့် သတ်မှတ်ထားသော ဒြပ်စင်နှင့် ကိုက်ညီပါသည်။
ပထမ <p> ဒြပ်စင်နှင့် ကိုက်ညီပါ။
အောက်ဖော်ပြပါ ဥပမာတွင်၊ ရွေးချယ်သူသည် မည်သည့်ဒြပ်စင်၏ ပထမကလေးဖြစ်သည့် <p> ဒြပ်စင်နှင့် ကိုက်ညီသည်-
ဥပမာ
p:first-child
{
color: blue;
}
<p> ဒြပ်စင်အားလုံးရှိ ပထမ <i> ဒြပ်စင်ကို ယှဉ်ပါ။
အောက်ပါဥပမာတွင်၊ ရွေးချယ်သူသည် <p> ဒြပ်စင်များအားလုံးရှိ ပထမ <i> ဒြပ်စင်နှင့် ကိုက်ညီသည်-
ဥပမာ
p i:first-child
{
color: blue;
}
ပထမကလေး <p> ဒြပ်စင်များအားလုံးရှိ <i> ဒြပ်စင်အားလုံးကို ယှဉ်ပါ။
အောက်ဖော်ပြပါ ဥပမာတွင်၊ ရွေးချယ်သူသည် အခြားဒြပ်စင်တစ်ခု၏ ပထမကလေးဖြစ်သော <p> ဒြပ်စင်များရှိ <i> ဒြပ်စင်များအားလုံးနှင့် ကိုက်ညီသည်-
ဥပမာ
p:first-child i
{
color: blue;
}
CSS - :lang Pseudo-class
:lang
pseudo-class သည် သင့်အား မတူညီသောဘာသာစကားများအတွက် အထူးစည်းမျဉ်းများကို သတ်မှတ်ခွင့်ပြုသည် ။
အောက်ပါဥပမာတွင်၊ :lang
lang="no" ဖြင့် <q> ဒြပ်စင်များအတွက် ကိုးကားအမှတ်အသားများကို သတ်မှတ်သည်-
ဥပမာ
<html>
<head>
<style>
q:lang(no) {
quotes: "~" "~";
}
</style>
</head>
<body>
<p>Some text <q lang="no">A quote in a paragraph</q>
Some text.</p>
</body>
</html>
နောက်ထပ် ဥပမာများ
ဤဥပမာသည် ဟိုက်ပါလင့်ခ်များသို့ အခြားစတိုင်များကို ထည့်သွင်းနည်းကို သရုပ်ပြသည်။
ဤဥပမာသည် :focus pseudo-class ကိုအသုံးပြုပုံကို သရုပ်ပြသည်။
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 |
CSS Pseudo Elements အားလုံး
Selector | Example | Example description |
---|---|---|
::after | p::after | Insert content after every <p> element |
::before | p::before | Insert content before every <p> element |
::first-letter | p::first-letter | Selects the first letter of every <p> element |
::first-line | p::first-line | Selects the first line of every <p> element |
::selection | p::selection | Selects the portion of an element that is selected by a user |