Flex — CSS Flexbox Layout Generator
A CLI tool for generating CSS Flexbox layouts. Create flex containers, configure alignment, justify, wrap, gap, and order properties, then export production-ready CSS code.
Prerequisites
- - Python 3.8+
- INLINECODE0 shell
- Write access to INLINECODE1
Data Storage
All layout configurations are stored in JSONL format at ~/.flex/data.jsonl. Each record represents a saved flex layout with all its properties.
Commands
Run commands via: INLINECODE3
create
Create a new flex container layout with a name and optional initial properties.
CODEBLOCK0
Arguments:
- -
--name — Layout name (required) - INLINECODE5 — Flex direction:
row, column, row-reverse, column-reverse (optional, default: row) - INLINECODE11 — Number of child items (optional, default: 3)
row
Create a quick horizontal row layout preset.
CODEBLOCK1
Arguments:
- -
--name — Layout name (required) - INLINECODE13 — Number of items (optional, default: 3)
- INLINECODE14 — Gap in pixels (optional, default: 0)
column
Create a quick vertical column layout preset.
CODEBLOCK2
Arguments:
- -
--name — Layout name (required) - INLINECODE16 — Number of items (optional, default: 3)
- INLINECODE17 — Gap in pixels (optional, default: 0)
wrap
Toggle or set flex-wrap on an existing layout.
CODEBLOCK3
Arguments:
- -
--id — Layout ID (required) - INLINECODE19 — Wrap value:
wrap, nowrap, wrap-reverse (optional, default: wrap)
align
Set align-items property on a layout.
CODEBLOCK4
Arguments:
- -
--id — Layout ID (required) - INLINECODE25 — Alignment:
flex-start, flex-end, center, stretch, baseline (required)
justify
Set justify-content property on a layout.
CODEBLOCK5
Arguments:
- -
--id — Layout ID (required) - INLINECODE32 — Justify:
flex-start, flex-end, center, space-between, space-around, space-evenly (required)
gap
Set the gap property on a layout.
CODEBLOCK6
Arguments:
- -
--id — Layout ID (required) - INLINECODE40 — Gap in pixels (optional)
- INLINECODE41 — Row gap in pixels (optional)
- INLINECODE42 — Column gap in pixels (optional)
order
Set the order of a specific child item within a layout.
CODEBLOCK7
Arguments:
- -
--id — Layout ID (required) - INLINECODE44 — Item index, 1-based (required)
- INLINECODE45 — Order value (required)
grow
Set flex-grow for a child item.
CODEBLOCK8
Arguments:
- -
--id — Layout ID (required) - INLINECODE47 — Item index (required)
- INLINECODE48 — Flex-grow value (required)
shrink
Set flex-shrink for a child item.
CODEBLOCK9
Arguments:
- -
--id — Layout ID (required) - INLINECODE50 — Item index (required)
- INLINECODE51 — Flex-shrink value (required)
export
Export a layout or all layouts as CSS code.
CODEBLOCK10
Arguments:
- -
--id — Export a specific layout (optional) - INLINECODE53 — Export all layouts (optional)
- INLINECODE54 — Output file path (optional, default: stdout)
help
Display help information and list all available commands.
CODEBLOCK11
version
Display the current tool version.
CODEBLOCK12
Examples
CODEBLOCK13
Notes
- - Each layout stores complete flex properties: direction, wrap, align, justify, gap, and per-item grow/shrink/order
- The
export command generates clean, production-ready CSS with class names derived from layout names - Use
row and column shortcuts for common patterns instead of INLINECODE58 - Item properties (grow, shrink, order) are stored per item index within each layout
Powered by BytesAgain | bytesagain.com | hello@bytesagain.com
Flex — CSS Flexbox 布局生成器
一个用于生成 CSS Flexbox 布局的命令行工具。创建弹性容器,配置对齐、排列、换行、间距和顺序属性,然后导出可直接用于生产的 CSS 代码。
前置条件
- - Python 3.8+
- bash shell
- 对 ~/.flex/ 目录的写入权限
数据存储
所有布局配置均以 JSONL 格式存储在 ~/.flex/data.jsonl 中。每条记录代表一个已保存的弹性布局及其所有属性。
命令
通过以下方式运行命令:bash scripts/script.sh [arguments...]
create
创建一个新的弹性容器布局,可指定名称和可选初始属性。
bash
bash scripts/script.sh create --name navbar --direction row --items 5
bash scripts/script.sh create --name sidebar --direction column
参数:
- - --name — 布局名称(必填)
- --direction — 弹性方向:row、column、row-reverse、column-reverse(可选,默认值:row)
- --items — 子元素数量(可选,默认值:3)
row
创建一个快速水平行布局预设。
bash
bash scripts/script.sh row --name header-row --items 4
bash scripts/script.sh row --name card-grid --gap 16
参数:
- - --name — 布局名称(必填)
- --items — 元素数量(可选,默认值:3)
- --gap — 间距(像素)(可选,默认值:0)
column
创建一个快速垂直列布局预设。
bash
bash scripts/script.sh column --name sidebar-nav --items 6
参数:
- - --name — 布局名称(必填)
- --items — 元素数量(可选,默认值:3)
- --gap — 间距(像素)(可选,默认值:0)
wrap
切换或设置现有布局的 flex-wrap 属性。
bash
bash scripts/script.sh wrap --id --value wrap
bash scripts/script.sh wrap --id --value nowrap
参数:
- - --id — 布局 ID(必填)
- --value — 换行值:wrap、nowrap、wrap-reverse(可选,默认值:wrap)
align
设置布局的 align-items 属性。
bash
bash scripts/script.sh align --id --value center
参数:
- - --id — 布局 ID(必填)
- --value — 对齐方式:flex-start、flex-end、center、stretch、baseline(必填)
justify
设置布局的 justify-content 属性。
bash
bash scripts/script.sh justify --id --value space-between
参数:
- - --id — 布局 ID(必填)
- --value — 排列方式:flex-start、flex-end、center、space-between、space-around、space-evenly(必填)
gap
设置布局的 gap 属性。
bash
bash scripts/script.sh gap --id --value 16
bash scripts/script.sh gap --id --row 8 --column 16
参数:
- - --id — 布局 ID(必填)
- --value — 间距(像素)(可选)
- --row — 行间距(像素)(可选)
- --column — 列间距(像素)(可选)
order
设置布局中特定子元素的 order 属性。
bash
bash scripts/script.sh order --id --item 2 --value -1
参数:
- - --id — 布局 ID(必填)
- --item — 元素索引,从 1 开始(必填)
- --value — 顺序值(必填)
grow
设置子元素的 flex-grow 属性。
bash
bash scripts/script.sh grow --id --item 1 --value 2
参数:
- - --id — 布局 ID(必填)
- --item — 元素索引(必填)
- --value — 弹性增长值(必填)
shrink
设置子元素的 flex-shrink 属性。
bash
bash scripts/script.sh shrink --id --item 3 --value 0
参数:
- - --id — 布局 ID(必填)
- --item — 元素索引(必填)
- --value — 弹性收缩值(必填)
export
将单个布局或所有布局导出为 CSS 代码。
bash
bash scripts/script.sh export --id
bash scripts/script.sh export --all --output layouts.css
参数:
- - --id — 导出特定布局(可选)
- --all — 导出所有布局(可选)
- --output — 输出文件路径(可选,默认值:标准输出)
help
显示帮助信息并列出所有可用命令。
bash
bash scripts/script.sh help
version
显示当前工具版本。
bash
bash scripts/script.sh version
示例
bash
创建导航栏
bash scripts/script.sh create --name navbar --direction row --items 5
bash scripts/script.sh justify --id abc123 --value space-between
bash scripts/script.sh align --id abc123 --value center
bash scripts/script.sh export --id abc123
快速卡片网格
bash scripts/script.sh row --name cards --items 4 --gap 16
bash scripts/script.sh wrap --id def456 --value wrap
导出所有内容
bash scripts/script.sh export --all --output flex-layouts.css
说明
- - 每个布局存储完整的弹性属性:方向、换行、对齐、排列、间距以及每个元素的增长/收缩/顺序
- export 命令生成干净、可直接用于生产的 CSS 代码,类名源自布局名称
- 使用 row 和 column 快捷方式替代 create 处理常见模式
- 元素属性(增长、收缩、顺序)按每个布局中的元素索引存储
由 BytesAgain 提供支持 | bytesagain.com | hello@bytesagain.com