
We can center a
in css using justify-content property and align-item property of flexbox. They are popular because they are responsive and easy to use. In this article, we shall learn how to center
using the Flexbox properties.
使用 align-items 和 justify-content 属性
使用flexbox的最流行的居中div的方法是结合justify-content和align-items属性。
-
justify-content属性会水平居中对齐div。
立即学习“前端免费学习笔记(深入)”;
align-items属性将div垂直居中对齐。
Yes!SUN企业网站系统 3.5 Build 20100303下载Yes!Sun基于PHP+MYSQL技术,体积小巧、应用灵活、功能强大,是一款为企业网站量身打造的WEB系统。其创新的设计理念,为企业网的开发设计及使用带来了全新的体验:支持前沿技术:动态缓存、伪静态、静态生成、友好URL、SEO设置等提升网站性能、用户体验、搜索引擎友好度的技术均为Yes!Sun所支持。易于二次开发:采用独创的平台化理念,按需定制项目中的各种元素,如:产品属性、产品相册、新闻列表
If you want to center align only in one direction, i.e., either vertically or horizontally, we should use only one among the properties we mentioned.
Use the align-items and the justify-contents to center align the child horizontally and vertically.
Example
This is the child element.