Blogger Information
Blog 20
fans 0
comment 0
visits 11506
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
传统定位布三行三列和flex布局
愿情的博客
Original
981 people have browsed it

布局

1.传统定位布局:三行三列

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>传统定位布局:三行三列</title>
  8. <style>
  9. :root {
  10. /* 是为了布局的,在后面使用rem计算方便 */
  11. font-size: 10px;
  12. }
  13. body *:not(.container) {
  14. background-color: lightblue;
  15. }
  16. body {
  17. /* 将字号恢复到16px */
  18. /* font-size: 16px; */
  19. font-size: 1.6rem;
  20. }
  21. header,
  22. footer {
  23. height: 5rem;
  24. /* background-color: lightblue; */
  25. }
  26. /* 主体区:定位 */
  27. .container {
  28. /* 定位父级:转为定位元素 */
  29. position: relative;
  30. min-height: 60rem;
  31. margin: 0.5rem;
  32. }
  33. .container aside {
  34. width: 20rem;
  35. /* background-color: lightblue; */
  36. min-height: inherit;
  37. }
  38. .container aside,
  39. .container main {
  40. position: absolute;
  41. }
  42. /* 将右侧移动最右侧 */
  43. .container aside:last-of-type {
  44. right: 0;
  45. }
  46. /* 显示主体内容区 */
  47. .container main {
  48. left: 20.5rem;
  49. right: 20.5rem;
  50. /* background-color: red; */
  51. min-height: inherit;
  52. }
  53. /* .container aside:last-of-type {
  54. background-color: red;
  55. width: 30rem;
  56. }*/
  57. </style>
  58. </head>
  59. <body>
  60. <header>页眉</header>
  61. <div class="container">
  62. <aside>左侧</aside>
  63. <main>内容区</main>
  64. <aside>右侧</aside>
  65. </div>
  66. <footer>页脚</footer>
  67. </body>
  68. </html>

2.flex来简化布局

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>使用flex来简化demo4: 三行三列</title>
  8. <style>
  9. :root {
  10. /* 是为了布局的,在后面使用rem计算方便 */
  11. font-size: 10px;
  12. }
  13. body {
  14. /* 将字号恢复到16px */
  15. /* font-size: 16px; */
  16. font-size: 1.6rem;
  17. }
  18. body *:not(.container) {
  19. background-color: lightblue;
  20. }
  21. header,
  22. footer {
  23. /* vh: 将页面的高度分为100份,1vh = 1 / 100 height */
  24. height: 8vh;
  25. }
  26. .container {
  27. /* 100vh - 16vh = 84vh */
  28. height: 84vh;
  29. /* 使用flex */
  30. display: flex;
  31. margin: 0.5rem 0;
  32. }
  33. /* 侧边栏 */
  34. .container aside {
  35. min-width: 20rem;
  36. }
  37. /* 主体内容区 */
  38. .container main {
  39. margin: 0 0.5rem;
  40. min-width: calc(100% - 40rem - 1rem);
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <header>页眉</header>
  46. <div class="container">
  47. <aside>左侧</aside>
  48. <main>内容区</main>
  49. <aside>右侧</aside>
  50. </div>
  51. <footer>页脚</footer>
  52. </body>
  53. </html>

3.简化2

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  7. <title>使用flex来简化:(传统布局:三行三列)</title>
  8. <style>
  9. :root {
  10. /* 是为了布局的,在后面使用rem计算方便 */
  11. font-size: 10px;
  12. }
  13. body {
  14. /* 将字号恢复到16px */
  15. /* font-size: 16px; */
  16. font-size: 1.6rem;
  17. height: 100vh;
  18. display: grid;
  19. grid-template-columns: 20rem 1fr 20rem;
  20. grid-template-rows: 8vh 1fr 8vh;
  21. gap: 0.5rem;
  22. }
  23. body * {
  24. background-color: lightblue;
  25. }
  26. header,
  27. footer {
  28. grid-column: span 3;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <header>页眉</header>
  34. <aside>左侧</aside>
  35. <main>内容区</main>
  36. <aside>右侧</aside>
  37. <footer>页脚</footer>
  38. </body>
  39. </html>
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!