Blogger Information
Blog 56
fans 1
comment 0
visits 62326
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
水平与垂直对齐
零龙
Original
635 people have browsed it

水平与垂直对齐

实例代码:

  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. </head>
  8. <style>
  9. *{
  10. margin: 0;
  11. padding: 0;
  12. box-sizing: border-box;
  13. }
  14. .box{
  15. width: 300px;
  16. height: 300px;
  17. margin: 5px;
  18. border: 1px solid #000;
  19. position: relative;
  20. float: left;
  21. }
  22. .item{
  23. width: 100px;
  24. height: 100px;
  25. border: 1px solid #000;
  26. position: absolute;
  27. top: 0;
  28. left: 0;
  29. right: 0;
  30. bottom: 0;
  31. margin:auto;
  32. }
  33. .item_1{
  34. text-align: center;
  35. }
  36. .box1{
  37. width: 300px;
  38. height: 300px;
  39. margin: 5px;
  40. border: 1px solid #000;
  41. float: left;
  42. }
  43. .box1 .item1{
  44. width: 100px;
  45. height: 100px;
  46. border: 1px solid #000;
  47. text-align: center;
  48. margin: 0 auto;
  49. }
  50. .box2{
  51. width: 300px;
  52. height: 300px;
  53. margin: 5px;
  54. border: 1px solid #000;
  55. float: left;
  56. position: relative;
  57. }
  58. .box2 .item2{
  59. width: 100px;
  60. height: 100px;
  61. border: 1px solid #000;
  62. text-align: center;
  63. position: absolute;
  64. top: 100PX;
  65. }
  66. </style>
  67. <body>
  68. <div class="box">
  69. <div class="item"></div>
  70. <div class="item_1">水平垂直居中</div>
  71. </div>
  72. <div class="box1">
  73. <div class="item1"></div>
  74. <div class="item1_1">水平居中</div>
  75. </div>
  76. <div class="box2">
  77. <div class="item2"></div>
  78. <div class="item2_1">垂直居中</div>
  79. </div>
  80. </body>
  81. </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