From 306c12d1fdcf5502ce6c39ee2c8765bcab71473f Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 5 Nov 2024 23:02:32 +0800 Subject: [PATCH] zx --- ...03\345\261\200\350\257\246\350\247\243.md" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "\345\221\250\346\227\255/20241104\342\200\224\342\200\224flex\345\270\203\345\261\200\350\257\246\350\247\243.md" diff --git "a/\345\221\250\346\227\255/20241104\342\200\224\342\200\224flex\345\270\203\345\261\200\350\257\246\350\247\243.md" "b/\345\221\250\346\227\255/20241104\342\200\224\342\200\224flex\345\270\203\345\261\200\350\257\246\350\247\243.md" new file mode 100644 index 0000000..795732d --- /dev/null +++ "b/\345\221\250\346\227\255/20241104\342\200\224\342\200\224flex\345\270\203\345\261\200\350\257\246\350\247\243.md" @@ -0,0 +1,88 @@ +# flex布局 + +## 弹性盒子、子元素 +- **弹性盒子**:指的是使用 `display:flex` 或 `display:inline-flex` 声明的**父容器**。 + +- **子元素/弹性元素**:指的是父容器里面的子元素们(父容器被声明为 flex 盒子的情况下)。 + +## 主轴和侧轴 +- 主轴:flex容器的主轴,默认是水平方向,从左向右。 + +- 侧轴:与主轴垂直的轴称作侧轴,默认是垂直方向,从上往下。 + +PS:主轴和侧轴并不是固定不变的,可以通过 `flex-direction` 更换方向 + +## 弹性盒子 +### 声明定义: +使用 `display:flex` 或 `display:inline-flex` 声明一个**父容器**为弹性盒子。此时,这个父容器里的子元素们,会遵循弹性布局。 + +备注:一般是用 `display:flex`这个属性。`display:inline-flex`用得较少。 +### flex-direction 属性 +`flex-direction`:用于设置盒子中**子元素**的排列方向。 + +|属性值|描述| +|:-|-:| +|row|从左到右水平排列子元素(默认值)| +|column|从上到下垂直排列子元素| +|row-reverse|从右到左排列子元素| +|column-reverse|从下到上垂直排列子元素| + +备注:如果我们不给父容器写`flex-direction`这个属性,那么,子元素默认就是从左到右排列的。 + +## flex-wrap属性 +`flex-wrap`:控制子元素溢出时的换行处理。 + +## justify-content属性 +`justify-content`:控制子元素在主轴上的排列方式。 + +## 弹性元素 +### justify-content属性 +`justify-content: flex-start;` 设置子元素在**主轴上的对齐方式**。属性值可以是: + +- `flex-start` 从主轴的起点对齐(默认值) +- `flex-end` 从主轴的终点对齐 +- `center` 居中对齐 +- `space-around` 在父盒子里平分 +- `space-between` 两端对齐 平分 + +### align-items属性 +`align-items`:设置子元素在**侧轴上的对齐方式**。属性值可以是: + - `flex-start` 从侧轴开始的方向对齐 + - `flex-end` 从侧轴结束的方向对齐 + - `baseline` 基线 默认同flex-start + - `center` 中间对齐 + - `stretch` 拉伸 + +``` + .box { + display: flex; + flex-wrap: nowrap; + + } + .a { + + box-sizing: border-box; + padding: 10px; + text-align: center; + height: 100px; + width: 100px; + + } + @media (max-width: 500px) { + .a:nth-child(n+6) { + display: none; + } + } + +.a-1{background-color: rgb(0, 89, 255);} +.a-2{background-color: rgb(146, 8, 3);} +.a-3{background-color: rgb(250, 246, 1);} +.a-4{background-color: rgb(53, 141, 3);} +.a-5{background-color: rgb(255, 0, 98);} +.a-6{background-color: rgb(137, 16, 236);} +.a-7{background-color: rgb(16, 20, 233);} +.a-8{background-color: rgb(168, 2, 80);} +.a-9{background-color: rgb(250, 147, 152);} +.a-10{background-color:rgb(0, 47, 255);} + +``` \ No newline at end of file -- Gitee