Blogger Information
Blog 28
fans 0
comment 1
visits 21343
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
使用定位与浮动完成一个三列经典布局
南宫
Original
568 people have browsed it

定位完成一个三列经典布局

  1. <!-- 页眉 -->
  2. <div class="header">
  3. <!-- 内容区:水平居中 -->
  4. <div class="content">
  5. <ul>
  6. <li><a href="">首页</a></li>
  7. <li><a href="">618主会场</a></li>
  8. <li><a href="">在线客服</a></li>
  9. </ul>
  10. </div>
  11. </div>
  12. <!-- 主体 -->
  13. <div class="container">
  14. <div class="left">左侧</div>
  15. <div class="main">内容区</div>
  16. <div class="right">右侧</div>
  17. </div>
  18. <!-- 页脚 -->
  19. <div class="footer">
  20. <div class="content">
  21. <p>某有限公司&copy; | 备案号:晋icp *************</p>
  22. </div>
  23. </div>
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. li {
  7. /* 去掉li标签黑点 */
  8. list-style: none;
  9. }
  10. a {
  11. /* 去掉a标签下划线 */
  12. text-decoration: none;
  13. color: #666;
  14. }
  15. /* 页眉与页脚 */
  16. .header,
  17. .footer {
  18. height: 40px;
  19. background-color: lightskyblue;
  20. }
  21. /* 页眉与页脚的内容区 */
  22. .content {
  23. width: 960px;
  24. margin: auto;
  25. }
  26. .content ul li {
  27. float: left;
  28. line-height: 40px;
  29. padding: 0 15px;
  30. }
  31. .content ul li:hover {
  32. background-color: coral;
  33. }
  34. /* 页脚样式 */
  35. .content p {
  36. text-align: center;
  37. line-height: 40px;
  38. }
  39. /* 主体用定位 */
  40. .container {
  41. width: 960px;
  42. margin: 10px auto;
  43. min-height: 600px;
  44. /* 转为定位元素,做为定位父级 */
  45. position: relative;
  46. }
  47. .container > .left {
  48. width: 200px;
  49. background-color: wheat;
  50. min-height: 600px;
  51. position: absolute;
  52. top: 0;
  53. left: 0;
  54. }
  55. .container > .right {
  56. width: 200px;
  57. background-color: wheat;
  58. min-height: 600px;
  59. position: absolute;
  60. top: 0;
  61. right: 0;
  62. }
  63. .container > .main {
  64. background-color: lightseagreen;
  65. min-height: 600px;
  66. width: 540px;
  67. position: absolute;
  68. top: 0;
  69. left: 210px;
  70. }

浮动完成一个三列经典布局

  1. <!-- 页眉 -->
  2. <div class="header">
  3. <!-- 内容区:水平居中 -->
  4. <div class="content">
  5. <ul>
  6. <li><a href="">首页</a></li>
  7. <li><a href="">618主会场</a></li>
  8. <li><a href="">在线客服</a></li>
  9. </ul>
  10. </div>
  11. </div>
  12. <!-- 主体 -->
  13. <div class="container">
  14. <div class="left">左侧</div>
  15. <div class="main">内容区</div>
  16. <div class="right">右侧</div>
  17. </div>
  18. <!-- 页脚 -->
  19. <div class="footer">
  20. <div class="content">
  21. <p>某有限公司&copy; | 备案号:晋icp *************</p>
  22. </div>
  23. </div>
  1. * {
  2. margin: 0;
  3. padding: 0;
  4. box-sizing: border-box;
  5. }
  6. li {
  7. /* 去掉li标签黑点 */
  8. list-style: none;
  9. }
  10. a {
  11. /* 去掉a标签下划线 */
  12. text-decoration: none;
  13. color: #666;
  14. }
  15. /* 页眉与页脚 */
  16. .header,
  17. .footer {
  18. height: 40px;
  19. background-color: lightskyblue;
  20. }
  21. /* 页眉与页脚的内容区 */
  22. .content {
  23. width: 960px;
  24. margin: auto;
  25. }
  26. .content ul li {
  27. float: left;
  28. line-height: 40px;
  29. padding: 0 15px;
  30. }
  31. .content ul li:hover {
  32. background-color: coral;
  33. }
  34. /* 页脚样式 */
  35. .content p {
  36. text-align: center;
  37. line-height: 40px;
  38. }
  39. /* 主体用定位 */
  40. .container {
  41. width: 960px;
  42. margin: 10px auto;
  43. min-height: 600px;
  44. /* 防止浮动元素的高度塌陷 */
  45. overflow: hidden;
  46. }
  47. .container > .left {
  48. width: 200px;
  49. background-color: wheat;
  50. min-height: 600px;
  51. float: left;
  52. }
  53. .container > .right {
  54. width: 200px;
  55. background-color: wheat;
  56. min-height: 600px;
  57. float: right;
  58. }
  59. .container > .main {
  60. background-color: lightseagreen;
  61. min-height: 600px;
  62. width: 540px;
  63. float: left;
  64. left: 10px;
  65. }

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