Space间距 - 图1

Space 间距

设置组件之间的间距。

何时使用

避免组件紧贴在一起,拉开统一的空间。

  • 适合行内元素的水平间距。
  • 可以设置各种水平对齐方式。

    代码演示

Space间距 - 图2

基本用法

相邻组件水平间距。

  1. <template>
  2. <a-space>
  3. Space
  4. <a-button type="primary">Button</a-button>
  5. <a-upload>
  6. <a-button> <a-icon type="upload" /> Click to Upload </a-button>
  7. </a-upload>
  8. <a-popconfirm title="Are you sure delete this task?" ok-text="Yes" cancel-text="No">
  9. <a-button>Confirm</a-button>
  10. </a-popconfirm>
  11. </a-space>
  12. </template>
  13. <script>
  14. export default {};
  15. </script>

Space间距 - 图3

间距大小

间距预设大、中、小三种大小。
通过设置 sizelarge middle 分别把间距设为大、中间距。若不设置 size,则间距为小。

  1. <template>
  2. <div>
  3. <a-radio-group v-model="size">
  4. <a-radio value="small">Small</a-radio>
  5. <a-radio value="middle">Middle</a-radio>
  6. <a-radio value="large">Large</a-radio>
  7. </a-radio-group>
  8. <br />
  9. <br />
  10. <a-space :size="size">
  11. <a-button type="primary">Primary</a-button>
  12. <a-button>Default</a-button>
  13. <a-button type="dashed">Dashed</a-button>
  14. <a-button type="link">Link</a-button>
  15. </a-space>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. size: 'small',
  23. };
  24. },
  25. };
  26. </script>

Space间距 - 图4

自定义尺寸

自定义间距大小。

  1. <template>
  2. <div>
  3. <a-slider v-model="size" />
  4. <br />
  5. <br />
  6. <a-space :size="size">
  7. <a-button type="primary">Primary</a-button>
  8. <a-button>Default</a-button>
  9. <a-button type="dashed">Dashed</a-button>
  10. <a-button type="link">Link</a-button>
  11. </a-space>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. data() {
  17. return {
  18. size: 8,
  19. };
  20. },
  21. };
  22. </script>

Space间距 - 图5

垂直间距

相邻组件垂直间距。
可以设置 width: 100% 独占一行。

  1. <template>
  2. <a-space direction="vertical">
  3. <a-card title="Card" style="width: 300px;">
  4. <p>Card content</p>
  5. <p>Card content</p>
  6. </a-card>
  7. <a-card title="Card" style="width: 300px;">
  8. <p>Card content</p>
  9. <p>Card content</p>
  10. </a-card>
  11. </a-space>
  12. </template>
  13. <script>
  14. export default {};
  15. </script>

Space间距 - 图6

对齐

设置对齐模式。

  1. <template>
  2. <div class="space-align-container">
  3. <div class="space-align-block">
  4. <a-space align="center">
  5. center
  6. <a-button type="primary">Primary</a-button>
  7. <span class="mock-block">Block</span>
  8. </a-space>
  9. </div>
  10. <div class="space-align-block">
  11. <a-space align="start">
  12. start
  13. <a-button type="primary">Primary</a-button>
  14. <span class="mock-block">Block</span>
  15. </a-space>
  16. </div>
  17. <div class="space-align-block">
  18. <a-space align="end">
  19. end
  20. <a-button type="primary">Primary</a-button>
  21. <span class="mock-block">Block</span>
  22. </a-space>
  23. </div>
  24. <div class="space-align-block">
  25. <a-space align="baseline">
  26. baseline
  27. <a-button type="primary">Primary</a-button>
  28. <span class="mock-block">Block</span>
  29. </a-space>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. export default {};
  35. </script>
  36. <style scoped>
  37. .space-align-container {
  38. display: flex;
  39. align-item: flex-start;
  40. flex-wrap: wrap;
  41. }
  42. .space-align-block {
  43. margin: 8px 4px;
  44. border: 1px solid #40a9ff;
  45. padding: 4px;
  46. flex: none;
  47. }
  48. .space-align-block .mock-block {
  49. display: inline-block;
  50. padding: 32px 8px 16px;
  51. background: rgba(150, 150, 150, 0.2);
  52. }
  53. </style>

API

参数说明类型默认值版本
align对齐方式start | end |center |baseline-1.6.5
direction间距方向vertical | horizontalhorizontal1.6.5
size间距大小small | middle | large | numbersmall1.6.5