Position Property

position គឺ​ជា​ property ប្រើ​សំរាប់​កំណត់​ពី​ស្ថានភាព​នៃ​ទីតាំង​របស់ element ។ តំលៃ​សំរាប់ property នេះ​មាន​ប្រាំ​គឺ static, relative, fixed, absolute , sticky

static ជា​ស្ថានភាព​នៃ​ទីតាំង​ធម្មតា​របស់​ element នៅ​ពេល​ដែល​ត្រូវ​បាន​បង្កើត​រួច​ហើយ​។ ពោល​គឺ​ការប្រើប្រាស់ property top, bottom, left, right គ្មាន​ឥទ្ធិពល​អ្វី​ទៅ​លើ element ដែល​មាន​ស្ថានភាព​ទីតាំង​ធម្មតា ឬ​ដែល​មាន property position មាន​តំលៃ​ជា static ។
<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Position Property</title>
    <style>
      div.static {
  		position: static;
  		border: 3px solid #73AD21;
	  }
    </style>
  </head>
  
  <body>
	

position: static;

An element with position: static; is not positioned in any special way; it is always positioned according to the normal flow of the page:

This div element has position: static;
</body> </html>

position: static;

An element with position: static; is not positioned in any special way; it is always positioned according to the normal flow of the page:

This div element has position: static;

ក៏ប៉ុន្តែ សំរាប់ element ដែល​មាន​ទីតាំង​ស្ថានភាព​ឬ position របស់​វា​មាន​តំលៃ​ជា relative វា​នឹង​រង​ឥទ្ធិពល​ពី​ top, bottom, left, right property ធៀប​ទៅ​នឹង​ element មេ​របស់​វា​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Position Property</title>
    <style>
      div.relative {
  		position: relative;
  		left: 30px;
  		border: 3px solid #73AD21;
	  }
    </style>
  </head>
  
  <body>
	

position: relative;

An element with position: relative; is positioned relative to its normal position:

This div element has position: relative;
</body> </html>

position: relative;

An element with position: relative; is positioned relative to its normal position:

This div element has position: relative;

ចំណែក​ឯ element ដែល​មាន​ postion មាន​តំលៃ​ជា fixed មាន​ទីតាំង​នឹង​ថ្កល់ ធៀប​ទៅ​នឹង​អេក្រង់​ទាំងមូល​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Position Property</title>
    <style>
      div.fixed {
  		position: fixed;
  		bottom: 0;
  		right: 0;
  		width: 300px;
  		border: 3px solid #73AD21;
	  }
    </style>
  </head>
  
  <body>
	

position: fixed;

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled:

This div element has position: fixed;
</body> </html>

position: fixed;

An element with position: fixed; is positioned relative to the viewport, which means it always stays in the same place even if the page is scrolled:

This div element has position: fixed;

ចំពោះ element ដែល​មាន​ position មាន​តំលៃ​ absolute ស្ថិត​នៅ​ក្នុង​ element មេ​ដែល​មាន​ position មាន​តំលៃ​ជា relative ឬ absolute មាន​ស្ថានភាព​ទីតាំង​របស់​វា​ត្រូវ​បាន​កំណត់​ឡើង​ដោយ​ធៀប​ទៅ​នឹង element មេ​ និង​ទទួល​រង​ឥទ្ធិពល​ពី top, bottom, left, right property។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Position Property</title>
    <style>
      div.relative {
  		position: relative;
  		width: 400px;
  		height: 200px;
  		border: 3px solid #73AD21;
	  } 

	  div.absolute {
  		position: absolute;
  		top: 80px;
  		right: 0;
  		width: 200px;
  		height: 100px;
  		border: 3px solid #73AD21;
	  }
    </style>
  </head>
  
  <body>
	

position: absolute;

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed):

This div element has position: relative;
This div element has position: absolute;
</body> </html>

position: absolute;

An element with position: absolute; is positioned relative to the nearest positioned ancestor (instead of positioned relative to the viewport, like fixed):

This div element has position: relative;
This div element has position: absolute;

តំលៃ absolute មាន​សារសំខាន់​នៅ​ពេល​ណា​ដែល​យើង​ចង់​អោយ​ element ផ្សេង​ៗ​អាច​មាន​ទីតាំង​ស្ថិត​នៅ​ជាន់​លើ​គ្នា​បាន​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Position Property</title>
    <style>
      img {
  		position: absolute;
  		left: 0px;
  		top: 0px;
  		z-index: -1;
	  }
    </style>
  </head>
  
  <body>
  	

This is a heading

</body> </html>

This is a heading


ចំពោះ element ដែល​មាន​ position មាន​តំលៃ​ជា sticky វិញ យើង​អាច​កំណត់​អោយ​វា​មាន​ស្ថានភាព​ទីតាំង​ជា​ element មាន position មាន​តលៃ​ជា fixed នៅ​ក្នុង​ចំងាយ​ណា​មួយ​ពី​ផ្នែក​ខាង​លើ​គេ​បង្អស់​របស់ element មេ។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Position Property</title>
    <style>
      div.sticky {
  		position: -webkit-sticky;
  		position: sticky;
  		top: 0;
  		padding: 5px;
  		background-color: #cae8ca;
  		border: 2px solid #4CAF50;
	  }
    </style>
  </head>
  
  <body>
	

Try to scroll inside this frame to understand how sticky positioning works.

Note: IE/Edge 15 and earlier versions do not support sticky position.

I am sticky!

In this example, the sticky element sticks to the top of the page (top: 0), when you reach its scroll position.

Scroll back up to remove the stickyness.

Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.

Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.

</body> </html>

Try to scroll inside this frame to understand how sticky positioning works.

Note: IE/Edge 15 and earlier versions do not support sticky position.

I am sticky!

In this example, the sticky element sticks to the top of the page (top: 0), when you reach its scroll position.

Scroll back up to remove the stickyness.

Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.

Some text to enable scrolling.. Lorem ipsum dolor sit amet, illum definitiones no quo, maluisset concludaturque et eum, altera fabulas ut quo. Atqui causae gloriatur ius te, id agam omnis evertitur eum. Affert laboramus repudiandae nec et. Inciderint efficiantur his ad. Eum no molestiae voluptatibus.