Grid 栅格
24 栅格系统,基于 Row / Col 组织页面比例、间距、偏移和响应式布局。
基础用法
CfRow / CfCol 是 24 栅格系统:一行被划分为 24 份,span=6 占 25%,span=8 占 33.33%,span=12 占 50%。gutter 控制列间距与行间距,offset 控制左侧留白。
背景
100%
25%
25% + offset 6
33.33%
33.33% + offset 8
50%
66.66%
xs=24 / md=12 / lg=8
响应式断点
gutter=[12, 12]
<script setup lang="ts">
import { CfCol, CfRow } from '@chufix-design/vue';
</script>
<template>
<div class="grid-demo">
<section class="grid-concept" aria-label="24 栅格比例示意">
<div class="grid-guide" aria-hidden="true"></div>
<CfRow :gutter="[8, 8]">
<CfCol :span="24"><div class="grid-block grid-block--solid">100%</div></CfCol>
<CfCol :span="6"><div class="grid-block">25%</div></CfCol>
<CfCol :span="6" :offset="6"><div class="grid-block">25% + offset 6</div></CfCol>
<CfCol :span="8"><div class="grid-block">33.33%</div></CfCol>
<CfCol :span="8" :offset="8"><div class="grid-block">33.33% + offset 8</div></CfCol>
<CfCol :span="12"><div class="grid-block">50%</div></CfCol>
<CfCol :span="16"><div class="grid-block">66.66%</div></CfCol>
</CfRow>
</section>
<section class="grid-card">
<CfRow :gutter="[12, 12]" align="stretch">
<CfCol :xs="24" :md="12" :lg="8">
<div class="panel">xs=24 / md=12 / lg=8</div>
</CfCol>
<CfCol :xs="24" :md="12" :lg="8">
<div class="panel">响应式断点</div>
</CfCol>
<CfCol :xs="24" :md="24" :lg="8">
<div class="panel">gutter=[12, 12]</div>
</CfCol>
</CfRow>
</section>
</div>
</template>
<style scoped>
.grid-demo {
width: 100%;
display: grid;
gap: 18px;
}
.grid-concept {
position: relative;
overflow: hidden;
border: 1px solid var(--line-1);
border-radius: 8px;
padding: 18px;
background: var(--surface-1);
}
.grid-guide {
position: absolute;
inset: 18px;
pointer-events: none;
opacity: .8;
background:
linear-gradient(
90deg,
color-mix(in srgb, var(--accent-1) 8%, transparent) 0,
color-mix(in srgb, var(--accent-1) 8%, transparent) calc(100% - 8px),
transparent calc(100% - 8px)
);
background-size: 4.1666666667% 100%;
}
.grid-block {
position: relative;
z-index: 1;
min-height: 48px;
display: grid;
place-items: center;
border-radius: 4px;
background: color-mix(in srgb, var(--accent-1) 68%, white);
color: white;
font-weight: 700;
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-1) 18%, transparent);
}
.grid-block--solid {
background: var(--accent-1);
}
.grid-card {
border: 1px solid var(--line-1);
border-radius: 8px;
padding: 16px;
background: var(--surface-0);
}
.panel {
height: 84px;
display: grid;
place-items: center;
border-radius: 8px;
border: 1px solid var(--line-1);
background: var(--surface-1);
color: var(--fg-1);
}
</style> <script setup>
import { CfCol, CfRow } from '@chufix-design/vue';
</script>
<template>
<div class="grid-demo">
<section class="grid-concept" aria-label="24 栅格比例示意">
<div class="grid-guide" aria-hidden="true"></div>
<CfRow :gutter="[8, 8]">
<CfCol :span="24"><div class="grid-block grid-block--solid">100%</div></CfCol>
<CfCol :span="6"><div class="grid-block">25%</div></CfCol>
<CfCol :span="6" :offset="6"><div class="grid-block">25% + offset 6</div></CfCol>
<CfCol :span="8"><div class="grid-block">33.33%</div></CfCol>
<CfCol :span="8" :offset="8"><div class="grid-block">33.33% + offset 8</div></CfCol>
<CfCol :span="12"><div class="grid-block">50%</div></CfCol>
<CfCol :span="16"><div class="grid-block">66.66%</div></CfCol>
</CfRow>
</section>
<section class="grid-card">
<CfRow :gutter="[12, 12]" align="stretch">
<CfCol :xs="24" :md="12" :lg="8">
<div class="panel">xs=24 / md=12 / lg=8</div>
</CfCol>
<CfCol :xs="24" :md="12" :lg="8">
<div class="panel">响应式断点</div>
</CfCol>
<CfCol :xs="24" :md="24" :lg="8">
<div class="panel">gutter=[12, 12]</div>
</CfCol>
</CfRow>
</section>
</div>
</template>
<style scoped>
.grid-demo {
width: 100%;
display: grid;
gap: 18px;
}
.grid-concept {
position: relative;
overflow: hidden;
border: 1px solid var(--line-1);
border-radius: 8px;
padding: 18px;
background: var(--surface-1);
}
.grid-guide {
position: absolute;
inset: 18px;
pointer-events: none;
opacity: .8;
background:
linear-gradient(
90deg,
color-mix(in srgb, var(--accent-1) 8%, transparent) 0,
color-mix(in srgb, var(--accent-1) 8%, transparent) calc(100% - 8px),
transparent calc(100% - 8px)
);
background-size: 4.1666666667% 100%;
}
.grid-block {
position: relative;
z-index: 1;
min-height: 48px;
display: grid;
place-items: center;
border-radius: 4px;
background: color-mix(in srgb, var(--accent-1) 68%, white);
color: white;
font-weight: 700;
box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-1) 18%, transparent);
}
.grid-block--solid {
background: var(--accent-1);
}
.grid-card {
border: 1px solid var(--line-1);
border-radius: 8px;
padding: 16px;
background: var(--surface-0);
}
.panel {
height: 84px;
display: grid;
place-items: center;
border-radius: 8px;
border: 1px solid var(--line-1);
background: var(--surface-1);
color: var(--fg-1);
}
</style> <CfRow gutter={[16, 16]}>
<CfCol span={6}>25%</CfCol>
<CfCol span={12}>50%</CfCol>
<CfCol span={6}>25%</CfCol>
</CfRow> <CfRow gutter={[16, 16]}>
<CfCol span={6}>25%</CfCol>
<CfCol span={12}>50%</CfCol>
<CfCol span={6}>25%</CfCol>
</CfRow> Row API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
as | string / ElementType | div | 渲染元素 |
gutter | number / string / [x, y] | 0 | 水平 / 垂直间距 |
justify | start / center / end / space-around / space-between / space-evenly | start | 水平分布 |
align | top / middle / bottom / stretch | top | 垂直对齐 |
wrap | boolean | true | 是否换行 |
Col API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
as | string / ElementType | div | 渲染元素 |
span | number | 24 | 占据列数,范围 0–24 |
offset | number | 0 | 左侧偏移列数 |
push | number | 0 | 向右移动列数 |
pull | number | 0 | 向左移动列数 |
order | number | 0 | flex 排序 |
xs / sm / md / lg / xl / xxl | number / ColBreakpointConfig | — | 响应式配置 |
ColBreakpointConfig
| 字段 | 类型 | 说明 |
|---|---|---|
span | number | 断点下占据列数 |
offset | number | 断点下左侧偏移 |
push | number | 断点下右移 |
pull | number | 断点下左移 |
order | number | 断点下排序 |
反馈与讨论
Grid 栅格 的讨论