水平居中对齐在页面布局中是最为常见的一种布局方式,标题出现较多;下面我们看看常见的四种水平居中对齐方式:
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小编还为您精选了以下内容,希望对您有所帮助:- 如何下载和安装方正仿宋简体字体
- Scrivener设置自动备份为ZIP文件
- Nomad建模软件色调映射设置教程
- WPS表格自动添加边框设置教程
- Excel表格自动换行设置技巧
- 新如何利用PPT定制幻灯片背景及颜色效果设置?
- Win7网络访问权限设置教程
- 实现连杆的往复运动
- Windows11显示方向设置指南
- UG10.0设置内切圆半径的操作步骤