Blogger Information
Blog 52
fans 1
comment 1
visits 38288
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1.理解 box-sizing功能并实例演示; 2. 理解相对定位与绝对定位,并实例演示他们的区别与联系
小丑0o鱼
Original
444 people have browsed it

1、box-sizing功能并实例演示;

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <style>
  9. /* 代码的初始化 */
  10. *{
  11. margin: 0;
  12. padding: 0;
  13. box-sizing: border-box;
  14. }
  15. /* :root===html */
  16. :root{
  17. /* 浏览器默认:font-size: 16px ; */
  18. /* 为了便于计算和使用方便 */
  19. font-size: 10px;
  20. }
  21. /* em,rem */
  22. /* em:根据元素的上下文来确定它的值; */
  23. /* rem:根据根元素的字号来设置 */
  24. /* 将W3C的标准盒子转为IE的盒子 */
  25. /* 就是将盒子的padding和border计算在它的width和height内; */
  26. /* 就用box-sizing */
  27. /* box-sizing: border-box; */
  28. /* 当前盒子的边际在那里,当前盒子不在内容区,而是到了边框,这时候内容区就会被压缩。
  29. 内容区始终包含了内边距和边框的*/
  30. .box{
  31. width: 20em;
  32. height: 20em;
  33. padding: 10px;
  34. margin: 10px;
  35. border: 2px solid red;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <p>1. 理解 box-sizing功能并实例演示; </p>
  41. <p> 2. 理解相对定位与绝对定位,并实例演示他们的区别与联系</p>
  42. <div class="box">
  43. </div>
  44. </body>
  45. </html>
  46. ##2、相对定位与绝对定位,并实例演示他们的区别与联系
  47. <!DOCTYPE html>
  48. <html lang="en">
  49. <head>
  50. <meta charset="UTF-8">
  51. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  52. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  53. <title>定位</title>
  54. <style>
  55. body{
  56. border: 2px solid red;
  57. }
  58. /* relative相对定位(相对于自身定位) */
  59. .box{
  60. width: 10rem;
  61. height: 10rem;
  62. background-color: aquamarine;
  63. /* position: static;静态定位,没有定位,默认 */
  64. /* position: static; */
  65. /* 相对定位,自动的转为定位元素了 */
  66. /* 定位元素:只要这个元素上有非static的定位属性,就是定位元素 */
  67. position: relative;
  68. /* 只要有定位元素,定位偏移就有效了 */
  69. top:5rem;
  70. left: 10rem;
  71. font-size: 5rem;
  72. }
  73. /* absolute:绝对定位,根据父元素定位,脱离了文档流 */
  74. /* 文档流:显示顺序与书写顺序一致 */
  75. /* 相对于它在原始文档流中的位置进行定位 */
  76. .box1{
  77. height: 10rem;
  78. border: 2px solid aquamarine;
  79. position: relative;
  80. }
  81. .box2{
  82. width: 10rem;
  83. height: 10rem;
  84. background-color: rgb(253, 72, 238);
  85. position: absolute ;
  86. left: 10rem;
  87. top:12rem;
  88. font-size: 2rem;
  89. }
  90. </style>
  91. </head>
  92. <body>
  93. <div class="box">box</div>
  94. <h1>PHP中文网</h1>
  95. <div class="box1">
  96. <div class="box2">box1</div>
  97. <h2>PHP学习</h2>
  98. </div>
  99. </body>
  100. </html>
Correcting teacher:PHPzPHPz

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!