1、文本内容居中对齐:text-align。
扩展用法:父元素嵌套子元素时,且子元素的宽度小于父元素宽度,使用text-align:center,可以实现子元素的居中对齐。
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>文本内容水平居中</title> 6 <style> 7 .text-center{ 8 border:3px solid red; 9 text-align: center; 10 /*text-align: right;*/ 11 } 12 </style> 13 </head> 14 <body> 15 <div class="text-center"> 16 水平居中对齐 17 </div> 18 </body> 19 </html>