Blogger Information
Blog 16
fans 0
comment 0
visits 15844
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
盒模型类型讲解,常用元素定位对齐方式简介
Allen在php中文网的学习笔记
Original
508 people have browsed it

1218作业

作业标题:1218作业
作业内容:1. 实例演示box-sizing属性; 2. 实例演示常用的元素居中方式
演示地址:https://php.gzj2001.com/1218/

作业代码

  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>1218作业</title>
  7. <style>
  8. * {
  9. font-size: 20px;
  10. }
  11. /* ---------1.box-sizing------------- */
  12. .box {
  13. width: 10em;
  14. height: 10em;
  15. background-color: yellow;
  16. border: 5px red solid;
  17. padding: 5px;
  18. background-clip: content-box;
  19. box-sizing: content-box;
  20. }
  21. .box2 {
  22. width: 10em;
  23. height: 10em;
  24. background-color: green;
  25. border: 5px red solid;
  26. padding: 5px;
  27. background-clip: content-box;
  28. box-sizing: border-box;
  29. }
  30. /* -----------2.居中------------ */
  31. /* 2.1水平居中 */
  32. .center {
  33. width: 20em;
  34. border: 1px red solid;
  35. }
  36. .center p {
  37. /* p标签水平居中 */
  38. text-align: center;
  39. }
  40. .center div {
  41. width: 5em;
  42. height: 5em;
  43. background-color: blue;
  44. margin: 0 auto;
  45. }
  46. /* 2.2垂直居中 */
  47. .line {
  48. width: 15em;
  49. height: 15em;
  50. border: 1px red solid;
  51. background-color: pink;
  52. }
  53. .line a {
  54. /* line-height: 与容器高度相等即可垂直居中; */
  55. line-height: 15em;
  56. }
  57. .line2 {
  58. width: 15em;
  59. /* 为了使块元素垂直居中,不设置高度 这里应该由padding寄出来 */
  60. /* height: 15em; */
  61. border: 1px red solid;
  62. background-color: pink;
  63. padding: 3em 0;
  64. }
  65. .line2>div {
  66. width: 3em;
  67. height: 3em;
  68. background-color: orange;
  69. }
  70. /* 2.3水平垂直居中 */
  71. /* 2.3.1行内元素 */
  72. /* text-align+ line-height */
  73. .end {
  74. width: 10em;
  75. height: 10em;
  76. background-color: #999;
  77. text-align: center;
  78. line-height: 10em;
  79. }
  80. </style>
  81. </head>
  82. <body>
  83. <div class="box">220*220px content-box 不包含 padding border大小</div>
  84. <br>
  85. <div class="box2">200*200px border-box 包含了padding border大小</div>
  86. <br>
  87. <div class="center">
  88. <p>水平居中</p>
  89. <div>水平居中</div>
  90. </div>
  91. <br>
  92. <div class="line">
  93. <a href="">垂直居中</a>
  94. </div>
  95. <br>
  96. <div class="line2">
  97. <div> 块垂直居中</div>
  98. </div>
  99. <br>
  100. <div class="end">
  101. <a href="">aaaaaaa</a>
  102. </div>
  103. </body>
  104. </html>
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