- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>京东</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- li {
- list-style: none;
- }
-
- .toolbar {
- position: fixed;
- left: 0;
- bottom: 0;
- /* 百分比布局 流式布局 */
- width: 100%;
- height: 50px;
- background-color: pink;
- border-top: 1px solid #ccc;
- }
-
- .toolbar li img {
- height: 100%;
- }
-
- .toolbar li {
- float: left;
- width: 20%;
- height: 50px;
- }
- </style>
- </head>
-
- <body>
- <div class="toolbar">
- <ul>
- <li>
- <a href="#"><img src="./images/index.png" alt=""></a>
- </li>
- <li>
- <a href="#"><img src="./images/classify.png" alt=""></a>
- </li>
- <li>
- <a href="#"><img src="./images/jd.png" alt=""></a>
- </li>
- <li>
- <a href="#"><img src="./images/car.png" alt=""></a>
- </li>
- <li>
- <a href="#"><img src="./images/login.png" alt=""></a>
- </li>
- </ul>
- </div>
- </body>
-
- </html>
-
总结:
- 体验flex布局
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>体验flex布局</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- .box {
- display: flex;
- justify-content: space-between;
- /* height: 200px; */
- border: 1px solid #000;
- }
-
- .box div {
- /* float: left;
- margin: 10px; */
- width: 100px;
- height: 100px;
- background-color: pink;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <div>1</div>
- <div>2</div>
- <div>3</div>
- </div>
- </body>
- </html>
-
作用:
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>体验flex布局</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- .box {
- /* 视觉效果: 子级一行排列/水平排列 */
- /* 水平排列: 默认主轴在水平, 弹性盒子都是沿着主轴排列 */
- display: flex;
- height: 200px;
- border: 1px solid #000;
- }
-
- .box div {
- width: 100px;
- height: 100px;
- background-color: pink;
- }
- </style>
- </head>
- <body>
- <div class="box">
- <div>1</div>
- <div>2</div>
- <div>3</div>
- </div>
- </body>
- </html>
-
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>主轴对齐方式</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- .box {
- display: flex;
-
- /* 居中 */
- /* 在中间排列 */
- /* justify-content: center; */
-
- /* 间距在弹性盒子(子级)之间 */
- /* 左右顶格,除了左右,中间的间距都相等 */
- /* justify-content: space-between; */
-
- /* 所有间距都相等,包括左右到边界的距离 */
- /* justify-content: space-evenly; */
-
- /* 间距加在子级的两侧 */
- /* 视觉效果: 中间的间距是左右到边界间距的两倍 */
- justify-content: space-around;
-
- height: 200px;
- margin: auto;
- border: 1px solid #000;
- }
-
- .box div {
- width: 100px;
- height: 100px;
- background-color: pink;
- }
- </style>
- </head>
-
- <body>
- <div class="box">
- <div>1</div>
- <div>2</div>
- <div>3</div>
- </div>
- </body>
-
- </html>
-
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>侧轴对齐方式</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- .box {
- display: flex;
-
- /* 居中 */
- /* align-items: center; */
-
- /* 拉伸,默认值(现有状态,测试的时候去掉子级的高度) */
- align-items: stretch;
-
- height: 300px;
- margin: auto;
- border: 1px solid #000;
- }
-
- .box div {
- /* width: 100px; */
- /* height: 100px; */
- background-color: pink;
- }
-
- /* 单独设置某个弹性盒子的侧轴对齐方式 */
- .box div:nth-child(2) {
- align-self: center;
- }
-
- </style>
- </head>
-
- <body>
- <div class="box">
- <div>1111</div>
- <div>2</div>
- <div>3</div>
- </div>
- </body>
-
- </html>
-
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- .box {
- display: flex;
-
- height: 300px;
- border: 1px solid #000;
- }
-
- .box div {
- height: 200px;
- margin: 0 20px;
- background-color: pink;
- }
-
- .box div:nth-child(1) {
- width: 50px;
- }
-
- .box div:nth-child(2) {
- /* 占用父级剩余尺寸的份数 */
- flex: 3;
- }
-
- .box div:nth-child(3) {
- flex: 1;
- }
-
- </style>
- </head>
- <body>
- <div class="box">
- <div>1</div>
- <div>2</div>
- <div>3</div>
- </div>
- </body>
- </html>
-
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>主轴方向</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- li {
- list-style: none;
- }
-
- .box li {
- display: flex;
- /* 1. 先确定主轴方向; 2. 再选择对应的属性实现主轴或侧轴的对齐方式 */
- /* 修改主轴方向: 列 */
- flex-direction: column;
-
- /* 视觉效果: 实现盒子水平居中 */
- align-items: center;
-
- /* 视觉效果: 垂直居中 */
- justify-content: center;
-
-
- width: 80px;
- height: 80px;
- border: 1px solid #ccc;
- }
-
- .box img {
- width: 32px;
- height: 32px;
- }
- </style>
- </head>
-
- <body>
- <div class="box">
- <ul>
- <li>
- <img src="./images/media.png" alt="">
- <span>媒体</span>
- </li>
- </ul>
- </div>
- </body>
-
- </html>
-
- <!DOCTYPE html>
- <html lang="en">
-
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>弹性盒子换行</title>
- <style>
- * {
- margin: 0;
- padding: 0;
- }
-
- .box {
- display: flex;
-
- /* 默认值, 不换行 */
- /* flex-wrap: nowrap; */
-
- /* 弹性盒子换行 */
- flex-wrap: wrap;
-
- /* 调节行对齐方式 */
- /* align-content: center; */
- /* align-content: space-around; */
- align-content: space-between;
-
- height: 500px;
- border: 1px solid #000;
- }
-
- .box div {
- width: 100px;
- height: 100px;
- margin: 10px;
- background-color: pink;
- }
- </style>
- </head>
-
- <body>
- <div class="box">
- <div>1</div>
- <div>2</div>
- <div>3</div>
- <div>4</div>
- <div>5</div>
- <div>6</div>
- <div>7</div>
- <div>8</div>
- </div>
- </body>
-
- </html>
-