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'