亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

搜索
博主信息
博文 13
粉絲 1
評(píng)論 0
訪問(wèn)量 18998
最新下載
更多>
網(wǎng)站特效
網(wǎng)站源碼
網(wǎng)站素材
前端模板
flex布局涉及到的12個(gè)屬性和實(shí)例
樊天龍的博客
原創(chuàng)
1142人瀏覽過(guò)

flex布局涉及到的12個(gè)屬性和實(shí)例

1.為什么要使用flex布局?

flex意為彈性布局,布局元素大小在flex容器中自動(dòng)伸縮,以適應(yīng)容器的變化,特別適合響應(yīng)式布局

2.容器上的6個(gè)屬性

序號(hào) 名稱 描述
1. flex-direction 主軸方向
2. flex-wrap 主軸上項(xiàng)目換行方式
3. flex-flow 主軸方向和主軸上的項(xiàng)目換行方式的復(fù)合屬性
4. justify-content 主軸上的項(xiàng)目對(duì)齊方式
5. align-items 交叉軸上的項(xiàng)目對(duì)齊方式(適用于單行容器)
6. align-content 交叉軸上的項(xiàng)目對(duì)齊方式(適用于多行容器)

2.1主軸方向flex-direction

2.1.1源代碼

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. .flex-container {
  8. /* 將容器設(shè)置為flex容器 */
  9. display: flex;
  10. /* 設(shè)置主軸的方向,默認(rèn)從左到右排列 */
  11. flex-direction: row;
  12. /* 主軸方向從右到左 */
  13. /* flex-direction: row-reverse; */
  14. /* 主軸方向從上到下 */
  15. /* flex-direction: column; */
  16. /* 主軸方向從下到上 */
  17. /* flex-direction: column-reverse; */
  18. width: 300px;
  19. height: 150px;
  20. }
  21. .item {
  22. width: 100px;
  23. height: 100px;
  24. }
  25. </style>
  26. <title>Document</title>
  27. </head>
  28. <body>
  29. <div class="flex-container">
  30. <div class="item">flex1</div>
  31. <div class="item">flex2</div>
  32. <div class="item">flex3</div>
  33. <div class="item">flex4</div>
  34. </div>
  35. </body>
  36. </html>

2.1.2效果圖

2.2項(xiàng)目換行方式flex-wrap

2.2.1源代碼

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. .flex-container {
  8. display: flex;
  9. /* 設(shè)置主軸方向項(xiàng)目換行方式,默認(rèn)不換行 */
  10. flex-wrap: nowrap;
  11. /* 換行 */
  12. /* flex-wrap: wrap; */
  13. /* 反向換行 */
  14. /* flex-wrap: wrap-reverse; */
  15. width: 300px;
  16. height: 300px;
  17. }
  18. .item {
  19. width: 100px;
  20. height: 100px;
  21. }
  22. </style>
  23. <title>Document</title>
  24. </head>
  25. <body>
  26. <div class="flex-container">
  27. <div class="item">flex1</div>
  28. <div class="item">flex2</div>
  29. <div class="item">flex3</div>
  30. <div class="item">flex4</div>
  31. </div>
  32. </body>
  33. </html>

2.2.2效果圖

2.3flex-flow

2.3.1源代碼

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. .flex-container {
  8. display: flex;
  9. /* flex-flow:為flex-direction和flex-wrap的復(fù)合屬性 */
  10. flex-flow: row wrap;
  11. width: 300px;
  12. height: 300px;
  13. }
  14. .item {
  15. width: 100px;
  16. height: 100px;
  17. }
  18. </style>
  19. <title>Document</title>
  20. </head>
  21. <body>
  22. <div class="flex-container">
  23. <div class="item">flex1</div>
  24. <div class="item">flex2</div>
  25. <div class="item">flex3</div>
  26. <div class="item">flex4</div>
  27. </div>
  28. </body>
  29. </html>

2.3.2效果圖

2,4.主軸上的項(xiàng)目對(duì)齊方式justify-content

2.4.1源代碼

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. .flex-container {
  8. display: flex;
  9. width: 500px;
  10. height: 150px;
  11. /* 主軸上項(xiàng)目對(duì)齊方式,默認(rèn)左對(duì)齊 */
  12. justify-content: flex-start;
  13. /* 右對(duì)齊 */
  14. /* justify-content: flex-end; */
  15. /* 居中對(duì)齊 */
  16. /* justify-content: center; */
  17. /* 兩端對(duì)齊 */
  18. /* justify-content: space-between; */
  19. /* 分散對(duì)齊,項(xiàng)目間距是兩側(cè)兩倍 */
  20. /* justify-content: space-around; */
  21. /* 平均對(duì)齊 */
  22. /* justify-content: space-evenly; */
  23. }
  24. .item {
  25. width: 100px;
  26. height: 100px;
  27. }
  28. </style>
  29. <title>Document</title>
  30. </head>
  31. <body>
  32. <div class="flex-container">
  33. <div class="item">flex1</div>
  34. <div class="item">flex2</div>
  35. <div class="item">flex3</div>
  36. <div class="item">flex4</div>
  37. </div>
  38. </body>
  39. </html>

2.4.2效果圖

2.5交叉軸上的項(xiàng)目對(duì)齊方式(適用于單行容器)align-items

2.5.1源代碼

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. .flex-container {
  8. display: flex;
  9. /* 交叉軸對(duì)齊方式,默認(rèn)為起始線對(duì)齊 */
  10. align-items: flex-start;
  11. /* 終止線對(duì)齊 */
  12. /* align-items: flex-end; */
  13. /* 居中對(duì)齊 */
  14. /* align-items: center; */
  15. width: 400px;
  16. height: 150px;
  17. }
  18. .item {
  19. width: 100px;
  20. height: 100px;
  21. }
  22. </style>
  23. <title>Document</title>
  24. </head>
  25. <body>
  26. <div class="flex-container">
  27. <div class="item">flex1</div>
  28. <div class="item">flex2</div>
  29. <div class="item">flex3</div>
  30. <div class="item">flex4</div>
  31. </div>
  32. </body>
  33. </html>

2.5.2效果圖

2.6交叉軸上的項(xiàng)目對(duì)齊方式(適用于多行容器)

2.6.1源代碼

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. .flex-container {
  8. display: flex;
  9. flex-flow: row wrap;
  10. /* 多行容器項(xiàng)目交叉軸對(duì)齊方式,默認(rèn)為stretch */
  11. /* align-content: stretch; */
  12. /* 起始線對(duì)齊 */
  13. align-content: flex-start;
  14. /* 終止線對(duì)齊 */
  15. /* align-content: flex-end; */
  16. /* 居中對(duì)齊 */
  17. /* align-content: center; */
  18. /* 兩端對(duì)齊 */
  19. /* align-content: space-between; */
  20. /* 分散對(duì)齊 */
  21. /* align-content: space-around; */
  22. /* 平均對(duì)齊 */
  23. /* align-content: space-evenly; */
  24. width: 300px;
  25. height: 300px;
  26. }
  27. .item {
  28. width: 100px;
  29. height: 100px;
  30. }
  31. </style>
  32. <title>Document</title>
  33. </head>
  34. <body>
  35. <div class="flex-container">
  36. <div class="item">flex1</div>
  37. <div class="item">flex2</div>
  38. <div class="item">flex3</div>
  39. <div class="item">flex4</div>
  40. </div>
  41. </body>
  42. </html>

2.6.2效果圖

效果圖同主軸對(duì)齊方式

3.項(xiàng)目上的6個(gè)屬性

序號(hào) 名稱 描述
1. order 項(xiàng)目排序
2. align-self 交叉軸獨(dú)立對(duì)齊方式
3.
3.
3.
3.

3.1項(xiàng)目排序order

3.1.1源代碼

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <style>
  7. .flex-container {
  8. display: flex;
  9. width: 400px;
  10. /* 項(xiàng)目排序,默認(rèn)為0,支持負(fù)數(shù)
  11. 數(shù)值越小排在前面
  12. */
  13. /* order: 0; */
  14. }
  15. .item {
  16. width: 100px;
  17. height: 100px;
  18. }
  19. .item:first-of-type {
  20. order: 4;
  21. }
  22. .item:nth-of-type(2) {
  23. order: 1;
  24. }
  25. .item:nth-of-type(3) {
  26. /* 支持負(fù)數(shù)排序 */
  27. order: -1;
  28. }
  29. .item:last-of-type {
  30. order: 6;
  31. }
  32. </style>
  33. <title>Document</title>
  34. </head>
  35. <body>
  36. <div class="flex-container">
  37. <div class="item">flex1</div>
  38. <div class="item">flex2</div>
  39. <div class="item">flex3</div>
  40. <div class="item">flex4</div>
  41. </div>
  42. </body>
  43. </html>

3.1.2效果圖

4.總結(jié)

  • flex基礎(chǔ)雖然已經(jīng)掌握,但是實(shí)戰(zhàn)中用的還是不是很熟練
  • 常用的屬性可以寫成復(fù)合屬性,來(lái)簡(jiǎn)化代碼
  • 后端學(xué)習(xí)時(shí)還可以再仔細(xì)研究和練習(xí)下
批改老師:天蓬老師天蓬老師

批改狀態(tài):合格

老師批語(yǔ):不錯(cuò), 用上錨點(diǎn)了, 有個(gè)建議, 在跳轉(zhuǎn)到目標(biāo)處之后應(yīng)該另一個(gè)按鈕, 再跳轉(zhuǎn)到頭部, <a hre="#">回到頂部</a>就可以
本博文版權(quán)歸博主所有,轉(zhuǎn)載請(qǐng)注明地址!如有侵權(quán)、違法,請(qǐng)聯(lián)系admin@php.cn舉報(bào)處理!
全部評(píng)論 文明上網(wǎng)理性發(fā)言,請(qǐng)遵守新聞評(píng)論服務(wù)協(xié)議
0條評(píng)論
關(guān)于我們 免責(zé)申明 意見(jiàn)反饋 講師合作 廣告合作 最新更新
php中文網(wǎng):公益在線php培訓(xùn),幫助PHP學(xué)習(xí)者快速成長(zhǎng)!
關(guān)注服務(wù)號(hào) 技術(shù)交流群
PHP中文網(wǎng)訂閱號(hào)
每天精選資源文章推送
PHP中文網(wǎng)APP
隨時(shí)隨地碎片化學(xué)習(xí)
PHP中文網(wǎng)抖音號(hào)
發(fā)現(xiàn)有趣的

Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)

  • 登錄PHP中文網(wǎng),和優(yōu)秀的人一起學(xué)習(xí)!
    全站2000+教程免費(fèi)學(xué)