diff --git "a/\350\214\203\344\275\263\346\254\243/20241104Flex\345\270\203\345\261\200.md" "b/\350\214\203\344\275\263\346\254\243/20241104Flex\345\270\203\345\261\200.md" new file mode 100644 index 0000000000000000000000000000000000000000..146ec6653e3b3327f633341edadcb8070cad6528 --- /dev/null +++ "b/\350\214\203\344\275\263\346\254\243/20241104Flex\345\270\203\345\261\200.md" @@ -0,0 +1,669 @@ +# 笔记: +## 弹性盒子 +使用display:flex或者display:inline-flex 声明一个父容器为弹性盒子 +***一般为:display:flex这个属性*** + 指的是display:flex或者display:inline-flex 声明的父容器 + ## flex-direction属性 + 用于设置盒子中的子元素 + ``` + 属性值 + row 从左到右排列子(默认) + column 从上到下 + row-reverse 从右到左 + column-reverse 从下到上 + ``` +## flex-wrap属性 +控制子元素溢出时的换行处理 + +## 子元素/ + 父容器被flex声明过后,指的是父容器里面的子元素们 +### 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` 拉伸 + + + ## 主轴和侧轴 + 主轴:flex容器的主轴,默认是水平方向,从左到右; + 侧轴:与主轴锤子的轴成为侧轴,可以通过flex-direction更改方向 +# 作业 +## 十个元素 +`主要代码:` +```css + /* 定于弹性盒子 */ + + .father{ + + display: flex; + flex-wrap: wrap; + } + .c1{ + width: 80px; + height: 80px; + background-color: crimson; + margin: 5px; + flex-wrap: wrap; + } + @media(max-width: 100px){ + .c1:nth-child(5){ + display: none; + } + } +``` +```html +
+
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ +
+ ``` + ## 骰子 + ## 经典圣杯布局 + `效果图展示:` + ![](./经典圣杯.gif) + `主要代码:` + ```css + *{ + margin: 0px; + padding: 0px; + } + .box{ + border: 1px solid; + width: 100vw; + height: 100vh; + } + .head{ +background-color: blue; +width: 100%; +height: 100px; + + } + .content{ + border: 1px solid; + width: 100vw; + height: 80%; + display: flex; + } + .left{ + background-color: darkcyan; + width: 30%; + + border: 1px solid ; + } + .center{ + background-color: hotpink; + width: 40%; + } + .right{ + background-color: cornflowerblue; + width: 30%; + border: 1px solid ; + } + .foot{ + background-color: crimson; + width: 100vw; + height: 100px; + border: 1px solid ; + + } + + @media screen and (max-width:600px) { + .content{ + flex-direction: column; + } + .left{ + width: 100%; + order: 2; + height: 30%; + } + .center{ + width: 100%; + order: 1; + height: 30%; + } + .right{ + width: 100%; + order: 3; + height: 40% + ; + } + } +``` +```html +
+
哈哈哈哈哈
+
+
左边
+
中间
+
右边
+
+
嘿嘿
+
+``` +## 携程 +```css + +``` +```html +
+
+
+
+ + +
+
+
+
+ +
+
+
+ +
+
+
+ 电话费 +
+
+ 电话费 +
+
+ 电话费 +
+
+ 电话费 +
+
+ 电话费 +
+
+ 电话费 +
+
+ 电话费 +
+
+ 电话费 +
+
+ 电话费 +
+
+ 电话费 +
+ +
+
+
+ +
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+
+ +
+
+
+
+ +
+
+ +
+
+ + +
+``` +## 骰子 +>代码: +```css +*{ + margin: 0; + padding: 0; +} +.box{ + width: 1000px; + height: 100px; + display: flex; +} +[class^='d']{ + width: 100px; + height: 100px; + border: 1px solid #eb3223; + margin-left: 10px; + display: flex; +} +[class^='t']{ + width: 15px; + height: 15px; + background-color: black; + border-radius: 50%; +} +.d1{ + justify-content: center; + align-items: center; +} +.d2{ + flex-direction: column; + justify-content: space-around; + align-items: center; +} +.d3{ + flex-direction: column; + align-items: center; + justify-content: space-around; +} +.t31{ + margin-right: 65px; +} +.t33{ + margin-left: 65px; +} +.d4{ + justify-content: space-around; +} +.h40{ + display: flex; + flex-direction: column; + justify-content: space-around; +} +.d5{ + justify-content: space-around; + align-items: center; +} +.t53{ + display: flex; + align-items: center; + justify-content: center; +} +.h50{ + height: 105px; + display: flex; + flex-direction: column; + justify-content: space-around; +} +.d6{ + justify-content: space-around; +} +.h60{ + display: flex; + flex-direction: column; + justify-content: space-around; +} +.d7{ + justify-content: space-around; + flex-direction: column; +} +.h70{ + display: flex; + justify-content: space-around; +} +.d8{ + justify-content: space-around; + flex-direction: column; +} +.h80{ + display: flex; + justify-content: space-between; + margin: 10px; +} +.h90{ + display: flex; + justify-content: space-around; +} +.d9{ + justify-content: space-around; + flex-direction: column; +} +``` \ No newline at end of file