企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# flex 项目主轴排列顺序 ## 1. `order`属性 | 序号 | 属性值 | 描述 | | ---- | --------- | --------------------------- | | 1 | `0`默认值 | 按书写顺序显示 | | 2 | `n` | 值越大,越靠后显示, 允许负数 | --- ## 2. 示例 ![](https://img.kancloud.cn/a9/bd/a9bd0f5d11a4365b5312356f2980ac02_375x218.jpg) ```html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>flex 项目主轴排列顺序</title> <style> /* 容器尺寸 */ .container { width: 300px; height: 150px; } /* flex容器 */ .container { display: flex; } /* flex项目 */ .item { width: 50px; height: 50px; background-color: lightcyan; font-size: 1.5rem; /* 默认值0: 在主轴上按书写顺序排列 */ order: 0; } /* 自定义项目排列顺序: 值越小, 越靠前(即起始线方向) */ .item:first-of-type { background-color: lightgreen; order: 2; } .item:nth-of-type(2) { background-color: yellow; order: 1; } .item:nth-of-type(3) { background-color: pink; order: 3; } .item:last-of-type { background-color: lightskyblue; order: -1; } </style> </head> <body> <div class="container"> <div class="item">1</div> <div class="item">2</div> <div class="item">3</div> <div class="item">4</div> </div> </body> </html> ```