CSS Pseudo-class

Pseudo-class ត្រូវ​ប្រើប្រាស់​សំរាប់​កំណត់​សភាពលក្ខណៈ​របស់​ element ទាំងឡាយ ស្ថិត​នៅ​ក្នុង​ស្ថានភាព​ណា​មួយ មាន​ដូចជា​ស្ថិត​ស្ថានភាព​ដែល mouse ស្ថិត​នៅ​ពី​លើ ស្ថានភាព​របស់ link នៅ​ពេល​ត្រូវ​ចុច និង​ស្ថានភាព​នៅ​ពេល​ដែល​ element focus ជាដើម​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>CSS Pseudo-class</title>
    <style>
      /* unvisited link */
	  a:link {
  		color: red;
	  }

	  /* visited link */
		a:visited {
  		color: green;
	  }

	  /* mouse over link */
	  a:hover {
  		color: hotpink;
	  }

	  /* selected link */
	  a:active {
  		color: blue;
	  }
    </style>
  </head>
  
  <body>
	

This is a link

Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective.

Note: a:active MUST come after a:hover in the CSS definition in order to be effective.

</body> </html>

This is a link

Note: a:hover MUST come after a:link and a:visited in the CSS definition in order to be effective.

Note: a:active MUST come after a:hover in the CSS definition in order to be effective.


យើង​អាច​ប្រើប្រាស់ pseudo-class ក្នុង​ការបង្កើត tooltip បាន ដោយ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>CSS Pseudo-class</title>
    <style>
      p {
  		display: none;
  		background-color: yellow;
  		padding: 20px;
	  }

	  div:hover p {
  		display: block;
	  }
    </style>
  </head>
  
  <body>
	
Hover over me to show the p element

Tada! Here I am!

</body> </html>
Hover over me to show the p element

Tada! Here I am!


:first-child ត្រូវ​គេ​យក​ទៅ​ប្រើប្រាស់​សំរាប់​ជ្រើសរើស​យក​element ណា​មួយ​ដែល​ជា first child នៃ element ណា​មួយ​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>CSS Pseudo-class</title>
    <style>
      p:first-child {
  		color: blue;
	  } 
    </style>
  </head>
  
  <body>
	

This is some text.

This is some text.

Note: For :first-child to work in IE8 and earlier, a DOCTYPE must be declared.

</body> </html>

This is some text.

This is some text.

Note: For :first-child to work in IE8 and earlier, a DOCTYPE must be declared.