CSS စံပမာ အပြားသတ္တု

What is a pseudo-class?

Pseudo-classes are used to define the special state of elements.

For example, it can be used for:

  • Set the style when the mouse hovers over the element
  • Set different styles for visited and unvisited links
  • Set the style of the element when it gains focus
Hover over me with the mouse

Syntax

pseudo-class syntax:

selector:pseudo-class {
  property: value;
}

Anchor pseudo-class

Links can be displayed in different ways:

实例

/* Unvisited link */
a:link {
  color: #FF0000;
}
/* Visited link */
a:visited {
  color: #00FF00;
}
/* Hover link */
a:hover {
  color: #FF00FF;
}
/* Selected link */
a:active {
  color: #0000FF;
}

亲自试一试

Note:a:hover it must be in the CSS definition a:link and a:visited only after that it can take effect!a:active it must be in the CSS definition a:hover only after that it can take effect! Pseudo-class name is not case-sensitive.

pseudo-class and CSS class

pseudo-class can be used with CSS class:

When you hover the mouse over the link in the example, it changes color:

实例

a.highlight:hover {
  color: #ff0000;
}

亲自试一试

hover on <div>

use on <div> element :hover pseudo-class instance:

实例

div:hover {
  background-color: blue;
}

亲自试一试

简单的工具提示悬停

把鼠标悬停到

元素以显示

元素(类似工具提示的效果):

悬停到我上面来显示

元素。

嘿嘿,我在这里!

实例

p {
  display: none;
  background-color: yellow;
  padding: 20px;
}
div:hover p {
  display: block;
}

亲自试一试

CSS - :first-child 伪类

:first-child 伪类与指定的元素匹配:该元素是另一个元素的第一个子元素。

匹配首个

元素

在下面的例子中,选择器匹配作为任何元素的第一个子元素的任何

元素:

实例

p:first-child {
  color: blue;
}

亲自试一试

匹配所有

元素中的首个 元素

在下面的例子中,选择器匹配所有

元素中的第一个 元素:

实例

p i:first-child {
  color: blue;
}

亲自试一试

匹配所有首个

元素中的所有 元素

在下面的例子中,选择器匹配作为另一个元素的第一个子元素的

元素中的所有 元素:

实例

p:first-child i {
  color: blue;
}

亲自试一试

CSS - :lang 伪类

:lang 伪类允许您为不同的语言定义特殊的规则。

在下面的例子中,:lang 为属性为 lang="en" 的 元素定义引号:

实例






Some text A quote in a paragraph Some text.

亲自试一试

更多实例

为超链接添加不同样式
本例演示如何向超链接添加其他样式。
:focus ကို အသုံးပြုပါလိမ့်。
ဤအမှတ်အသားတွင် :focus ပြောင်းလဲခြင်း ကို အသုံးပြုပါလိမ့်。

အားလုံးသော CSS ပြောင်းလဲခြင်း

ရွေးချယ်သူ အကျိုးသုံး အကျိုးသုံးအချက်
:active a:active လက်ဆုံးဖြတ်ခြင်းဆိုတာ ချိန်တွင် ရွေးချယ်ပါ。
:checked input:checked ရွေးချယ်ဖြစ်သော <input> အရာတွေကို。
:disabled input:disabled တားမြစ်ဖြစ်သော <input> အရာတွေကို ရွေးချယ်ပါ。
:empty p:empty ရွေးချယ်သော ငယ်ရွားသော <p> အရာတွေကို。
:enabled input:enabled အခွင့်ပြုထားသော အီးအီးအို အား ခွင့်ပြုထားသည်
:first-child p:first-child အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော အီးအီးအို အား အဖြစ် ဖြစ်သည့် အီးအီးအို အား ခွင့်ပြုထားသည်
:first-of-type p:first-of-type အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော အီးအီးအို အား အဖြစ် ဖြစ်သည့် အီးအီးအို အား ခွင့်ပြုထားသည်
:focus input:focus ပထမပေါက် အား ခွင့်ပြုထားသော အီးအီးအို အား ခွင့်ပြုထားသည်
:hover a:hover အပ်လှူရိုက် အား ဖြစ်သော လမ်းကြောင်း အား ခွင့်ပြုထားသည်
:in-range input:in-range အသုံးပြုထားသော အီးအီးအို အား အချက်အလက် ကြား ဖြစ်သော အီးအီးအို အား ခွင့်ပြုထားသည်
:invalid input:invalid မမှားဖြစ်သော အသုံးပြုထားသော အီးအီးအို အား ခွင့်ပြုထားသည်
:lang(language) p:lang(it) lang အကို "it" မှ စတင်သော အီးအီးအို အား ခွင့်ပြုထားသော အီးအီးအို
:last-child p:last-child အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော အီးအီးအို အား အဖြစ် ဖြစ်သည့် အီးအီးအို အား ခွင့်ပြုထားသည်
:last-of-type p:last-of-type အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော အီးအီးအို အား အဖြစ် ဖြစ်သည့် အီးအီးအို အား ခွင့်ပြုထားသည်
:link a:link မမှားဖြစ်သော လမ်းကြောင်း အား ခွင့်ပြုထားသည်
:not(selector) :not(p) အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော အီးအီးအို အား ကို ခွင့်ပြုထားသော အီးအီးအို
:nth-child(n) p:nth-child(2) အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော အဖြစ် ဖြစ်သည့် အီးအီးအို အား အစုအဝေး ပြား သော အီးအီးအို
:nth-last-child(n) p:nth-last-child(2) အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော အဖြစ် ဖြစ်သည့် အီးအီးအို အား အစုအဝေး ပြား သော အီးအီးအို
:nth-last-of-type(n) p:nth-last-of-type(2) အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော <p> အီးအီးအို အား အစုအဝေး ပြား သော အီးအီးအို
:nth-of-type(n) p:nth-of-type(2) အဖြစ် ဖြစ်သည့် အဖြစ် ရှိသော ပြင်ပတ်ယန်း အဖြစ် ရှိသော အပ် အီးအီးအို
:only-of-type p:only-of-type အဖြစ် ဖြစ်သည့် ပြင်ပတ်ယန်း အဖြစ် ရှိသော အပ် အီးအီးအို
:only-child p:only-child ပြင်ပတ်ယန်း ဖြစ်သည့် အဖြစ် ကို ခွင့်ပြုထားသော <p> အီးအီးအို
:optional input:optional 选择不带 "required" 属性的 元素。
:out-of-range input:out-of-range 选择值在指定范围之外的 元素。
:read-only input:read-only 选择指定了 "readonly" 属性的 元素。
:read-write input:read-write 选择不带 "readonly" 属性的 元素。
:required input:required 选择指定了 "required" 属性的 元素。
:root root 选择元素的根元素。
:target #news:target 选择当前活动的 #news 元素(单击包含该锚名称的 URL)。
:valid input:valid 选择所有具有有效值的 元素。
:visited a:visited ရှိ <a> လောင်းကို ရွေးချယ်ပါ

အခြေခံရွေးချယ်သူ အားလုံး

ရွေးချယ်သူ အကျိုးသုံး အကျိုးသုံးအချက်
::after p::after ရှိ <p> အစိတ်အပိုင်းအား အပြီးသို့ အသစ်အရေးအချက် ထည်သွင်းပါ
::before p::before ရှိ <p> အစိတ်အပိုင်းအား အသစ်အရေးအချက် ထည်သွင်းပါ
::first-letter p::first-letter ရှိ <p> အစိတ်အပိုင်းကို ရွေးချယ်ပါ
::first-line p::first-line ရှိ <p> အစိတ်အပိုင်းကို ရွေးချယ်ပါ
::selection p::selection အသုံးပြုသူ ရွေးချယ်သော အစိတ်အပိုင်းကို ရွေးချယ်ပါ