css设置字体上下居中 css字体居中对齐怎么做

水平居中对齐在页面布局中是最为常见的一种布局方式,标题出现较多;下面我们看看常见的四种水平居中对齐方式:
1、 使用margin:0 auto; 进行布局
<style> .content{ width:100px; height:100px; margin:0 auto; background-color:red; }</style><div class="content"></div>2、使用绝对定位布局
<style> .parent{ width:400px; height:200px; border:1px solid #000; position:relative; } .child{ width:100px; height:100px; background-color:red; position:absolute; left:50%; margin-left:-50px; //50为容器宽度的一半 }</style><div class="parent"> <div class="child"></div></div>3、使用text-align:center;和inline-block进行布局
【css设置字体上下居中 css字体居中对齐怎么做】<style> .parent{ width:400px; height:200px; border:1px solid #000; text-align:center; } .child{ width:100px; height:100px; background-color:red; display:inline-block; }</style><div class="parent"> <div class="child"></div></div>4、使用table进行布局
<style> .parent{ width:400px; height:200px; border:1px solid #000; } .child{ background-color:red; display:table; margin:0 auto; }</style><div class="parent"> <div class="child"></div></div>


    以上关于本文的内容,仅作参考!温馨提示:如遇健康、疾病相关的问题,请您及时就医或请专业人士给予相关指导!

    「四川龙网」www.sichuanlong.com小编还为您精选了以下内容,希望对您有所帮助: