博客列表 >html学习:第8章 框模型与定位

html学习:第8章 框模型与定位

王小飞
王小飞原创
2020年05月15日 16:59:01639浏览

实列演示代码:

  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>Document</title>
  7. <style>
  8. body {
  9. height: 2000px;
  10. /* 网站整体传个背景图 */
  11. background-image: url(images/t018b071039ea200dc7.jpg);
  12. background-repeat: no-repeat;
  13. }
  14. /* 设置一个框,margin设置margin:auto使它在页面居中 */
  15. .nei {
  16. width: 1200px;
  17. height: 800px;
  18. margin: auto;
  19. border: 5px solid;
  20. }
  21. .nei1 {
  22. width: 200px;
  23. height: 200px;
  24. background-color: rgb(15, 226, 86);
  25. border: 1px solid;
  26. margin-top: 20px;
  27. padding-top: 10px;
  28. float: right;
  29. /* 相对定位,配合top,left,right,bottom使用 */
  30. position: absolute;
  31. top: 200px;
  32. /* 因为box的margin被浏览器强制为boody的宽度,所有定位700px没有靠着右边 */
  33. left: 700px;
  34. }
  35. .nei2 {
  36. width: 300px;
  37. height: 300px;
  38. border: 1px solid;
  39. background-color: rgb(14, 124, 235);
  40. float: right;
  41. }
  42. .xuan {
  43. width: 150px;
  44. height: 200px;
  45. background-color: rgb(201, 58, 22);
  46. position: fixed;
  47. right: 0;
  48. bottom: 0;
  49. }
  50. </style>
  51. </head>
  52. <body>
  53. <!-- 第一个大框 -->
  54. <div class="nei"">
  55. <!-- 第一个小框 -->
  56. <div class="nei1"></div>
  57. <!-- 第二个小框 -->
  58. <div class="nei2"></div>
  59. </div>
  60. <!-- 悬浮 -->
  61. <div class="xuan"></div>
  62. </body>
  63. </html>

效果:

声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议