Attribute Selector

នៅ​ក្នុង​ភាសា CSS ការជ្រើសរើស​យក​ element មក​ធ្វើការ​កែច្នៃ​ទាំងឡាយ អាច​ត្រូវ​ធ្វើ​ឡើង​តាម​រយៈ​ attribute របស់​ element ទាំងនោះ​។ ពិនិត្យ​កម្មវិធី​ខាង​ក្រោម​នេះ​៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Attribute Selector</title>
    <style>
    	a[target] {
  		  background-color: yellow;
		}
    </style>
  </head>
  
  <body>
	

The links with a target attribute gets a yellow background:

w3schools.com disney.com wikipedia.org </body> </html>

The links with a target attribute gets a yellow background:

w3schools.com disney.com wikipedia.org

កាន់​តែ​ច្បាស់​ជាង​នេះ​ទៀត​នោះ យើង​អាច​ជ្រើសរើស​យក​ element ទាំងឡាយ​មក​ធ្វើការ​រចនា តាម​រយៈ attribute ជាប់​ជាមួយ​នឹង​តំលៃ​របស់​វា​មក​ជាមួយ​ផង​ដែរ​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Attribute Selector</title>
    <style>
    	a[target=_blank] {
  		  background-color: yellow;
		}
    </style>
  </head>
  
  <body>
	

The links with a target attribute gets a yellow background:

w3schools.com disney.com wikipedia.org </body> </html>

The links with a target attribute gets a yellow background:

w3schools.com disney.com wikipedia.org

ចពោះ​ការ​ជ្រើសរើស​យក element តាម​រយៈ attribute ដែល​មាន​ទំរង់​ជា [attribute~="value"] មាន​ន័យថា ជា​ការជ្រើសរើស​យក​ element ទាំងឡាយ​តាម​រយៈ attribute ណា​មួយ ដែល​មាន​តំលៃ​មាន​ពាក្យ​កំណត់​ណា​មួយ​នៅ​ក្នុង​នោះ​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Attribute Selector</title>
    <style>
    	[title~=web] {
  		  border: 5px solid yellow;
		}
    </style>
  </head>
  
  <body>
	

The links with a target attribute gets a yellow background:

w3schools.com disney.com wikipedia.org </body> </html>

The links with a target attribute gets a yellow background:

w3schools.com disney.com wikipedia.org

ចំពោះ​ការជ្រើសរើស​យក element ដែល​មាន​ទំរង​ជា [attribute|="value"] មានន័យថា គឹ​ជា​ការជ្រើសរើស​យក element ទាំងឡាយ​ណា តាម​រយៈ attribute ណាមួយ​ដែល​មាន​តំលៃ​ចាប់​ផ្តើម​ដោយ​ពាក្យ​ណាមួយ​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Attribute Selector</title>
    <style>
    	[class|=top] {
  		  background: yellow;
		}
    </style>
  </head>
  
  <body>
	

Welcome

Hello world!

Are you learning CSS?

</body> </html>

Welcome

Hello world!

Are you learning CSS?


ចំំពោះ​ការជ្រើសរើស​យក element ដែល​មាន​ទំរង់​ជា [attribute^="value"] មានន័យថា គឹ​ជា​ការជ្រើសរើស​យក element ទាំងឡាយ​ណា តាម​រយៈ attribute ណាមួយ​ដែល​មាន​តំលៃ​មាន​ពាក្យ​ណាមួយ​នៅ​ខាង​ដើម​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Attribute Selector</title>
    <style>
    	[class^=top] {
  		  background: yellow;
		}
    </style>
  </head>
  
  <body>
	

Welcome

Hello world!

Are you learning CSS?

</body> </html>

Welcome

Hello world!

Are you learning CSS?


ចំពោះ​ការជ្រើសរើស​យក​ element មាន​ទំរង់​ជា [attribute$="value"] មានន័យថា គឹ​ជា​ការជ្រើសរើស​យក element ទាំងឡាយ​ណា តាម​រយៈ attribute ណាមួយ​ដែល​មាន​តំលៃ​មាន​ពាក្យ​ណាមួយ​នៅ​ខាង​ចុង​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Attribute Selector</title>
    <style>
    	[class$="test"] {
  		  background: yellow;
		}
    </style>
  </head>
  
  <body>
	
The first div element.
The second div element.
The third div element.

This is some text in a paragraph.

</body> </html>
The first div element.
The second div element.
The third div element.

This is some text in a paragraph.


ចំពោះ​ការជ្រើសរើស​យក​ element មាន​ទំរង់​ជា [attribute*="value"] មានន័យថា គឹ​ជា​ការជ្រើសរើស​យក element ទាំងឡាយ​ណា តាម​រយៈ attribute ណាមួយ​ដែល​មាន​តំលៃ​មាន​ពាក្យ​ណាមួយ​នៅ​ក្នុង​នោះ​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Attribute Selector</title>
    <style>
    	[class*="te"] {
  		  background: yellow;
		}
    </style>
  </head>
  
  <body>
	
The first div element.
The second div element.
The third div element.

This is some text in a paragraph.

</body> </html>
The first div element.
The second div element.
The third div element.

This is some text in a paragraph.