登录  /  注册
博主信息
博文 31
粉丝 2
评论 0
访问量 26818
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
绝对定位和浮动使用实现三列布局
霏梦
原创
614人浏览过

- 作者:霏梦

定位

  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>
批改老师:天蓬老师天蓬老师

批改状态:合格

老师批语:下次看清作业要求, 没写完就先不要提交了
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学