Blogger Information
Blog 31
fans 2
comment 0
visits 27601
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
绝对定位和浮动使用实现三列布局
霏梦
Original
638 people have browsed it

- 作者:霏梦

定位

  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. <title>布局实例:用绝对定位完成一个通用的三列布局</title>
  7. <STYle>
  8. *{
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. li{
  14. list-style: none;
  15. float: left;
  16. line-height: 50px;
  17. padding: 0 10px;
  18. }
  19. a{
  20. text-decoration: none;
  21. color: orangered;
  22. }
  23. .footer,.header{
  24. height: 50px;
  25. background-color: palegoldenrod;
  26. }
  27. .content{
  28. width: 960px;
  29. margin: auto;
  30. background-color: palegreen;
  31. }
  32. li:hover{
  33. background-color: purple;
  34. }
  35. p{
  36. line-height: 50px;
  37. text-align: center;
  38. }
  39. .container{
  40. width: 960px;
  41. margin: 10px auto;
  42. /* background-color: royalblue; */
  43. min-height: 600px;
  44. position:relative;
  45. }
  46. .container > .left{
  47. width: 200px;
  48. background-color: rosybrown;
  49. min-height: 600px;
  50. position: absolute;
  51. top: 0;
  52. left: 0;
  53. }
  54. .container > .right{
  55. width: 200px;
  56. background-color: rosybrown;
  57. min-height: 600px;
  58. position: absolute;
  59. top: 0;
  60. right: 0;
  61. }
  62. .container> .main{
  63. min-height: 600px;
  64. background-color: seagreen;
  65. width: 540px;
  66. position: absolute;
  67. top: 0;
  68. left: 210px;
  69. }
  70. </STYle>
  71. </head>
  72. <body>
  73. <!-- 页眉 -->
  74. <div class="header">
  75. <div class="content">
  76. <ul>
  77. <li><a href="">HOME</a></li>
  78. <li><a href="">618</a></li>
  79. <li><a href="">KEFU</a></li>
  80. <li><a href="">Contact</a></li>
  81. </ul>
  82. </div>
  83. </div>
  84. <!-- 主体 -->
  85. <div class="container">
  86. <div class="left">左侧</div>
  87. <div class="main">内容</div>
  88. <div class="right">右侧</div>
  89. </div>
  90. <!-- 页脚 -->
  91. <div class="footer">
  92. <p>北京望京东路&copy;京:ICP434343</p>
  93. </div>
  94. </body>
  95. </html>

绝对定位


浮动


  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. <title>布局实例:用浮动完成一个通用的三列布局</title>
  7. <STYle>
  8. *{
  9. margin: 0;
  10. padding: 0;
  11. box-sizing: border-box;
  12. }
  13. li{
  14. list-style: none;
  15. float: left;
  16. line-height: 50px;
  17. padding: 0 10px;
  18. }
  19. a{
  20. text-decoration: none;
  21. color: orangered;
  22. }
  23. .footer,.header{
  24. height: 50px;
  25. background-color: palegoldenrod;
  26. }
  27. .content{
  28. width: 960px;
  29. margin: auto;
  30. background-color: palegreen;
  31. }
  32. li:hover{
  33. background-color: purple;
  34. }
  35. p{
  36. line-height: 50px;
  37. text-align: center;
  38. }
  39. /* 主体部分 */
  40. .container{
  41. width: 960px;
  42. margin: 10px auto;
  43. /* background-color: royalblue; */
  44. min-height: 600px;
  45. /* 防止踢陷 */
  46. overflow: hidden;
  47. }
  48. .container > .left{
  49. width: 200px;
  50. background-color: rosybrown;
  51. min-height: 600px;
  52. float: left;
  53. }
  54. .container > .right{
  55. width: 200px;
  56. background-color: rosybrown;
  57. min-height: 600px;
  58. float: right;
  59. }
  60. .container> .main{
  61. min-height: 600px;
  62. background-color: seagreen;
  63. width: 540px;
  64. float: left;
  65. margin-left: 10px;
  66. }
  67. </STYle>
  68. </head>
  69. <body>
  70. <!-- 页眉 -->
  71. <div class="header">
  72. <div class="content">
  73. <ul>
  74. <li><a href="">HOME</a></li>
  75. <li><a href="">618</a></li>
  76. <li><a href="">KEFU</a></li>
  77. <li><a href="">Contact</a></li>
  78. </ul>
  79. </div>
  80. </div>
  81. <!-- 主体 -->
  82. <div class="container">
  83. <div class="left">左侧</div>
  84. <div class="main">内容</div>
  85. <div class="right">右侧</div>
  86. </div>
  87. <!-- 页脚 -->
  88. <div class="footer">
  89. <p>北京望京东路&copy;京:ICP434343</p>
  90. </div>
  91. </body>
  92. </html>
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:下次看清作业要求, 没写完就先不要提交了
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