CSS的水平居中和垂直居中方式
水平居中 1.行内元素或行内块元素水平居中,即给其父元素添加text-align:center 1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <title>Document</title> 8 <style> 9 * { 10 padding: 0; 11 margin: 0; 12 } 13 14 .wrapper { 15 height: 400px; 16 background-color: pink; 17 text-align: center; 18 } 19 </style> 20 </head> 21 22 <body> 23 24 <div class="wrapper"> 25 <span class="center">text-align:center</span> 26 </div> 27 28 </body> 29 30 </html> 2.块级元素水平居中可以用margin:0 auto 1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta