css怎么设置居中


本文摘自PHP中文网,作者coldplay.xixi,侵删。

css设置居中的方法:1、通过【margin: 0 auto; text-align: center】实现CSS水平居中;2、通过【display:flex】实现CSS水平居中;3、通过【display:table-cell】实现居中。

本教程操作环境:windows7系统、css3版,DELL G3电脑。

css设置居中的方法:

1、通过margin: 0 auto; text-align: center实现CSS水平居中。

这种方法是实现CSS水平居中最最常用的,我在前端开发中大概有60%的CSS水平居中就是通过“margin: 0 auto; text-align: center”实现的。

566f10bd7ec26a869c5d01b8618a6ba.png

2、通过display:flex实现CSS水平居中。

随着越来越多兼容flexbox,所以通过“display:flex”实现CSS水平居中的方案也越来越受青睐。

通过display:flex实现CSS水平居中的原理是父元素display:flex;flex-direction:column;而子元素align-self:center;

阅读剩余部分

相关阅读 >>

css hr是什么意思

css的渐变是什么?css 透明渐变详解

css counter-increment属性怎么用

hbuilderx写css代码没有提示怎么办

css怎么选择所有子元素

css3做出多样边框特效

网页设计中,css一般是指?

css清除浮动的方法有哪些

css怎样实现div高度自适应

css可以在html里面写吗

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...