关于如何实现浮动元素居中

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6         <style type="text/css">
 7             .box{
 8                 float: left;
 9                 position: relative;
10                 left: 50%;
11             }
12             p{
13                 float: left;
14                 position: relative;
15                 right: 50%;
16             }
17         </style>
18     </head>
19     <body>
20         <div class="box">
21             <p>我是内容</p>
22             <p>我也是浮动</p>        
23         </div>
24     </body>
25 </html>

通过简单的定位position:relative,区区几行代码即可实现内容的居中

原文地址:https://www.cnblogs.com/hhsy/p/5776703.html