首页 > 其他分享 >css05 CSS Pseudo-classes

css05 CSS Pseudo-classes

时间:2024-05-28 20:57:04浏览次数:21  
标签:elements css05 Pseudo element classes every child Selects first

https://www.w3schools.com/css/css_pseudo_classes.asp

 

What are Pseudo-classes?

A pseudo-class is used to define a special state of an element.

For example, it can be used to:

  • Style an element when a user mouses over it
  • Style visited and unvisited links differently
  • Style an element when it gets focus

 


Syntax

The syntax of pseudo-classes:

selector:pseudo-class {
  property: value;
}

Anchor Pseudo-classes

Links can be displayed in different ways:

Example

/* 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;
}

Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective! a:active MUST come after a:hover in the CSS definition in order to be effective! Pseudo-class names are not case-sensitive.


   

Pseudo-classes and HTML Classes

Pseudo-classes can be combined with HTML classes:

When you hover over the link in the example, it will change color:

Example

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

Hover on <div>

An example of using the :hover pseudo-class on a <div> element:

Example

div:hover {
  background-color: blue;
}

Simple Tooltip Hover

Hover over a <div> element to show a <p> element (like a tooltip):

Hover over me to show the <p> element.

Example

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

div:hover p {
  display: block;
}

CSS - The :first-child Pseudo-class

The :first-child pseudo-class matches a specified element that is the first child of another element.

Match the first <p> element

In the following example, the selector matches any <p> element that is the first child of any element:

Example

p:first-child {
  color: blue;
}

Match the first <i> element in all <p> elements

In the following example, the selector matches the first <i> element in all <p> elements:

Example

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

Match all <i> elements in all first child <p> elements

In the following example, the selector matches all <i> elements in <p> elements that are the first child of another element:

Example

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

CSS - The :lang Pseudo-class

The :lang pseudo-class allows you to define special rules for different languages.

In the example below, :lang defines the quotation marks for <q> elements with lang="no":

Example

<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>




All CSS Pseudo Classes

SelectorExampleExample 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

All CSS Pseudo Elements

SelectorExampleExample 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
::marker ::marker Selects the markers of list items
::selection p::selection Selects the portion of an element that is selected by a user

标签:elements,css05,Pseudo,element,classes,every,child,Selects,first
From: https://www.cnblogs.com/emanlee/p/18218830

相关文章

  • HTML 14 - CSS Classes
    InHTML,aclassisanattributethatcanbeappliedtooneormoreelementsandisusedtostyleandcategorizeelementsbasedoncommoncharacteristicsorpurpose.Classesallowsmultipleelementstosharethesamestylingrules.Byassigningthesamec......
  • python (63):dataclasses 简单示例
    dataclasses简单示例:importtransformersfromdataclassesimportdataclass,fieldimportargparse@dataclassclassPerson():age:int=field(default=10)Name:str=field(default="Tom")high:int=field(default=185,......
  • About After-school Classes.
    昨天语文大作文,今天英语作文。$\\$Nowadays,childrenalwayshavemanyafter-schoolclasses.MyparentsandIhavedifferentopinionsonthissituation.$\\$Myparentsbelieve,after-schoolclassescanhelpusfindgoodjobsinthefuture.Goodcompanies......
  • 【异常】FATAL ERROR in native method: JDWP loaded classes, jvmtiError=JVMTI_ERRO
    一、异常内容IDEA启动微服务之后,提示FATALERRORinnativemethod:JDWPloadedclasses,jvmtiError=JVMTI_ERROR_OUT_OF_MEMORY(110)FATALERRORinnativemethod:JDWPloadedclasses,jvmtiError=JVMTI_ERROR_OUT_OF_MEMORY(110) atsun.misc.Unsafe.defineAnonym......
  • Pointer-like classes像指针又像函数
    Pointer-likeclasses像指针又像函数智能指针概念:一个类做出来像类又像指针示例代码:#pragmaonce#ifndef__SHAREPOINTER__#define__SHAREPOINTER__​template<classT>classshared_ptr{public:shared_ptr(T*p):px(p){}T&operator*()const{return*px;}......
  • [SWPUCTF 2021 新生赛]PseudoProtocols
    [SWPUCTF2021新生赛]PseudoProtocols尝试直接访问hint.php,发现并没有效果联想到题目为PseudoProtocols(伪协议),尝试使用伪协议php://filter参数详解该协议的参数会在该协议路径上进行传递,多个参数都可以在一个路径上传递。具体参考如下:php://filter参数描述res......
  • [SWPUCTF 2021 新生赛]PseudoProtocols
    第三层的意思是:(file_get_contents($a,'r'))是一个函数调用,它尝试以读取模式打开$a参数指定的文件,并返回文件的内容。==='Iwantflag'是一个比较操作符,用于比较file_get_contents($a,'r')的结果与字符串"Iwantflag"是否完全相等。如果相等,则条件成立。因此,整......
  • Pseudo-Label伪标签
    1.Semi-SupervisedLearningSemi-SupervisedLearning(半监督学习)是监督学习和无监督学习的一种结合方法。半监督学习使用大量的未标记数据,以及同时使用标记数据,来进行模式识别工作。2.Pseudo-Label产生伪标签的步骤非常简单,可以用如下步骤概括:Step1:给定带标签数据和不带标......
  • Using classes exported from a DLL using LoadLibrary
    UsingclassesexportedfromaDLLusingLoadLibraryAnup.VRateme: 4.94/5(67votes)25Jan20056minread 368.5K    10.8K    129    41AnarticleonloadingaDLLexplicitlyusingLoadLibraryandusingthecla......
  • 无涯教程-Java - Singleton Classes函数
    Singleton的目的是控制对象的创建,将对象的数量限制为一个。由于只有一个Singleton实例,因此Singleton的任何实例字段在每个类中只会出现一次,就像static字段一样。单例通常控制对资源的访问,例如数据库连接或Socket。例如,如果您仅对数据库的一个连接拥有许可证,或者JDBC驱动......