博客列表 >水平与垂直对齐

水平与垂直对齐

零龙
零龙原创
2020年06月24日 19:24:23634浏览

水平与垂直对齐

实例代码:

  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>
  • 实例效果

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