Blogger Information
Blog 6
fans 0
comment 0
visits 3670
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
CSS定位与浮动及经典三列布局
Dobeen
Original
470 people have browsed it

演示图

代码

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>布局练习</title>
  6. <style>
  7. /* 初始化 */
  8. * { padding: 0; margin: 0; box-sizing: border-box; font-size: 14px; }
  9. body { background-color: #f3f5f7; }
  10. li { list-style: none; }
  11. a { text-decoration: none; }
  12. .clear { zoom: 1; }
  13. .clear:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
  14. /* 初始化 */
  15. /* 头部样式 */
  16. .header { position: relative; background-color: #000; }
  17. .header .logo { position: absolute; top: 0; left: 20px; height: 60px; width: 140px; background: url(https://www.php.cn/static/images/logo.png) no-repeat center center; background-size: 100%; }
  18. .nav { padding-left: 180px; }
  19. .guest-box { float: right; }
  20. .header li { float: left; }
  21. .nav > li { margin: 0 10px; position: relative; }
  22. .nav > li a, .guest-box > li a { display: inline-block; height: 60px; line-height: 60px; color: #bbb; padding: 0 20px; }
  23. .nav > li a:hover, .guest-box > li a:hover { color: #FFF; }
  24. .subnav { position: absolute; width: 222px; border: 1px solid #d2d2d2; top: 60px; display: none; background-color: #FFF; }
  25. .subnav > li a { color: #333; display: block; width: 110px; height: 40px; line-height: 40px; }
  26. .subnav > li a:hover { color: #333; background-color: #f2f2f2; }
  27. .navbar { position: absolute; left: 0; bottom: 0; width: 100px; height: 5px; background-color: #00a700; }
  28. /* 头部样式 */
  29. /* 内容区域样式 */
  30. .adbox { width: 1200px; margin: 20px auto; }
  31. .adbox img { border-radius: 8px; }
  32. .content { width: 1200px; margin: auto; position: relative; }
  33. .content > .left { position: absolute; top: 0; left: 0; width: 300px; }
  34. .content > .right { position: absolute; top: 0; right: 0; width: 260px; }
  35. .content > .middle { margin-left: 310px; margin-right: 270px; }
  36. /* 栏目框样式 */
  37. .content-box { height: 420px; width: 100%; background-color: #FFF; border-radius: 8px; }
  38. .content-box .box-head { margin: 0 15px; border-bottom: 1px dotted #e9e9e9; padding: 8px 5px; font-weight: bolder; }
  39. .toutiaolist { padding: 15px; }
  40. .toutiaolist li { height: 30px; line-height: 30px; }
  41. .toutiaolist li a { color: #333; }
  42. .courselist li { float: left; width: 33.333%; margin-top: 20px; }
  43. .courselist li .course { width: 180px; height: 160px; margin: auto; border-radius: 8px; box-shadow: 0 5px 10px 0 rgba(0,0,0,0.1); font-size: 30px; text-align: center; line-height: 160px; }
  44. .shouce { padding: 0 15px 0 15px;}
  45. .shouce li { position: relative; margin-top: 20px; }
  46. .shouce li img { position: absolute; top: 0; left: 0; width: 45px; height: 45px; }
  47. .shouce li a { display: block; color: #333; margin-left: 55px; font-size: 13px; line-height: 20px; }
  48. .footer { background-color: #393D49; color: #787d82; position: fixed; bottom: 0; width: 100%; padding: 15px 0; }
  49. .footer p { height: 30px; line-height: 30px; font-size: 12px; text-align: center; }
  50. </style>
  51. </head>
  52. <body>
  53. <div class="header clear">
  54. <a href="http://php.cn" class="logo"></a>
  55. <ul class="nav">
  56. <li><a href="#">首页</a></li>
  57. <li><a href="#">视频教程</a></li>
  58. <li><a href="#">入门教程</a></li>
  59. <li><a href="#">社区问答</a></li>
  60. <li>
  61. <a href="#">技术文章</a>
  62. <ul class="subnav clear">
  63. <li><a href="#">头条</a></li>
  64. <li><a href="#">博客</a></li>
  65. <li><a href="#">PHP教程</a></li>
  66. <li><a href="#">JS教程</a></li>
  67. <li><a href="#">Mysql教程</a></li>
  68. <li><a href="#">PHP框架</a></li>
  69. </ul>
  70. </li>
  71. <li><a href="#">资源下载</a></li>
  72. <li><a href="#">编程词典</a></li>
  73. <li><a href="#">工具下载</a></li>
  74. <li><a href="#">PHP培训</a></li>
  75. </ul>
  76. <ul class="guest-box">
  77. <li><a href="#">登录</a></li>
  78. <li><a href="#">注册</a></li>
  79. </ul>
  80. </div>
  81. <div class="container">
  82. <div class="adbox">
  83. <a href="https://www.php.cn/toutiao-387072.html" target="_blank"><img src="https://www.php.cn/static/images/index_ad222.jpg"></a>
  84. </div>
  85. <div class="content">
  86. <div class="left">
  87. <div class="content-box">
  88. <div class="box-head">头条</div>
  89. <div class="box-body">
  90. <ul class="toutiaolist">
  91. <li><a href="#">php中文网原创视频:《天龙八部》公益ph</a></li>
  92. <li><a href="#">php中文网《玉女心经》公益PHP培训系列</a></li>
  93. <li><a href="#">php的版本发展历史(1995-2020)</a></li>
  94. <li><a href="#">您知道吗?最好的语言:PHP 25 岁了!</a></li>
  95. <li><a href="#">史上最污技术解读,我竟然秒懂了</a></li>
  96. <li><a href="#">2020年最新5个简洁优秀的个人博客模板免</a></li>
  97. <li><a href="#">5款优秀的vue后台管理系统模板推荐</a></li>
  98. <li><a href="#">6个大气的bootstrap后台管理系统模板推荐</a></li>
  99. <li><a href="#">phpstudy v8.1.0.4 版本今日发布!</a></li>
  100. <li><a href="#">您知道吗?最好的语言:PHP 25 岁了!</a></li>
  101. <li><a href="#">史上最污技术解读,我竟然秒懂了</a></li>
  102. <li><a href="#">php中文网《玉女心经》公益PHP培训系列</a></li>
  103. </ul>
  104. </div>
  105. </div>
  106. </div>
  107. <div class="middle">
  108. <div class="content-box">
  109. <div class="box-head">最新课程</div>
  110. <div class="box-body">
  111. <ul class="courselist clear">
  112. <li><div class="course">1</div></li>
  113. <li><div class="course">2</div></li>
  114. <li><div class="course">3</div></li>
  115. <li><div class="course">4</div></li>
  116. <li><div class="course">5</div></li>
  117. <li><div class="course">6</div></li>
  118. </ul>
  119. </div>
  120. </div>
  121. </div>
  122. <div class="right">
  123. <div class="content-box">
  124. <div class="box-head">常用手册</div>
  125. <div class="box-body">
  126. <ul class="shouce">
  127. <li>
  128. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg">
  129. <a href="#">php手册Linux手册</a>
  130. <a href="#">ThinkPHP6.0CI手册大全</a>
  131. </li>
  132. <li>
  133. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg">
  134. <a href="#">php手册Linux手册</a>
  135. <a href="#">ThinkPHP6.0CI手册大全</a>
  136. </li>
  137. <li>
  138. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg">
  139. <a href="#">php手册Linux手册</a>
  140. <a href="#">ThinkPHP6.0CI手册大全</a>
  141. </li>
  142. <li>
  143. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg">
  144. <a href="#">php手册Linux手册</a>
  145. <a href="#">ThinkPHP6.0CI手册大全</a>
  146. </li>
  147. <li>
  148. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg">
  149. <a href="#">php手册Linux手册</a>
  150. <a href="#">ThinkPHP6.0CI手册大全</a>
  151. </li>
  152. <li>
  153. <img src="https://www.php.cn/upload/system/000/000/001/57d55fe881432245.jpg">
  154. <a href="#">php手册Linux手册</a>
  155. <a href="#">ThinkPHP6.0CI手册大全</a>
  156. </li>
  157. </ul>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. <div class="footer">
  164. <div class="content">
  165. <p>关于我们 | 免责申明 | 赞助与捐赠 | 广告合作</p>
  166. <p>php中文网:公益在线php培训,帮助PHP学习者快速成长!</p>
  167. <p>Copyright 2014-2020 https://www.php.cn/ All Rights Reserved | 皖B2-20150071-9 皖公网安备 34010402701654号</p>
  168. <p>座机号码:0551-64933227 安徽省合肥市政务新区置地广场D座2101</p>
  169. </div>
  170. </div>
  171. <script>
  172. const navs = document.querySelectorAll('.nav > li');
  173. navs.forEach(function (nav) {
  174. nav.addEventListener('mouseover', showMenu);
  175. nav.addEventListener('mouseout', closeMenu);
  176. });
  177. function showMenu (event) {
  178. if(event.target.nextElementSibling != null && event.target.nextElementSibling.nodeName == 'UL'){
  179. event.target.nextElementSibling.style.display = 'block';
  180. }
  181. const currentnav = event.currentTarget;
  182. const navbar = document.createElement('span');
  183. navbar.classList.add('navbar');
  184. currentnav.appendChild(navbar);
  185. }
  186. function closeMenu (event) {
  187. if(event.target.nextElementSibling != null && event.target.nextElementSibling.nodeName == 'UL'){
  188. event.target.nextElementSibling.style.display = 'none';
  189. }
  190. const navbars = document.querySelectorAll('.navbar');
  191. navbars.forEach(function (navbar) {
  192. navbar.parentNode.removeChild(navbar);
  193. });
  194. }
  195. </script>
  196. </body>
  197. </html>

学习小结

1、本次练习结合了之前学过的下拉菜单、事件监听,之前学的好多记不住都忘记了,练习时候又回过头看直播回放视频,巩固了一下;
2、现在对绝对定位、相对定位以及浮动有了更深的理解;

Correcting teacher:WJWJ

Correction status:qualified

Teacher's comments:写的很不错,能结合之前所学的知识,模仿php中文网!继续加油!
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