borders.mdx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border">1</div>
  19. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-top">2</div>
  20. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-end">3</div>
  21. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-bottom">4</div>
  22. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-start">5</div>
  23. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-x">6</div>
  24. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-y">7</div>
  25. ```
  26. ## Border size
  27. 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.
  28. ```html
  29. <div class="border-0">1</div>
  30. <div class="border">2</div>
  31. <div class="border-wide">3</div>
  32. ```
  33. ```html example centered separated background="white"
  34. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-0">1</div>
  35. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border">2</div>
  36. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border-wide">3</div>
  37. ```
  38. ## Remove border
  39. 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.
  40. ```html
  41. <div class="border border-top-0">1</div>
  42. <div class="border border-end-0">2</div>
  43. <div class="border border-bottom-0">3</div>
  44. <div class="border border-start-0">4</div>
  45. <div class="border border-x-0">5</div>
  46. <div class="border border-y-0">6</div>
  47. ```
  48. ```html example centered separated background="white"
  49. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-top-0">1</div>
  50. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-end-0">2</div>
  51. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-bottom-0">3</div>
  52. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-start-0">4</div>
  53. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-x-0">5</div>
  54. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-y-0">6</div>
  55. ```
  56. ## Border color
  57. 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.
  58. ```html
  59. <div class="border border-primary">1</div>
  60. <div class="border border-secondary">2</div>
  61. <div class="border border-success">3</div>
  62. <div class="border border-warning">4</div>
  63. <div class="border border-danger">5</div>
  64. <div class="border border-info">6</div>
  65. <div class="border border-dark">7</div>
  66. <div class="border border-light">8</div>
  67. ```
  68. ```html example centered separated background="white"
  69. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-primary">1</div>
  70. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-secondary">2</div>
  71. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-success">3</div>
  72. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-warning">4</div>
  73. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-danger">5</div>
  74. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-info">6</div>
  75. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-dark">7</div>
  76. <div class="d-flex align-items-center justify-content-center text-secondary w-5 h-5 bg-light border border-light">8</div>
  77. ```
  78. ## Border radius
  79. 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.
  80. ```html
  81. <div class="border rounded-0">1</div>
  82. <div class="border rounded">2</div>
  83. <div class="border rounded-1">3</div>
  84. <div class="border rounded-2">4</div>
  85. <div class="border rounded-3">5</div>
  86. <div class="border rounded-circle">6</div>
  87. ```
  88. ```html example centered separated background="white"
  89. <div class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-0">1</div>
  90. <div class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded">2</div>
  91. <div class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-1">3</div>
  92. <div class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-2">4</div>
  93. <div class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-3">5</div>
  94. <div class="d-flex align-items-center justify-content-center text-secondary w-6 h-6 bg-light border rounded-circle">6</div>
  95. ```
  96. ## Border opacity
  97. 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.
  98. ```html
  99. <div class="border border-success border-opacity-50">This is 50% opacity success border</div>
  100. ```
  101. ```html example
  102. <div class="border border-success p-2 mb-2">This is default success border</div>
  103. <div class="border border-success p-2 mb-2 border-opacity-75">This is 75% opacity success border</div>
  104. <div class="border border-success p-2 mb-2 border-opacity-50">This is 50% opacity success border</div>
  105. <div class="border border-success p-2 mb-2 border-opacity-25">This is 25% opacity success border</div>
  106. <div class="border border-success p-2 border-opacity-10">This is 10% opacity success border</div>
  107. ```