跳到主要内容

Grid 栅格

24 栅格制,用 CSS Grid 实现(grid-template-columns: repeat(24, 1fr)),span / offset 直接映射到 grid-column,无需 flex 百分比换算。

基础用法​

基础用法
span 12
span 12
span 8
span 8
span 8
offset 3
居中
span 8
span 8
span 8
span 8
span 24 / md 12 / xl 8
span 24 / md 12 / xl 8
span 24 / xl 8
span 8 push 8
pull 2
sizes 批量声明
import { LhRow, LhCol } from '@lh-ui/react'

export default function Demo() {
return (
<LhRow gutter={12}>
<LhCol span={12}>span 12</LhCol>
<LhCol span={12}>span 12</LhCol>
<LhCol span={8}>span 8</LhCol>
<LhCol span={8}>span 8</LhCol>
<LhCol span={8}>span 8</LhCol>
</LhRow>
)
}

Row Props​

属性说明类型可选值默认值
justify主轴上排列'start' | 'center' | 'end' | 'space-between' | 'space-around'—'start'
align交叉轴上对齐'top' | 'middle' | 'bottom'—'top'
gutter列间距(px 或 [横向, 纵向])number | [number, number]—0
wrap是否换行boolean—true
sx快速布局属性SxProps——

Col Props​

属性说明类型可选值默认值
span占据列数(24 栅格制)number——
offset左侧偏移列数number——
push向右平移列数number——
pull向左平移列数number——
xs<640px 生效(未声明时向下回退)LhColSize——
sm≥640px 生效LhColSize——
md≥768px 生效LhColSize——
lg≥1024px 生效LhColSize——
xl≥1280px 生效LhColSize——
sizes按断点批量声明(与 xs~xl 等价,任选其一)Partial<Record<LhGridBreakpoint, LhColSize>>——
sx快速布局属性SxProps——
响应式断点

xs / sm / md / lg / xl 按 Tailwind 阈值(640 / 768 / 1024 / 1280)分档;未声明的档位向下回退(xs 恒兜底),未声明任何断点时走 span。offset / push / pull 在断点档位上同样生效(以对象形式声明尺寸即可)。缩放浏览器窗口观察分栏变化。

无障碍​

  • 纯布局组件,无交互语义;请勿用栅格承载需要语义结构的列表(应使用 List / Table 等)

样式​

import '@lh-ui/react/style/grid'