Select Element

តាម​ធម្មតា មុន​នឹង​ធ្វើ​ការរចនា​កែច្នៃ​ element ទាំងឡាយ​បាន យើង​ចាំបាច់ត្រូវ​ជ្រើសរើស​យក element ទាំងនោះ​ជាមុន​សិន​។ ហើយ​នៅ​ក្នុង​ភាសា CSS មាន​របៀប​ច្រើន​យ៉ាងណាស់ ក្នុង​ការជ្រើសរើស​យក element ទាំងនោះ​។ ជាកិច្ចចាប់ផ្តើម យើង​អាច​ប្រើ​របៀប​ជ្រើសរើស​យក element ទាំងឡាយ តាម​រយៈ tag របស់​វា ដោយ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Select Element</title>
    <style>
    	p{
    	  text-align: center;
  		  color: red;
		} 
    </style>
  </head>
  
  <body>
	

Every paragraph will be affected by the style.

Me too!

And me!

</body> </html>

Every paragraph will be affected by the style.

Me too!

And me!


តែ​បើ​យើង​ចង់​ជ្រើសរើស​យក​ element ណាមួយ​ដ៏​ជាក់លាក់​នោះ យើង​អាច​ធ្វើការ​ជ្រើស​រើស​យក element នោះ​តាម​attribute id តែ​មួយ​គត់​របស់​វា​បាន​ ដោយ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Select Element</title>
    <style>
    	#para1{
    	  text-align: center;
  		  color: red;
		} 
    </style>
  </head>
  
  <body>
	

Hello World!

This paragraph is not affected by the style.

</body> </html>

Hello World!

This paragraph is not affected by the style.


ដូច​គ្នា​ដែរ យើង​អាច​ជ្រើសរើស​យក element មួយ​ចំនួន តាមរយៈ attribute ដែល​ជា​ class របស់​វា ដោយ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Select Element</title>
    <style>
    	.center {
  		  text-align: center;
  		  color: red;
		}
    </style>
  </head>
  
  <body>
	

Red and center-aligned heading

Red and center-aligned paragraph.

</body> </html>

Red and center-aligned heading

Red and center-aligned paragraph.


ក្នុង​ករណី element មួយ​មាន attribute class មាន value លើស​ពី​មួយ ការកែច្នៃ​រចនា element នោះ អាច​ត្រូវ​ធ្វើ​ឡើង​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Select Element</title>
    <style>
    	p.center {
  		  text-align: center;
  		  color: red;
		}

		p.large {
  		  font-size: 300%;
		}
    </style>
  </head>
  
  <body>
	

This heading will not be affected

This paragraph will be red and center-aligned.

This paragraph will be red, center-aligned, and in a large font-size.

</body> </html>

This heading will not be affected

This paragraph will be red and center-aligned.

This paragraph will be red, center-aligned, and in a large font-size.


បើ​សិន​ជា​យើង​ជ្រើសរើស​យក element ទាំងអស់ ដែល​មាន​នៅ​ក្នុង​ទំព័រ HTML យើង​ត្រូវ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Select Element</title>
   <style>
	* {
  	  text-align: center;
  	  color: blue;
	}
	</style>
  </head>
  
  <body>
	

Hello world!

Every element on the page will be affected by the style.

Me too!

And me!

</body> </html>

Hello world!

Every element on the page will be affected by the style.

Me too!

And me!


យ៉ាងណាម៉ិញ ក្រៅ​ពី​ជ្រើសរើស​យក element តាម​រយៈ tag មួយ​ប្រភេទ id ឬ class ណាមួយ យើង​អាច​ប្រើប្រាស់ tag, id, class ចំរុះ​គ្នា​តែ​ម្តង ក្នង​ការជ្រើសរើស​យក element ជា​ច្រើន​មក​កែច្នៃ ដោយ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Select Element</title>
   <style>
	    h1, h2, p {
  	      text-align: center;
  	      color: red;
	    }
	</style>
  </head>
  
  <body>
	

Hello World!

Smaller heading!

This is a paragraph.

</body> </html>

Hello World!

Smaller heading!

This is a paragraph.