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

水平居中对齐在页面布局中是最为常见的一种布局方式,标题出现较多;下面我们看看常见的四种水平居中对齐方式:1、使用margin:0auto;进行布局.content{width:100px;

水平居中对齐在页面布局中是最为常见的一种布局方式,标题出现较多;下面我们看看常见的四种水平居中对齐方式:

1、 使用margin:0 auto; 进行布局

 .content{ width:100px; height:100px; margin:0 auto; background-color:red; }

2、使用绝对定位布局

 .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为容器宽度的一半 }

3、使用text-align:center;和inline-block进行布局

 .parent{ width:400px; height:200px; border:1px solid #000; text-align:center; } .child{ width:100px; height:100px; background-color:red; display:inline-block; }

4、使用table进行布局

 .parent{ width:400px; height:200px; border:1px solid #000; } .child{ background-color:red; display:table; margin:0 auto; }

本文内容由互联网用户自发贡献,该文观点仅代表作者本人。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 97552693@qq.com 举报,一经查实,本站将立刻删除。本文链接:https://teaffka.com/n/25455.html

(0)
恰卡的头像恰卡
上一篇 2023年 11月 27日
下一篇 2023年 11月 27日

相关推荐

发表回复

登录后才能评论

联系我们

在线咨询: QQ交谈

邮件:97552693@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息