borders.mdx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. ---
  2. title: Borders
  3. summary: Use border utilities to quickly style the border and border-radius of an element. Great for images, buttons, or any other element.
  4. description: Style elements with border utilities.
  5. ---
  6. ## Border direction
  7. Borders can be applied to specific sides of an element using utility classes. This is particularly useful for styling individual sides of a box, such as highlighting the top border for emphasis or applying a separator between elements. Below are examples of how to set borders for each side of an element.
  8. ```html
  9. <div class="border">1</div>
  10. <div class="border-top">2</div>
  11. <div class="border-end">3</div>
  12. <div class="border-bottom">4</div>
  13. <div class="border-start">5</div>
  14. <div class="border-x">6</div>
  15. <div class="border-y">7</div>
  16. ```
  17. ```html example centered separated background="white"
  18. <div
  19. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border"
  20. >
  21. 1
  22. </div>
  23. <div
  24. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-top"
  25. >
  26. 2
  27. </div>
  28. <div
  29. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-end"
  30. >
  31. 3
  32. </div>
  33. <div
  34. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-bottom"
  35. >
  36. 4
  37. </div>
  38. <div
  39. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-start"
  40. >
  41. 5
  42. </div>
  43. <div
  44. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-x"
  45. >
  46. 6
  47. </div>
  48. <div
  49. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-y"
  50. >
  51. 7
  52. </div>
  53. ```
  54. ## Border size
  55. Border size utilities allow you to control the thickness of borders, providing flexibility to suit different design needs. You can add no border, a standard border, or a wide border for a more prominent effect. These classes are especially useful for creating visual hierarchy or highlighting specific elements.
  56. ```html
  57. <div class="border-0">1</div>
  58. <div class="border">2</div>
  59. <div class="border-wide">3</div>
  60. ```
  61. ```html example centered separated background="white"
  62. <div
  63. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-0"
  64. >
  65. 1
  66. </div>
  67. <div
  68. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border"
  69. >
  70. 2
  71. </div>
  72. <div
  73. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-wide"
  74. >
  75. 3
  76. </div>
  77. ```
  78. ## Remove border
  79. If you want to selectively remove borders from specific sides of an element, you can use border removal utilities. This feature simplifies styling tasks, such as creating a seamless connection between elements or achieving minimalistic designs.
  80. ```html
  81. <div class="border border-top-0">1</div>
  82. <div class="border border-end-0">2</div>
  83. <div class="border border-bottom-0">3</div>
  84. <div class="border border-start-0">4</div>
  85. <div class="border border-x-0">5</div>
  86. <div class="border border-y-0">6</div>
  87. ```
  88. ```html example centered separated background="white"
  89. <div
  90. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-top-0"
  91. >
  92. 1
  93. </div>
  94. <div
  95. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-end-0"
  96. >
  97. 2
  98. </div>
  99. <div
  100. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-bottom-0"
  101. >
  102. 3
  103. </div>
  104. <div
  105. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-start-0"
  106. >
  107. 4
  108. </div>
  109. <div
  110. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-x-0"
  111. >
  112. 5
  113. </div>
  114. <div
  115. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-y-0"
  116. >
  117. 6
  118. </div>
  119. ```
  120. ## Border color
  121. Customizing the border color helps to enhance the visual appeal and consistency of your design. With utility classes, you can easily apply specific colors to borders, allowing for greater flexibility in creating visually distinct sections.
  122. ```html
  123. <div class="border border-primary">1</div>
  124. <div class="border border-secondary">2</div>
  125. <div class="border border-success">3</div>
  126. <div class="border border-warning">4</div>
  127. <div class="border border-danger">5</div>
  128. <div class="border border-info">6</div>
  129. <div class="border border-dark">7</div>
  130. <div class="border border-light">8</div>
  131. ```
  132. ```html example centered separated background="white"
  133. <div
  134. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-primary"
  135. >
  136. 1
  137. </div>
  138. <div
  139. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-secondary"
  140. >
  141. 2
  142. </div>
  143. <div
  144. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-success"
  145. >
  146. 3
  147. </div>
  148. <div
  149. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-warning"
  150. >
  151. 4
  152. </div>
  153. <div
  154. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-danger"
  155. >
  156. 5
  157. </div>
  158. <div
  159. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-info"
  160. >
  161. 6
  162. </div>
  163. <div
  164. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-dark"
  165. >
  166. 7
  167. </div>
  168. <div
  169. class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-light"
  170. >
  171. 8
  172. </div>
  173. ```
  174. ## Border radius
  175. Adding border radius gives elements smooth, rounded edges, which can make designs feel more modern and approachable. You can choose from various levels of rounding, including full circles, using the available utility classes.
  176. ```html
  177. <div class="border rounded-0">1</div>
  178. <div class="border rounded">2</div>
  179. <div class="border rounded-1">3</div>
  180. <div class="border rounded-2">4</div>
  181. <div class="border rounded-3">5</div>
  182. <div class="border rounded-circle">6</div>
  183. ```
  184. ```html example centered separated background="white"
  185. <div
  186. class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-0"
  187. >
  188. 1
  189. </div>
  190. <div
  191. class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded"
  192. >
  193. 2
  194. </div>
  195. <div
  196. class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-1"
  197. >
  198. 3
  199. </div>
  200. <div
  201. class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-2"
  202. >
  203. 4
  204. </div>
  205. <div
  206. class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-3"
  207. >
  208. 5
  209. </div>
  210. <div
  211. class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-circle"
  212. >
  213. 6
  214. </div>
  215. ```
  216. ## Border opacity
  217. You can adjust the opacity of borders to create subtle visual effects or to blend elements seamlessly into the background. By using border opacity utilities, you can control the transparency of borders, allowing for more creative and visually appealing designs. To change the opacity of a border, add the `border-opacity-*` class to the element.
  218. ```html
  219. <div class="border border-success border-opacity-50">This is 50% opacity success border</div>
  220. ```
  221. ```html example
  222. <div class="border border-success p-2 mb-2">This is default success border</div>
  223. <div class="border border-success p-2 mb-2 border-opacity-75">
  224. This is 75% opacity success border
  225. </div>
  226. <div class="border border-success p-2 mb-2 border-opacity-50">
  227. This is 50% opacity success border
  228. </div>
  229. <div class="border border-success p-2 mb-2 border-opacity-25">
  230. This is 25% opacity success border
  231. </div>
  232. <div class="border border-success p-2 border-opacity-10">This is 10% opacity success border</div>
  233. ```