Margin Property

បើ​សិន​ជា​យើង​ចង់​អោយ​មាន​គំលាត​រវាង element ណា​មួយ ជាមួយ​នឹង element ដទៃ​ទៀត យើង​ត្រូវ​ប្រើប្រាស់ property margin ដែល​ចែក​ចេញ​ជា property មួយ​ចំនួន​ទៀត មាន​ដូចជា margin-top, margin-bottom, margin-right, margin-left

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Margin Property</title>
    <style>
      div {
  		border: 1px solid black;
  		margin-top: 100px;
  		margin-bottom: 100px;
  		margin-right: 150px;
  		margin-left: 80px;
  		background-color: lightblue;
	  }
    </style>
  </head>
  
  <body>
	

Using individual margin properties

This div element has a top margin of 100px, a right margin of 150px, a bottom margin of 100px, and a left margin of 80px.
</body> </html>

Using individual margin properties

This div element has a top margin of 100px, a right margin of 150px, a bottom margin of 100px, and a left margin of 80px.

ជារួម នៅ​ក្នុង​ការអនុវត្ត យើង​អាច​ប្រើប្រាស់​តែ property margin តែ​មួយ​ក្នុង​កំណត់​គំលាត​នៅ​គ្រប់​ជ្រុង​ទាំងអស់​របស់​ element ទាំងឡាយ​ ដោយ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Margin Property</title>
    <style>
      div {
  		border: 1px solid black;
  		margin: 25px 50px 75px 100px;
  		background-color: lightblue;
	  }
    </style>
  </head>
  
  <body>
	

The margin shorthand property - 4 values

This div element has a top margin of 25px, a right margin of 50px, a bottom margin of 75px, and a left margin of 100px.
<hr/> </body> </html>

The margin shorthand property - 4 values

This div element has a top margin of 25px, a right margin of 50px, a bottom margin of 75px, and a left margin of 100px.


យ៉ាងណាម៉ិញ បើ​សិន​ចង់​កំណត់​គំលាត​រវាង​ជ្រុង​ខាង​លើ ជ្រុង​ខាង​ស្តាំ​និង​ឆ្វេង និង​ជ្រុង​ខាង​ក្រោម​ យើង​ត្រូវ​ធ្វើ​ដូច​ខាង​ក្រោម​នេះ៖

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Margin Property</title>
    <style>
      div {
  		border: 1px solid black;
  		margin: 25px 50px 75px;
  		background-color: lightblue;
	  }
    </style>
  </head>
  
  <body>
	

The margin shorthand property - 3 values

This div element has a top margin of 25px, a right and left margin of 50px, and a bottom margin of 75px.
<hr/> </body> </html>

The margin shorthand property - 3 values

This div element has a top margin of 25px, a right and left margin of 50px, and a bottom margin of 75px.


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

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Margin Property</title>
    <style>
      div {
  		border: 1px solid black;
  		margin: 25px 50px;
  		background-color: lightblue;
	  }
    </style>
  </head>
  
  <body>
	

The margin shorthand property - 2 values

This div element has a top and bottom margin of 25px, and a right and left margin of 50px.
<hr/> </body> </html>

The margin shorthand property - 2 values

This div element has a top and bottom margin of 25px, and a right and left margin of 50px.


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

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Margin Property</title>
    <style>
      div {
  		border: 1px solid black;
  		margin: 25px;
  		background-color: lightblue;
	  }
    </style>
  </head>
  
  <body>
	

The margin shorthand property - 1 value

This div element has a top, bottom, left, and right margin of 25px.
<hr/> </body> </html>

The margin shorthand property - 1 value

This div element has a top, bottom, left, and right margin of 25px.


លើស​ពី​នេះ​ទៀត ក្នុង​ករណី​ដែល element មាន​ប្រវែង​កំណត់​ណា​មួយ យើង​អាច​កំណត់តំលៃ​របស់ property margin ​ជា auto បាន។ ក្នុង​ករណី​នេះ element នឹងត្រូវ​ស្ថិត​ចំ​កណ្តាល element មេ​របស់​វា​។

<!DOCTYPE html>
<html>
  <head>
  	<meta charset="UTF-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  	<title>Margin Property</title>
    <style>
       div {
  		width:300px;
  		margin: auto;
  		border: 1px solid red;
	   }
    </style>
  </head>
  
  <body>
	

Use of margin:auto

You can set the margin property to auto to horizontally center the element within its container. The element will then take up the specified width, and the remaining space will be split equally between the left and right margins:

This div will be horizontally centered because it has margin: auto;
</body> </html>

Use of margin:auto

You can set the margin property to auto to horizontally center the element within its container. The element will then take up the specified width, and the remaining space will be split equally between the left and right margins:

This div will be horizontally centered because it has margin: auto;