margins.mdx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. ---
  2. title: Margins
  3. summary: Use margin utilities to control the space between elements.
  4. description: Control the space between elements with margin utilities.
  5. ---
  6. Margin utilities allow you to control the space between elements, providing flexibility to suit different design needs. These utilities are especially useful for creating spacing between components or aligning them consistently. Below are examples of how to use margin utilities for various directions and sizes.
  7. ### Margin size
  8. In table below you can see the available margin sizes.
  9. Name|Value
  10. -|-
  11. 0|0
  12. 1|0.25rem
  13. 2|0.5rem
  14. 3|1rem
  15. 4|1.5rem
  16. 5|2rem
  17. 6|3rem
  18. 7|5rem
  19. 8|8rem
  20. ### Margin
  21. Use the `.m-*` utilities to control the margin of an element. Margin utilities are used to create consistent spacing around an element, ensuring that the layout is visually balanced.
  22. ```html example hide-code centered separated vertical
  23. <div class="d-flex">
  24. <div class="bg-purple-lt">
  25. <div class="px-3 py-2 m-0 bg-purple rounded text-white font-monospace">.m-0</div>
  26. </div>
  27. </div>
  28. <div class="d-flex">
  29. <div class="bg-purple-lt">
  30. <div class="px-3 py-2 m-4 bg-purple rounded text-white font-monospace">.m-4</div>
  31. </div>
  32. </div>
  33. <div class="d-flex">
  34. <div class="bg-purple-lt">
  35. <div class="px-3 py-2 m-8 bg-purple rounded text-white font-monospace">.m-8</div>
  36. </div>
  37. </div>
  38. ```
  39. ### Start margin
  40. Start margins control the spacing to the left of an element, helping to create consistent horizontal gaps between elements. Start margin class names are prefixed with `ms-`.
  41. ```html
  42. <div class="ms-4">...</div>
  43. ```
  44. ```html example hide-code centered separated vertical
  45. <div class="d-flex">
  46. <div class="bg-red-lt">
  47. <div class="px-3 py-2 ms-0 bg-red rounded text-white font-monospace">.ms-0</div>
  48. </div>
  49. </div>
  50. <div class="d-flex">
  51. <div class="bg-red-lt">
  52. <div class="px-3 py-2 ms-4 bg-red rounded text-white font-monospace">.ms-4</div>
  53. </div>
  54. </div>
  55. <div class="d-flex">
  56. <div class="bg-red-lt">
  57. <div class="px-3 py-2 ms-8 bg-red rounded text-white font-monospace">.ms-8</div>
  58. </div>
  59. </div>
  60. ```
  61. ### End margin
  62. End margins control the spacing on the right side of an element. These utilities are helpful for creating visual separation between elements that flow horizontally. End margin class names are prefixed with `me-`.
  63. ```html
  64. <div class="me-4">...</div>
  65. ```
  66. ```html example hide-code centered separated vertical
  67. <div class="d-flex">
  68. <div class="bg-orange-lt">
  69. <div class="px-3 py-2 ms-0 bg-orange rounded text-white font-monospace">.me-0</div>
  70. </div>
  71. </div>
  72. <div class="d-flex">
  73. <div class="bg-orange-lt">
  74. <div class="px-3 py-2 me-4 bg-orange rounded text-white font-monospace">.me-4</div>
  75. </div>
  76. </div>
  77. <div class="d-flex">
  78. <div class="bg-orange-lt">
  79. <div class="px-3 py-2 me-8 bg-orange rounded text-white font-monospace">.me-8</div>
  80. </div>
  81. </div>
  82. ```
  83. ### Top margin
  84. Top margins define the spacing above an element. This is useful for separating stacked components or creating vertical spacing between sections. Top margin class names are prefixed with `mt-`.
  85. ```html
  86. <div class="mt-4">...</div>
  87. ```
  88. ```html example hide-code centered separated vertical
  89. <div class="d-flex">
  90. <div class="bg-yellow-lt">
  91. <div class="px-3 py-2 mt-0 bg-yellow rounded text-white font-monospace">.mt-0</div>
  92. </div>
  93. </div>
  94. <div class="d-flex">
  95. <div class="bg-yellow-lt">
  96. <div class="px-3 py-2 mt-4 bg-yellow rounded text-white font-monospace">.mt-4</div>
  97. </div>
  98. </div>
  99. <div class="d-flex">
  100. <div class="bg-yellow-lt">
  101. <div class="px-3 py-2 mt-8 bg-yellow rounded text-white font-monospace">.mt-8</div>
  102. </div>
  103. </div>
  104. ```
  105. ### Bottom margin
  106. Bottom margins control the spacing below an element, helping to create consistent vertical gaps between stacked elements. Bottom margin class names are prefixed with `mb-`.
  107. ```html
  108. <div class="mb-4">...</div>
  109. ```
  110. ```html example hide-code centered separated vertical
  111. <div class="d-flex">
  112. <div class="bg-lime-lt">
  113. <div class="px-3 py-2 mb-0 bg-lime rounded text-white font-monospace">.mb-0</div>
  114. </div>
  115. </div>
  116. <div class="d-flex">
  117. <div class="bg-lime-lt">
  118. <div class="px-3 py-2 mb-4 bg-lime rounded text-white font-monospace">.mb-4</div>
  119. </div>
  120. </div>
  121. <div class="d-flex">
  122. <div class="bg-lime-lt">
  123. <div class="px-3 py-2 mb-8 bg-lime rounded text-white font-monospace">.mb-8</div>
  124. </div>
  125. </div>
  126. ```
  127. ### Horizontal margin
  128. Use the `mx-*` utilities to control the horizontal margin of an element. Horizontal margin utilities are used to create consistent spacing between elements that flow horizontally.
  129. ```html
  130. <div class="mx-4">...</div>
  131. ```
  132. ```html example hide-code centered separated vertical
  133. <div class="d-flex">
  134. <div class="bg-azure-lt">
  135. <div class="px-3 py-2 mx-0 bg-azure rounded text-white font-monospace">.mx-0</div>
  136. </div>
  137. </div>
  138. <div class="d-flex">
  139. <div class="bg-azure-lt">
  140. <div class="px-3 py-2 mx-4 bg-azure rounded text-white font-monospace">.mx-4</div>
  141. </div>
  142. </div>
  143. <div class="d-flex">
  144. <div class="bg-azure-lt">
  145. <div class="px-3 py-2 mx-8 bg-azure rounded text-white font-monospace">.mx-8</div>
  146. </div>
  147. </div>
  148. ```
  149. ### Vertical margin
  150. Use the `my-*` utilities to control the vertical margin of an element. Vertical margin utilities are used to create consistent spacing between elements that flow vertically.
  151. ```html
  152. <div class="my-4">...</div>
  153. ```
  154. ```html example hide-code centered separated vertical
  155. <div class="d-flex">
  156. <div class="bg-blue-lt">
  157. <div class="px-3 py-2 my-0 bg-blue rounded text-white font-monospace">.my-0</div>
  158. </div>
  159. </div>
  160. <div class="d-flex">
  161. <div class="bg-blue-lt">
  162. <div class="px-3 py-2 my-4 bg-blue rounded text-white font-monospace">.my-4</div>
  163. </div>
  164. </div>
  165. <div class="d-flex">
  166. <div class="bg-blue-lt">
  167. <div class="px-3 py-2 my-8 bg-blue rounded text-white font-monospace">.my-8</div>
  168. </div>
  169. </div>
  170. ```
  171. ## Horizontal centering
  172. Additionally, Tabler also includes an `.mx-auto` class for horizontally centering fixed-width block level content—that is, content that has `display: block` and a width set—by setting the horizontal margins to `auto`.
  173. ```html
  174. <div class="mx-auto">...</div>
  175. ```
  176. ```html example hide-code centered vertical
  177. <div class="bg-teal-lt w-100 d-flex">
  178. <div class="px-3 py-2 mx-auto bg-teal rounded text-white font-monospace">.mx-auto</div>
  179. </div>
  180. ```
  181. ## Gap
  182. Use the `.gap-*` utilities to control the space between elements in a grid layout. The gap utilities are used to create consistent spacing between grid items, ensuring that the layout is visually balanced.
  183. ```html
  184. <div class="d-grid gap-6">...</div>
  185. ```
  186. ```html example
  187. <div class="d-grid gap-6 bg-indigo-lt">
  188. <div class="px-3 py-2 bg-indigo text-white rounded">Grid item 1</div>
  189. <div class="px-3 py-2 bg-indigo text-white rounded">Grid item 2</div>
  190. <div class="px-3 py-2 bg-indigo text-white rounded">Grid item 3</div>
  191. </div>
  192. ```