16_margin 居中.html 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. #div1{
  10. height: 50px;
  11. background: #00f;
  12. }
  13. ul{
  14. background: #0f0;
  15. list-style: none;
  16. }
  17. li{
  18. background: #f00;
  19. }
  20. /* body{
  21. margin:0;
  22. }
  23. ul{
  24. padding-left: 0;
  25. } */
  26. /* 通配符 选择所有标签*/
  27. *{
  28. margin:0;
  29. padding: 0;
  30. }
  31. #div3{
  32. width: 1200px;
  33. height:100px;
  34. background: palevioletred;
  35. /* margin-left:120px; */
  36. /* 固定宽度的块级元素 水平居中 上线 0 左右自适应 */
  37. margin:0 auto;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <!-- <div id="div1"></div>
  43. <ul>
  44. <li>11</li>
  45. <li>22</li>
  46. </ul> -->
  47. <!-- 宽度1200 高100 左右居中 -->
  48. <div id="div3"></div>
  49. </body>
  50. </html>