\n
\n \n
\n
\n\n```css\n.container {\n display: flex;\n justify-content: center;\n align-items: center;\n height: 100vh; /* 可根据需要调整高度 */\n}\n\n.centered-box {\n /* 可根据需要设置宽度、高度、背景颜色等样式 */\n}\n```\n\n上述代码中,`.container`使用Flexbox布局,通过`justify-content: center;`和`align-items: center;`将内部元素水平和垂直居中。`.centered-box`是要居中的内容,可以根据需求自行设置宽度、高度、背景颜色等样式。

原文地址: https://www.cveoy.top/t/topic/pIKJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录