Skip to content

Space 间距

Space 用于在多个元素之间设置统一间距。VISTA B 直接使用 Element Plus 的 el-space,适合按钮组、操作区、标签列表、卡片列表等需要保持稳定间隔的场景。

基础用法

el-space 包裹多个元素,组件会自动给子元素添加统一间距。

卡片名称
列表项 1
列表项 2
列表项 3
列表项 4
卡片名称
列表项 1
列表项 2
列表项 3
列表项 4
卡片名称
列表项 1
列表项 2
列表项 3
列表项 4
vue
<el-space wrap>
  <div v-for="item in 3" :key="item" class="space-demo-card">
    <div class="space-demo-card__header">
      <span>卡片名称</span>
      <el-button type="primary" link>操作</el-button>
    </div>
    <div v-for="line in 4" :key="line">列表项 {{ line }}</div>
  </div>
</el-space>

垂直布局

使用 direction="vertical" 可以让元素纵向排列。

卡片名称
列表项 1
列表项 2
列表项 3
卡片名称
列表项 1
列表项 2
列表项 3
vue
<el-space direction="vertical">
  <el-button>保存</el-button>
  <el-button>预览</el-button>
</el-space>

控制间距

size 支持内置尺寸 smalldefaultlarge,对应 8px12px16px。默认间距为 small

vue
<el-space :size="size">
  <el-button type="primary">保存</el-button>
  <el-button>取消</el-button>
  <el-button>预览</el-button>
</el-space>

自定义 Size

当内置尺寸不满足设计要求时,可以传入数字,也可以传入 [horizontal, vertical] 分别控制横向与纵向间距。

20px
vue
<el-space wrap :size="[20, 16]">
  <el-button>操作 1</el-button>
  <el-button>操作 2</el-button>
</el-space>

自动换行

在水平布局下加上 wrap,内容宽度不足时会自动折行。

vue
<el-space wrap>
  <el-button v-for="item in 18" :key="item" text>
    Text button
  </el-button>
</el-space>

行间分隔符

spacer 可以传入文字、数字,也可以传入 VNode。常见用法是为操作项增加分隔符。

|
|
vue
<el-space spacer="|">
  <el-button>按钮 1</el-button>
  <el-button>按钮 2</el-button>
</el-space>

对齐方式

alignment 调整子元素在交叉轴上的对齐方式,可选值与 CSS align-items 一致。

center
文本
headerbody
flex-start
文本
headerbody
flex-end
文本
headerbody
vue
<el-space alignment="flex-start">
  <span>文本</span>
  <el-button>按钮</el-button>
</el-space>

填充容器

加上 fill 后,子元素会填充父容器。fill-ratio 可以控制填充比例,默认值为 100

direction:
fillRatio: 30
卡片 1
卡片 2
卡片 3
卡片 4
卡片 5
vue
<el-space fill wrap :fill-ratio="30" style="width: 100%">
  <div>卡片 1</div>
  <div>卡片 2</div>
  <div>卡片 3</div>
</el-space>

API

Space 属性

属性说明类型默认值
direction排列方向horizontal / verticalhorizontal
alignment对齐方式,对应 CSS align-itemsstringcenter
size间距大小small / default / large / number / [number, number]small
wrap是否自动折行booleanfalse
spacer间隔符string / number / VNode
fill子元素是否填充父容器booleanfalse
fill-ratio填充父容器的比例number100
class自定义类名string / object / array
style自定义样式string / object / array
prefix-clsspace-item 类名前缀string

Space 插槽

插槽说明
default需要添加间隔的元素

HOMEVISTA 设计规范