布局

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>

更多相关文章

  1. flex项目上的三个属性
  2. flex布局理解
  3. css-flex布局
  4. 固定定位:模态框
  5. 【CSS入门】前端布局神器Flex弹性盒模型详解及适用场景(建议收藏
  6. 0324作业-flex布局
  7. flex布局:flex容器中的四个属性的功能,参数,以及作用
  8. 在苹果Mac上的“邮件”中如何使用列布局?
  9. J. Cole 的 InnoDB 系列 - 3. InnoDB空间文件布局的基础

随机推荐

  1. Android版本管理解决方法小议
  2. 获取Android自己写好了的apk以及反编译
  3. android 数据储存——网络存储(5)
  4. Android视图绘制流程完全解析,带你一步步
  5. 【Android自动化打包】03. APK的数字签名
  6. Android 开机启动应用
  7. Android之文件保存 — Bitmap保存到SD卡
  8. Unity导出android工程集成到android stud
  9. Android(安卓)修改系统时区导致SimpleDat
  10. Android Jetpack让Android一飞冲天